[sdks/android] Workaround Android Studio JUnit test runner runtime classpath issue.
This commit is contained in:
parent
a7d2057bc6
commit
e06bfd1b7d
1 changed files with 20 additions and 1 deletions
|
@ -68,11 +68,30 @@ cargo {
|
||||||
defaultToolchainBuildPrefixDir = Platform.RESOURCE_PREFIX
|
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 {
|
dependencies {
|
||||||
|
jnaForTest 'net.java.dev.jna:jna:4.5.2@jar'
|
||||||
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
implementation 'net.java.dev.jna:jna:4.5.2@aar'
|
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 'junit:junit:4.12'
|
||||||
testImplementation 'org.robolectric:robolectric:3.8'
|
testImplementation 'org.robolectric:robolectric:3.8'
|
||||||
testImplementation 'org.mockito:mockito-core:2.20.0'
|
testImplementation 'org.mockito:mockito-core:2.20.0'
|
||||||
|
|
Loading…
Reference in a new issue