I have android module named A. I added dependency to another module B like so: implementation project(':B'). While the module A builds without an issue, when I try to build (and run) integration tests, I get
Duplicate class org.xmlpull.v1.XmlPullParser found in modules kxml2-2.3.0.jar (net.sf.kxml:kxml2:2.3.0) and xpp3-1.1.3.3.jar (xpp3:xpp3:1.1.3.3)
Duplicate class org.xmlpull.v1.XmlPullParserException found in modules kxml2-2.3.0.jar (net.sf.kxml:kxml2:2.3.0) and xpp3-1.1.3.3.jar (xpp3:xpp3:1.1.3.3)
Duplicate class org.xmlpull.v1.XmlPullParserFactory found in modules kxml2-2.3.0.jar (net.sf.kxml:kxml2:2.3.0) and xpp3-1.1.3.3.jar (xpp3:xpp3:1.1.3.3)
Duplicate class org.xmlpull.v1.XmlSerializer found in modules kxml2-2.3.0.jar (net.sf.kxml:kxml2:2.3.0) and xpp3-1.1.3.3.jar (xpp3:xpp3:1.1.3.3)
I tried to exclude org.xmlpull.kxml by changing my import statement to
implementation (project(':B')) {
exclude group: 'org.xmlpull.v1'
}
but the problem still exists. I have run out of ideas. Can anyone help?
In my case the solution was to exclude xpp3
implementation(':B') {
exclude module: 'xpp3'
}
here is a nice explanation
Related
In my build.gradle (app) I have added this dependency: implementation 'androidx.preference:preference:1.2.0'
When I compile and build my project with the previous dependency these errors are shown:
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
> Duplicate class androidx.lifecycle.ViewModelLazy found in modules jetified-lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1) and lifecycle-viewmodel-2.5.0-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.0)
Duplicate class androidx.lifecycle.ViewTreeViewModelKt found in modules jetified-lifecycle-viewmodel-ktx-2.3.1-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1) and lifecycle-viewmodel-2.5.0-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.0)
I have been searching for information to solve it and adding these both dependencies has solved it but I think that this solution is a botched solution and maybe it can be solved in a really better way.
def lifecycle_version = "2.5.1"
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
Does it exist a better solution to solve it? Thanks for the help
I'm using two library that have dependencies of two different versions of Koin.
One of the library has org.koin:koin-android:2.0.1 and the other has io.insert-koin:koin-core-jvm:3.0.1 dependencies.
At compile time I got tons of Duplicate class error as below,
Duplicate class org.koin.android.BuildConfig found in modules jetified-koin-android-2.0.1-runtime (org.koin:koin-android:2.0.1) and jetified-koin-android-3.0.1-runtime (io.insert-koin:koin-android:3.0.1)
Duplicate class org.koin.android.ext.koin.KoinExtKt$androidContext$1 found in modules jetified-koin-android-2.0.1-runtime (org.koin:koin-android:2.0.1) and jetified-koin-android-3.0.1-runtime (io.insert-koin:koin-android:3.0.1)
Duplicate class org.koin.core.scope.Scope$injectOrNull$1 found in modules jetified-koin-core-2.0.1 (org.koin:koin-core:2.0.1) and jetified-koin-core-jvm-3.0.1 (io.insert-koin:koin-core-jvm:3.0.1)
Duplicate class org.koin.java.KoinJavaComponent$inject$1 found in modules jetified-koin-core-jvm-3.0.1 (io.insert-koin:koin-core-jvm:3.0.1) and jetified-koin-java-2.0.1 (org.koin:koin-java:2.0.1)
...
When I try to exclude one of them as below,
configurations {
all {
exclude group: "io.insert-koin", module: "koin-android"
exclude group: "io.insert-koin", module: "koin-core-jvm"
}
}
I got NoClassDefFoundError at runtime on the relevant one.
When exclude org.koin:koin-android:2.0.1
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.koin.core.KoinComponent" on path: DexPathList[[zip file "/data/app/...
When exclude io.insert-koin:koin-core-jvm:3.0.1
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.koin.core.component.KoinComponent" on path: DexPathList[[zip file "/data/app/...
How can I get to use both libraries?
Koin 3.x.x has no backwards compatibility. If there is no update on the sdk which uses Koin 2.x.x version, maybe you should better find an older version for the opposite library, which uses Koin 2.x.x. But please be aware Koin version 2.2.3 also has a different path than others (Because of jcenter limitations)
How can I get to use both libraries?
You can't use both versions of Koin at the same time, but you can tell Gradle to replace one version by the other at compile time. Note that it's not the same as excluding one of the versions altogether, but really replacing one by the other.
Here's an example:
eachDependency { details ->
// change org.koin:koin-androidx-viewmodel into io.insert-koin:koin-android
if (details.requested.group == 'org.koin' && details.requested.name == 'koin-androidx-viewmodel') {
details.useTarget group: 'io.insert-koin', name: 'koin-android', version: details.requested.version
}
}
You can read more in Gradle's doc https://docs.gradle.org/current/userguide/resolution_rules.html
It is only a partial solution though (and a hacky one too), as we're still limited by the API incompatibilities between Koin 2.x and 3.x. But if what you're using from Koin 2.x is still there in Koin 3.x, that should work.
In my projects, I need to import third party jar file and Facebook SDK.
compile files('libs/SkinSDK.jar')
compile 'com.facebook.android:facebook-android-sdk:4.14.0'
Both include same BundleJSONConverter class. So, I cannot do generate signed APK. It always shows duplicate entry com/facebook/internal/BundleJSONConverter.
So, I want to exclude in Facebook or SkinSDK.jar. I tried like
compile ('com.facebook.android:facebook-android-sdk:4.14.0') {
exclude group: 'com.facebook.internal', module: 'BundleJSONConverter'
}
It's not working and showing same error.
The exclude method of the configuration closure for a dependency excludes transitive dependencies. So, if your module dependency depends on other modules, you can exclude them from your build. You can check out the transitive dependencies of the 'com.facebook.android:facebook-android-sdk:4.14.0' module on its Maven repository info page.
If the BundleJSONConverter class exists in a transitive dependency, you can exclude the specific module in the same way you are trying now. Just specify the group, the module and the version, like you do for dependencies.
If you just want to exclude one class for a dependency jar, take a look at the jar jar links tool and its Gradle plugin. It allows you to alter included jars, e.g. to change packages or remove classes.
The following (shortened) example shows the usage of the plugin and some methods to alter the dependency jar:
compile jarjar.repackage {
from 'org.apache.hive:hive-exec:0.13.0.2.1.5.0-695'
archiveBypass "commons*.jar"
archiveExclude "slf4j*.jar"
classDelete "org.apache.thrift.**"
classRename 'org.json.**', 'org.anarres.hive.json.#1'
}
Bumped into similar situation. This is what I did, not elegant as I hoped, but it works:
Rename the jar file (SkinSDK.jar in your case): .zip instead of .jar
Go "inside" the zip file (I'm using DoubleCommander, there are many other utilities for that), or extract it to a temporary folder.
Delete the duplicate class that causes the problem. Go "outside" the zip file.
Rename (or re-pack) the file from .zip to .jar . Compile.
Hope it works...
I had a similar problem with duplicated classes after importing a jar. In my case, the conflict was between a class in that jar and a class in my own project.
Below I share the solution you can use to discard classes that you have available in your own source tree, assuming the one in the jar is the right one to use:
android {
sourceSets {
main {
java {
filter.excludes = [
"com/package/Duplicated.java",
]
}
}
}
}
ProjectA contains an abstract unit test, TestA.
ProjectB has a test called TestB, which needs to extends from TestA, to fulfil the test requirements for this specific implementation.
I've added to the build.gradle configuration file on ProjectB, ProjectA as a dependency compilation test:
testCompile project(':ProjectA')
Also, as a dependency compilation:
compile project(':ProjectA')
Although I'm able to extend from TestA, when I try to run TestB I get the next error:
error: cannot find symbol class TestA
So, is there any way to share test code between modules?
Thanks.
As mentioned in this question you should add dependency on test sources like this:
compileTestJava.dependsOn tasks.getByPath(':projectA:testClasses')
testCompile files(project(':projectA').sourceSets.test.output.classesDir)
I do know Multiple dex problems have been reported a lot of times before, but none of the solutions seems to work in my case.
Console:
Unable to execute dex: Multiple dex files define Lbolts/AggregateException;
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lbolts/AggregateException;
One of the popular solutions is unmarking the 'Android private libraries' container from buildpath. I cannot do that because there are a few more libraries in that container that i need.
Another solution is unmarking any duplicate library explicitly added in .jar form. I have no such libraries.
The duplicate library in my case is: android-support-v7-appcompat.jar
I have it (directly referenced from the sdk folder) in these two containers:
1.) Android Private Libraries
2.) Android Dependencies
The problem is that i just cannot untick any of these two containers completely, because both of them contain other necessary libraries. But i also am unable to remove just this duplicate .jar file from either containers.
EDIT:
N.B. When i add the android-support-v7-appcompat library_project to my project, it enters into both containers. There must be some way so that goes into only one.
Can any one help me how i can do it?
RESOLVED
bolts-android library was the real trouble here. There were two different versions of it causing a conflict. The FacebookSDK library brings bolts-android-1.1.2, and android-support-v7-appcompat brings bolts-android-1.1.4.
I unmarked Android Private Libraries container in the FacebookSDKlibrary project, which contained bolts-android-1.1.2. As a result, my project now had only one version, bolts-android-1.1.4, settling the conflict. It runs fine now.
Also, turns out, the duplicate android-support-v7-appcompat entries were not an issue.
i encountered this recently on my react native project, you can go to your android folder of your project . and in terminal hit this command "./gradlew app:dependencies" to see dependencies tree. i found two package for android bolts under facebook sdk . if you exclude this package from facebook sdk things will work fine again
compile ('com.facebook.react:react-native:+') {
exclude group: 'com.parse.bolts', module: 'bolts-tasks'
}
This can happen when adding facebook SDK to Android, you can solve it with:
compile ("com.facebook.android:facebook-android-sdk:4.1.0") {
exclude group: 'com.parse.bolts', module: 'bolts-android'
}
as react version has updated to 0.31.0,when you want to integrate com.facebook.fresco:animated-gif:0.10.0 which has com.parse.bolts has well,you may do like this:
compile ('com.facebook.react:react-native:+') {
exclude group: 'com.parse.bolts', module: 'bolts-tasks'
}
compile ('com.facebook.fresco:animated-gif:0.10.0'){
exclude group: 'com.parse.bolts', module: 'bolts-tasks'
}