128 lines
4.5 KiB
Groovy
128 lines
4.5 KiB
Groovy
apply plugin: 'com.android.library'
|
|
apply plugin: 'org.mozilla.rust-android-gradle.rust-android'
|
|
|
|
apply plugin: 'kotlin-android'
|
|
apply plugin: 'com.jfrog.bintray'
|
|
// Simply applying this plugin gets bintray to publish a pom file.
|
|
apply plugin: 'com.github.dcendents.android-maven'
|
|
|
|
import com.sun.jna.Platform
|
|
|
|
android {
|
|
compileSdkVersion rootProject.ext.build['compileSdkVersion']
|
|
defaultConfig {
|
|
minSdkVersion rootProject.ext.build['minSdkVersion']
|
|
targetSdkVersion rootProject.ext.build['targetSdkVersion']
|
|
|
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
|
|
|
versionCode 0
|
|
versionName "0.7"
|
|
}
|
|
buildTypes {
|
|
release {
|
|
minifyEnabled false
|
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
}
|
|
}
|
|
|
|
sourceSets {
|
|
androidTest.assets.srcDirs += '../../../../fixtures'
|
|
|
|
test.resources.srcDirs += '../../../../fixtures'
|
|
test.resources.srcDirs += "$buildDir/rustResources"
|
|
}
|
|
|
|
// TODO silences:
|
|
// [InvalidPackage]: not included in Android: java.awt. Referenced from com.sun.jna.Native.AWT.
|
|
lintOptions {
|
|
abortOnError false
|
|
}
|
|
|
|
// Help folks debugging by including symbols in our native libraries. Yes, this makes the
|
|
// resulting AAR very large. The Android ecosystem seems to be in flux around who is in charge
|
|
// of stripping native binaries, but for now let's provide symbols and see how consumers react.
|
|
packagingOptions {
|
|
doNotStrip "**/*.so"
|
|
}
|
|
|
|
testOptions.unitTests.all {
|
|
maxParallelForks = 4
|
|
}
|
|
}
|
|
|
|
cargo {
|
|
module = '../../../../ffi'
|
|
targetDirectory = '../../../../target'
|
|
targetIncludes = ['libmentat_ffi.so', 'libmentat_ffi.dylib', 'libmentat_ffi.dll']
|
|
|
|
targets = [
|
|
'default', // For unit tests.
|
|
'arm',
|
|
'arm64',
|
|
'x86',
|
|
]
|
|
|
|
// This puts the output of `cargo build` (the "default" toolchain) into the correct directory
|
|
// for JNA to find it.
|
|
defaultToolchainBuildPrefixDir = Platform.RESOURCE_PREFIX
|
|
}
|
|
|
|
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 'net.java.dev.jna:jna:4.5.2@jar'
|
|
|
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
|
implementation 'net.java.dev.jna:jna:4.5.2@aar'
|
|
|
|
testImplementation files(configurations.jnaForTest.files)
|
|
testImplementation 'junit:junit:4.12'
|
|
testImplementation 'org.robolectric:robolectric:3.8'
|
|
testImplementation 'org.mockito:mockito-core:2.20.0'
|
|
|
|
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
|
|
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
|
androidTestImplementation 'com.android.support.test:rules:1.0.2'
|
|
}
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
|
|
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["generate${productFlavor}${buildType}Assets"].dependsOn(tasks["cargoBuild"])
|
|
|
|
tasks["process${productFlavor}${buildType}UnitTestJavaRes"].dependsOn(tasks["cargoBuild"])
|
|
}
|
|
}
|
|
|
|
archivesBaseName = 'mentat'
|
|
|
|
apply from: '../publish.gradle'
|
|
ext.configurePublish(
|
|
'org.mozilla.mentat',
|
|
'mentat',
|
|
'A persistent, embedded knowledge base.')
|