Revision control

Copy as Markdown

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This is based off:
import groovy.json.JsonOutput
apply plugin: 'com.android.library'
apply plugin: 'org.mozilla.rust-android-gradle.rust-android'
android {
namespace "mozilla.telemetry.glean_native"
ndkVersion rootProject.ext.build.ndkVersion
compileSdkVersion rootProject.ext.build.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.build['minSdkVersion']
targetSdkVersion rootProject.ext.build['targetSdkVersion']
}
buildTypes {
debug {
// Export our rules in debug, as a consumer might still enable proguard/r8
consumerProguardFiles "$projectDir/proguard-rules-consumer.pro"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles "$projectDir/proguard-rules-consumer.pro"
}
withoutLib {
initWith release
}
}
buildFeatures {
buildConfig true
}
sourceSets {
test.jniLibs.srcDirs += "$buildDir/rustJniLibs/desktop"
}
publishing {
singleVariant('release') {
withSourcesJar()
}
}
// Uncomment to include debug symbols in native library builds.
// packagingOptions { doNotStrip "**/*.so" }
}
cargo {
// The directory of the Cargo.toml to build.
module = '../bundle-android'
// The Android NDK API level to target.
apiLevel = rootProject.ext.build['minSdkVersion']
// Where Cargo writes its outputs.
targetDirectory = '../../target'
// HACK:
// We consume this as libxul.
// Glean is build into libxul from mozilla-central
// and users consume it as part of GeckoView.
// Because UniFFI does not have the option to switch the library to consume,
// except at build time, we use this hack for now.
libname = 'xul'
targets = rootProject.ext.rustTargets
profile = rootProject.ext.cargoProfile
extraCargoBuildArguments = rootProject.ext.extraCargoBuildArguments
}
configurations {
// There's an interaction between Gradle's resolution of dependencies with different types
// (@jar, @aar) for `implementation` and `testImplementation` and with Android Studio's built-in
// JUnit test runner. The runtime classpath in the built-in JUnit test runner gets the
// dependency from the `implementation`, which is type @aar, and therefore the JNA dependency
// doesn't provide the JNI dispatch libraries in the correct Java resource directories. I think
// what's happening is that @aar type in `implementation` resolves to the @jar type in
// `testImplementation`, and that it wins the dependency resolution battle.
//
// A workaround is to add a new configuration which depends on the @jar type and to reference
// the underlying JAR file directly in `testImplementation`. This JAR file doesn't resolve to
// the @aar type in `implementation`. This works when invoked via `gradle`, but also sets the
// correct runtime classpath when invoked with Android Studio's built-in JUnit test runner.
// Success!
jnaForTest
}
dependencies {
jnaForTest(libs.jna) {
artifact {
extension ="jar"
type = "jar"
}
}
implementation(libs.jna) {
artifact {
extension ="aar"
type = "aar"
}
}
}
afterEvaluate {
// The `cargoBuild` task isn't available until after evaluation.
android.libraryVariants.all { variant ->
def productFlavor = ""
variant.productFlavors.each {
productFlavor += "${it.name.capitalize()}"
}
def buildType = "${variant.buildType.name.capitalize()}"
tasks["merge${productFlavor}${buildType}JniLibFolders"].dependsOn(tasks["cargoBuild"])
}
}
apply from: "$projectDir/publish.gradle"
// If using jnaForTestConfiguration
// please also update the corresponding .buildconfig-android.yml
// `publishedArtifacts` property.
ext.configurePublish(
/* jnaForTestConfiguration= */ configurations.jnaForTest
)