[sdks/android] Workaround Android Studio JUnit test runner runtime classpath issue.

This commit is contained in:
Nick Alexander 2018-07-27 10:20:12 -07:00
parent a7d2057bc6
commit e06bfd1b7d

View file

@ -68,11 +68,30 @@ cargo {
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 'net.java.dev.jna:jna:4.5.2'
testImplementation files(configurations.jnaForTest.files)
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:3.8'
testImplementation 'org.mockito:mockito-core:2.20.0'