mirror of
https://github.com/signalapp/libsignal.git
synced 2026-05-09 08:33:13 +02:00
Use `./gradlew -P jniTypeTagging` to build with type tags enabled. This has a moderate code size cost, and an unmeasured cost in run-time performance. On 64-bit targets, the tagging relies on bits 48..56 of pointers produced by the default Rust memory allocator being unused (specifically 0), which they are on all our current targets.
192 lines
6.4 KiB
Groovy
192 lines
6.4 KiB
Groovy
import groovy.json.JsonSlurper
|
|
|
|
plugins {
|
|
id 'com.android.library' version '8.9.0'
|
|
id 'maven-publish'
|
|
id 'signing'
|
|
}
|
|
|
|
archivesBaseName = "libsignal-android"
|
|
|
|
repositories {
|
|
google()
|
|
mavenCentral()
|
|
mavenLocal()
|
|
}
|
|
|
|
android {
|
|
namespace 'org.signal.libsignal'
|
|
|
|
compileSdk 34
|
|
ndkVersion '28.0.13004108'
|
|
|
|
defaultConfig {
|
|
minSdkVersion 21
|
|
targetSdkVersion 33
|
|
multiDexEnabled true
|
|
testInstrumentationRunner "org.signal.libsignal.util.AndroidJUnitRunner"
|
|
// Automatically propagate matching environment variables into Java properties.
|
|
// See the custom AndroidJUnitRunner and TestEnvironment classes for more details.
|
|
testInstrumentationRunnerArguments["org.signal.libsignal.test.environment"] = collectTestEnvironment()
|
|
}
|
|
|
|
compileOptions {
|
|
coreLibraryDesugaringEnabled true
|
|
sourceCompatibility JavaVersion.VERSION_17
|
|
targetCompatibility JavaVersion.VERSION_17
|
|
}
|
|
|
|
sourceSets {
|
|
androidTest {
|
|
java {
|
|
// Also run all the Android-agnostic tests by default.
|
|
srcDir '../client/src/test/java'
|
|
srcDir '../shared/test/java'
|
|
}
|
|
resources {
|
|
srcDir '../client/src/test/resources'
|
|
}
|
|
}
|
|
}
|
|
|
|
packagingOptions {
|
|
// Defer stripping to the Android app project.
|
|
doNotStrip '**/*.so'
|
|
}
|
|
|
|
publishing {
|
|
singleVariant('release')
|
|
}
|
|
}
|
|
|
|
String collectTestEnvironment() {
|
|
def result = []
|
|
System.getenv().each { k, v ->
|
|
if (k.startsWith("LIBSIGNAL_TESTING_")) {
|
|
// Limit what characters we accept in values.
|
|
// This is going to get mashed down to a single command-line argument.
|
|
// (This pattern is only meant to head off likely problems and was not specifically
|
|
// tested; if you need to use one of these characters, you can remove the check and see
|
|
// if things Just Work, or tweak our AndroidJUnitRunner to handle different delimiters
|
|
// or escaping.)
|
|
if (v.matches(".*[, \t\r\n].*")) {
|
|
logger.warn("warning: ignoring ${k} for running tests; it contains invalid characters")
|
|
return
|
|
}
|
|
result << "${k}=${v}"
|
|
}
|
|
}
|
|
result.join(",")
|
|
}
|
|
|
|
// From https://github.com/rustls/rustls-platform-verifier
|
|
File findRustlsPlatformVerifierClasses() {
|
|
def dependencyText = providers.exec {
|
|
it.workingDir = project.rootDir.parentFile
|
|
commandLine("bash", "java/find_cargo.sh", "metadata", "--format-version", "1")
|
|
}.standardOutput.asText.get()
|
|
|
|
def dependencyJson = new JsonSlurper().parseText(dependencyText)
|
|
def manifestPath = file(dependencyJson.packages.find { it.name == "rustls-platform-verifier-android" }.manifest_path)
|
|
|
|
// Modifications here:
|
|
// Rather than use the Maven repository in the crates.io source, reference the AAR directly by path.
|
|
// Then, extract the classes from it so that we have a self-contained library.
|
|
def aar = fileTree(manifestPath.parentFile).matching {
|
|
include "maven/rustls/rustls-platform-verifier/*/rustls-platform-verifier-*.aar"
|
|
}.getSingleFile()
|
|
def classesJar = zipTree(aar).matching {
|
|
// Make sure there's nothing in the AAR that we haven't accounted for.
|
|
// This isn't perfect: there could be something important in AndroidManifest.xml.
|
|
// But it's likely good enough.
|
|
exclude "AndroidManifest.xml"
|
|
exclude "META-INF/com/android/build/gradle/aar-metadata.properties"
|
|
exclude "R.txt"
|
|
}.getSingleFile()
|
|
assert classesJar.name == "classes.jar"
|
|
return classesJar
|
|
}
|
|
|
|
dependencies {
|
|
implementation files(findRustlsPlatformVerifierClasses())
|
|
|
|
androidTestImplementation "androidx.test:runner:1.4.0"
|
|
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
|
androidTestImplementation 'com.googlecode.json-simple:json-simple:1.1'
|
|
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.6'
|
|
api project(':client')
|
|
}
|
|
|
|
preBuild {
|
|
dependsOn 'collectAssets'
|
|
dependsOn 'makeJniLibraries'
|
|
}
|
|
|
|
String[] archsFromProperty(String prop) {
|
|
findProperty(prop)?.split(',')?.findAll { it != '' }?.collect { 'android-' + it }
|
|
}
|
|
|
|
task makeJniLibraries(type:Exec) {
|
|
group 'Rust'
|
|
description 'Build the JNI libraries for Android'
|
|
|
|
def archs = archsFromProperty('androidArchs') ?: ['android']
|
|
def debugLevelLogsFlag = project.hasProperty('debugLevelLogs') ? ['--debug-level-logs'] : []
|
|
def jniTypeTaggingFlag = project.hasProperty('jniTypeTagging') ? ['--jni-type-tagging'] : []
|
|
def debugFlag = project.hasProperty('debugRust') ? ['--debug'] : []
|
|
// Explicitly specify 'bash' for Windows compatibility.
|
|
commandLine 'bash', '../build_jni.sh', *debugLevelLogsFlag, *jniTypeTaggingFlag, *debugFlag, *archs
|
|
environment 'ANDROID_NDK_HOME', android.ndkDirectory
|
|
}
|
|
|
|
task collectAssets(type:Copy) {
|
|
from('../../acknowledgments/acknowledgments.md') {
|
|
rename 'acknowledgments.md', 'libsignal.md'
|
|
}
|
|
into 'src/main/assets/acknowledgments'
|
|
}
|
|
|
|
// MARK: Publication
|
|
afterEvaluate {
|
|
publishing {
|
|
publications {
|
|
mavenJava(MavenPublication) {
|
|
artifactId = archivesBaseName
|
|
from components.release
|
|
|
|
pom {
|
|
name = archivesBaseName
|
|
packaging = 'aar'
|
|
description = 'Signal Protocol cryptography library for Android'
|
|
url = 'https://github.com/signalapp/libsignal'
|
|
|
|
scm {
|
|
url = 'scm:git@github.com:signalapp/libsignal.git'
|
|
connection = 'scm:git@github.com:signalapp/libsignal.git'
|
|
developerConnection = 'scm:git@github.com:signalapp/libsignal.git'
|
|
}
|
|
|
|
licenses {
|
|
license {
|
|
name = 'AGPLv3'
|
|
url = 'https://www.gnu.org/licenses/agpl-3.0.txt'
|
|
}
|
|
}
|
|
|
|
developers {
|
|
developer {
|
|
name = 'Signal Messenger LLC'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
setUpSigningKey(signing)
|
|
signing {
|
|
required { isReleaseBuild() && gradle.taskGraph.hasTask(":android:publish") }
|
|
sign publishing.publications.mavenJava
|
|
}
|
|
}
|