Skip to content

Common pitfalls

Ely Deckers edited this page Jan 7, 2021 · 2 revisions

Dependency conflicts

When you're working on a project that contains multiple dependencies, chances are you will run into some version conflicts eventually (e.g. #106). The way I suggest you fix these for Android is by forcing one specific version fo the conflicting dependencies. The case below illustrates how to fix a conflict between different versions of the org.jetbrains.kotlinx:kotlinx-coroutines-core library:

# file: app/build.gradle

(...)
dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
+    implementation('org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7') { force = true }
+    implementation('org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.3.7') { force = true }
    implementation "com.facebook.react:react-native:+"  // From node_modules
(...)

Duplicate files copied

Sometimes forcing a specific version of a dependency alone isn't enough though, for example when duplicate files are copied. In case of a duplication you'll be confronted with an error like this:

Execution failed for task ':mergeDebugAndroidTestJavaResource'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > More than one file was found with OS independent path 'META-INF/AL2.0'.

The duplicate file in the example isn't a curial file for the app though, since it is a license file. We can easily resolve the situation by just picking the first encountered file:

# file: app/build.gradle

(...)
android {
(...)
   packagingOptions {
+        pickFirst 'META-INF/AL2.0'
+        pickFirst 'META-INF/LGPL2.1'
   }
(...)

Note that it is possible to exclude the license files altogether, and while this doesn't sound like a bad idea on itself, this practice violates most open source licenses in that most of them dictate that all distributions of the software are required to contain an unaltered copy of said license.

Clone this wiki locally