Skip to content

Commit e912335

Browse files
committed
Revert "Bug 1823532 - Remove jnaForTest from project Gradle build files."
This reverts commit 92c1b9e.
1 parent 47fd026 commit e912335

File tree

7 files changed

+85
-0
lines changed

7 files changed

+85
-0
lines changed

android-components/build.gradle

+22
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,28 @@ subprojects {
228228
}
229229
}
230230

231+
configurations {
232+
// There's an interaction between Gradle's resolution of dependencies with different types
233+
// (@jar, @aar) for `implementation` and `testImplementation` and with Android Studio's built-in
234+
// JUnit test runner. The runtime classpath in the built-in JUnit test runner gets the
235+
// dependency from the `implementation`, which is type @aar, and therefore the JNA dependency
236+
// doesn't provide the JNI dispatch libraries in the correct Java resource directories. I think
237+
// what's happening is that @aar type in `implementation` resolves to the @jar type in
238+
// `testImplementation`, and that it wins the dependency resolution battle.
239+
//
240+
// A workaround is to add a new configuration which depends on the @jar type and to reference
241+
// the underlying JAR file directly in `testImplementation`. This JAR file doesn't resolve to
242+
// the @aar type in `implementation`. This works when invoked via `gradle`, but also sets the
243+
// correct runtime classpath when invoked with Android Studio's built-in JUnit test runner.
244+
// Success!
245+
jnaForTest
246+
}
247+
248+
dependencies {
249+
jnaForTest ComponentsDependencies.thirdparty_jna
250+
testImplementation files(configurations.jnaForTest.copyRecursive().files)
251+
}
252+
231253
if (project.hasProperty("coverage") && project.name != "support-test") {
232254
android.buildTypes.all { buildType ->
233255
tasks.withType(Test).configureEach() {

android-components/components/service/glean/build.gradle

+17
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ android {
2323
namespace 'mozilla.components.service.glean'
2424
}
2525

26+
configurations {
27+
// There's an interaction between Gradle's resolution of dependencies with different types
28+
// (@jar, @aar) for `implementation` and `testImplementation` and with Android Studio's built-in
29+
// JUnit test runner. The runtime classpath in the built-in JUnit test runner gets the
30+
// dependency from the `implementation`, which is type @aar, and therefore the JNA dependency
31+
// doesn't provide the JNI dispatch libraries in the correct Java resource directories. I think
32+
// what's happening is that @aar type in `implementation` resolves to the @jar type in
33+
// `testImplementation`, and that it wins the dependency resolution battle.
34+
//
35+
// A workaround is to add a new configuration which depends on the @jar type and to reference
36+
// the underlying JAR file directly in `testImplementation`. This JAR file doesn't resolve to
37+
// the @aar type in `implementation`. This works when invoked via `gradle`, but also sets the
38+
// correct runtime classpath when invoked with Android Studio's built-in JUnit test runner.
39+
// Success!
40+
jnaForTest
41+
}
42+
2643
// Define library names and version constants.
2744
String GLEAN_LIBRARY = "org.mozilla.telemetry:glean:${Versions.mozilla_glean}"
2845
String GLEAN_LIBRARY_FORUNITTESTS = "org.mozilla.telemetry:glean-native-forUnitTests:${Versions.mozilla_glean}"

android-components/plugins/dependencies/src/main/java/DependenciesPlugin.kt

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ object Versions {
3939
// zxing 3.4+ requires a minimum API of 24 or higher
4040
const val zxing = "3.3.3"
4141

42+
const val jna = "5.13.0"
4243
const val disklrucache = "2.0.2"
4344
const val leakcanary = "2.10"
4445

@@ -196,6 +197,7 @@ object ComponentsDependencies {
196197
const val thirdparty_okhttp_urlconnection = "com.squareup.okhttp3:okhttp-urlconnection:${Versions.okhttp}"
197198
const val thirdparty_sentry_latest = "io.sentry:sentry-android:${Versions.sentry_latest}"
198199
const val thirdparty_zxing = "com.google.zxing:core:${Versions.zxing}"
200+
const val thirdparty_jna = "net.java.dev.jna:jna:${Versions.jna}@jar"
199201
const val thirdparty_disklrucache = "com.jakewharton:disklrucache:${Versions.disklrucache}"
200202

201203
const val firebase_messaging = "com.google.firebase:firebase-messaging:${Versions.Firebase.messaging}"

fenix/app/build.gradle

+20
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,23 @@ nimbus {
470470
experimenterManifest = ".experimenter.yaml"
471471
}
472472

473+
configurations {
474+
// There's an interaction between Gradle's resolution of dependencies with different types
475+
// (@jar, @aar) for `implementation` and `testImplementation` and with Android Studio's built-in
476+
// JUnit test runner. The runtime classpath in the built-in JUnit test runner gets the
477+
// dependency from the `implementation`, which is type @aar, and therefore the JNA dependency
478+
// doesn't provide the JNI dispatch libraries in the correct Java resource directories. I think
479+
// what's happening is that @aar type in `implementation` resolves to the @jar type in
480+
// `testImplementation`, and that it wins the dependency resolution battle.
481+
//
482+
// A workaround is to add a new configuration which depends on the @jar type and to reference
483+
// the underlying JAR file directly in `testImplementation`. This JAR file doesn't resolve to
484+
// the @aar type in `implementation`. This works when invoked via `gradle`, but also sets the
485+
// correct runtime classpath when invoked with Android Studio's built-in JUnit test runner.
486+
// Success!
487+
jnaForTest
488+
}
489+
473490
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
474491
kotlinOptions {
475492
freeCompilerArgs += [
@@ -480,6 +497,9 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
480497
}
481498

482499
dependencies {
500+
jnaForTest FenixDependencies.jna
501+
testImplementation files(configurations.jnaForTest.copyRecursive().files)
502+
483503
implementation project(':browser-engine-gecko')
484504

485505
implementation FenixDependencies.kotlin_coroutines

fenix/buildSrc/src/main/java/FenixDependencies.kt

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ object FenixVersions {
1818
const val leakcanary = "2.10"
1919
const val osslicenses_plugin = "0.10.4"
2020
const val detekt = "1.19.0"
21+
const val jna = "5.13.0"
2122

2223
const val androidx_activity = "1.6.1"
2324
const val androidx_compose = "1.3.1"
@@ -120,6 +121,8 @@ object FenixDependencies {
120121
const val adjust = "com.adjust.sdk:adjust-android:${FenixVersions.adjust}"
121122
const val installreferrer = "com.android.installreferrer:installreferrer:${FenixVersions.installreferrer}"
122123

124+
const val jna = "net.java.dev.jna:jna:${FenixVersions.jna}@jar"
125+
123126
const val junit = "junit:junit:${FenixVersions.junit}"
124127
const val mockk = "io.mockk:mockk:${FenixVersions.mockk}"
125128
const val mockk_android = "io.mockk:mockk-android:${FenixVersions.mockk}"

focus-android/app/build.gradle

+19
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,23 @@ nimbus {
207207
experimenterManifest = ".experimenter.yaml"
208208
}
209209

210+
configurations {
211+
// There's an interaction between Gradle's resolution of dependencies with different types
212+
// (@jar, @aar) for `implementation` and `testImplementation` and with Android Studio's built-in
213+
// JUnit test runner. The runtime classpath in the built-in JUnit test runner gets the
214+
// dependency from the `implementation`, which is type @aar, and therefore the JNA dependency
215+
// doesn't provide the JNI dispatch libraries in the correct Java resource directories. I think
216+
// what's happening is that @aar type in `implementation` resolves to the @jar type in
217+
// `testImplementation`, and that it wins the dependency resolution battle.
218+
//
219+
// A workaround is to add a new configuration which depends on the @jar type and to reference
220+
// the underlying JAR file directly in `testImplementation`. This JAR file doesn't resolve to
221+
// the @aar type in `implementation`. This works when invoked via `gradle`, but also sets the
222+
// correct runtime classpath when invoked with Android Studio's built-in JUnit test runner.
223+
// Success!
224+
jnaForTest
225+
}
226+
210227
dependencies {
211228
implementation FocusDependencies.androidx_appcompat
212229
implementation FocusDependencies.androidx_browser
@@ -304,6 +321,8 @@ dependencies {
304321
focusImplementation FocusDependencies.adjust
305322
focusImplementation FocusDependencies.install_referrer // Required by Adjust
306323

324+
jnaForTest FocusDependencies.jna
325+
testImplementation files(configurations.jnaForTest.copyRecursive().files)
307326
testImplementation "org.mozilla.telemetry:glean-native-forUnitTests:${project.ext.glean_version}"
308327

309328
testImplementation FocusDependencies.testing_junit_api

focus-android/buildSrc/src/main/java/FocusDependencies.kt

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ object FocusVersions {
6363
}
6464

6565
object ThirdParty {
66+
const val jna = "5.13.0"
6667
const val leakcanary = "2.10"
6768
const val osslicenses_plugin = "0.10.4"
6869
const val sentry = "6.15.0"
@@ -110,6 +111,7 @@ object FocusDependencies {
110111
const val google_play = "com.google.android.play:core:${FocusVersions.Google.play}"
111112
const val kotlin_gradle_plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${FocusVersions.Gradle.kotlin_plugin}"
112113
const val android_gradle_plugin = "com.android.tools.build:gradle:${FocusVersions.Gradle.android_plugin}"
114+
const val jna = "net.java.dev.jna:jna:${FocusVersions.ThirdParty.jna}@jar"
113115
const val leakcanary = "com.squareup.leakcanary:leakcanary-android-core:${FocusVersions.ThirdParty.leakcanary}"
114116
const val sentry = "io.sentry:sentry-android:${FocusVersions.ThirdParty.sentry}"
115117

0 commit comments

Comments
 (0)