diff --git a/sdks/android/Mentat/library/build.gradle b/sdks/android/Mentat/library/build.gradle index 680ec094..cf33a652 100644 --- a/sdks/android/Mentat/library/build.gradle +++ b/sdks/android/Mentat/library/build.gradle @@ -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'