Multiple dex files define Lorg/apache/commons/logging/impl/LogFactoryImpl - android

As the title says, Multiple dex files are being defined, I'ven been digging around with no luck on how to solve this one, so I decided to reach out on the community, to make the story short, I'm updating the gradle build system of this legacy project from gradle 0+ to gradle 3+, I managed to refactor the common configurations such as flavoring, dependencies (from compile to api/implementation), (you name it..), until I stumbled on this dex issue, the first thing that came to my mind is to break down the dependencies by the help of Using gradle to find dependency tree, but unfortunately its taking my time too much on gradlew commands and still ending up with gradlew issues(unable to execute AndroidSdk something), so I took a step back(to minimize the time I needed) and did this... (playing the odds)
dependencies {
api (project(':<omitted project name>')) {
exclude group: 'org.apache.commons', module: 'logging'
}
api (project(':<omitted project name>')) {
exclude group: 'org.apache.commons', module: 'logging'
}
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:design:23.1.0'
implementation ('com.google.code.gson:gson:2.3'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.squareup.picasso:picasso:2.5.2'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.squareup.okhttp:okhttp:2.4.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('org.bitbucket.b_c:jose4j:0.5.2'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'commons-io',name:'commons-io',version: '2.0.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'com.jcraft', name: 'jsch', version: '0.1.44-1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.android.support:design:23.1.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.android.support:appcompat-v7:24.2.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.facebook.android:facebook-android-sdk:4.10.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-gcm:9.0.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-auth:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.github.PhilJay:MPAndroidChart:v3.0.2'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'org.apache.commons', name: 'commons-compress', version: '1.3') {
exclude group: 'org.apache.commons', module: 'logging'
}
implementation (group: 'org.apache.commons', name: 'commons-vfs2', version: '2.2') {
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('io.socket:socket.io-client:1.0.0') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
exclude group: 'org.apache.commons', module: 'logging'
}
api fileTree(dir: 'libs', include: ['*.jar'])
api files('libs/nfc7003.jar')
api files('libs/minilcd7003.jar')
api files('libs/Scan7003.jar')
api files('libs/UserInterface.jar')
api files('libs/printer7003.jar')
}
I cant figure out whos dependency in the above list has this transitive issue with the logging framework, I define an exclusion on them all, still no luck..
just to mention the reason behind : I need the advance profiling of Android studio 3, and the latest gradle(4+)/build tool(3+) must be used to be able to do so, that lead me here ..
please help me on this one, thanks in advance...
[Edit] Build message:
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define
Lorg/apache/commons/logging/impl/LogFactoryImpl$2;
Error:com.android.dex.DexException: Multiple dex files define
Lorg/apache/commons/logging/impl/LogFactoryImpl$2;
Error: at
com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
Error: at
com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
Error: at
com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
Error: at
com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Error: at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error: at
com.android.builder.dexing.
DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error: at
com.android.builder.dexing.
DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error: at java.util.concurrent.
ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error: at
java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error: at
java.util.concurrent.
ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error: at
java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error: at
java.util.concurrent.
ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task '
:<omitted project name>:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException:
com.android.dex.DexException: Multiple dex files define
Lorg/apache/commons/logging/impl/LogFactoryImpl$2;

The problem is because you are using duplicated library in your build.gradle.
First, for support library, you need to use the same version. Do not use the following:
implementation 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:design:23.1.0'
implementation ('com.android.support:design:23.1.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.android.support:appcompat-v7:24.2.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
instead use the following:
implementation 'com.android.support:support-v4:25.4.0'
implementation 'com.android.support:design:25.4.0'
// appcompat is implicitly include within support design.
Second, for google play service, use the same version. Do not use the following:
implementation ('com.google.android.gms:play-services:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-gcm:9.0.1'){
exclude group: 'org.apache.commons', module: 'logging'
}
implementation ('com.google.android.gms:play-services-auth:9.8.0'){
exclude group: 'org.apache.commons', module: 'logging'
}
instead use:
// Dont use the whole play service library
//implementation 'com.google.android.gms:play-services:9.8.0'
implementation 'com.google.android.gms:play-services-gcm:9.8.0'
implementation 'com.google.android.gms:play-services-auth:9.8.0'
Third, to exclude common-logging you need to use something like this:
compile(group: 'org.apache.commons', name: 'commons-compress', version: '1.3'){
exclude group: 'commons-logging', module: 'commons-logging'
}
or use the following:
configurations.all {
exclude group: "commons-logging", module: "commons-logging"
}
You don't need to adding exclude to every library because some library didn't have any commons-logging inside them.

try
// https://mvnrepository.com/artifact/commons-io/commons-io
compile group: 'commons-io', name: 'commons-io', version: '2.6'
remove all exclude options and commons-io.
above dependency might just work fine

Related

PeriodicWorkRequest with compileSdkVersion 21

I am trying to add PeriodicWorkRequest on an old project. That uses compileSdkVersion 21. I can not update compileSDKVersion.
This is my build.gradle
implementation 'com.android.support:support-v4:21.0.3'
implementation ('com.google.firebase:firebase-messaging:9.8.0')
//{
//exclude group: "com.android.support", module: "support-v4"
//}
implementation ('android.arch.work:work-runtime:1.0.1')
{
exclude group: "com.android.support", module: "support-compat"
exclude group: "com.android.support", module: "support-core-ui"
exclude group: "com.android.support", module: "support-fragment"
exclude group: "com.android.support", module: "support-core-utils"
}
I get these errors:
Android resource linking failed
build\intermediates\packaged_manifests\debug\AndroidManifest.xml:408: AAPT: error: attribute android:directBootAware not found.
Is it possible to include WorkManager in my project?
Thanks

Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.ClassNotFoundException - NOT multidex related

On some android phones only the latest build of our app is crashing with
Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.ClassNotFoundException
It's occurring on a phone running Android 5.1.1.
The problem is NOT multidex-related (all other answers I've googled relate to multidex; we've had multidex enabled in our apps for years).
I'm assuming it's related to us updating to the latest Admob, but I haven't been able to find any related advice online.
We're pulling in the following:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:4.2.0'
}
dependencies {
// NEW FUSE INTEGRATION
compile('com.upsight.android:mediation-core:2.12.0') {
exclude group: 'com.google.android.gms', module: 'play-services'
//exclude group: 'com.google.android.gms', module: 'play-services-basement'
exclude group: 'com.android.support'
exclude group: 'com.upsight.android', module: 'mediation-ad-network-u2'
exclude group: 'com.upsight.android', module: 'mediation-ad-network-m2'
exclude group: 'com.upsight.android', module: 'mediation-ad-network-ac'
exclude group: 'com.upsight.android', module: 'mediation-ad-network-al'
exclude group: 'com.upsight.android', module: 'mediation-ad-network-vungle'
}
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:support-v13:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:multidex:1.0.3'
// compile files('libs/FlurryAnalytics_6.7.0.jar')
implementation 'com.flurry.android:analytics:11.3.0#aar'
// compile 'com.flurry.android:marketing:11.3.0#aar' ' No longer needed for Push'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-ads:17.0.0'
implementation('com.adincube.sdk:AdinCube-Java-1626ebe:2.+#aar') {
transitive = true
}
implementation 'com.google.android.ads.consent:consent-library:1.0.6'
// Fyber
implementation (name:'ia-sdk-core-release-7.3.1', ext:'aar')
implementation (name:'ia-video-kit-release-7.3.1', ext:'aar')
implementation (name:'ia-mraid-kit-release-7.3.1', ext:'aar')
implementation (name:'ia-native-kit-release-7.3.1', ext:'aar')
implementation 'com.google.code.gson:gson:2.7'
implementation ('com.google.android.gms:play-services-base:16.1.0')
//implementation ('com.google.android.gms:play-services-ads-identifier:17.2.0')
}
In this case, updating the Gradle build tools to
com.android.tools.build:gradle:3.1.3
eliminated the problem. Previously they were at 3.0.1
So, one more thing for people to try if they come across this problem!

React Native not compile in release

I compile my proeject with react-native-camera and another libs to android.
when I try to compile my project in release with this code:
compile (project(':react-native-camera')) {
exclude group: "com.google.android.gms"
exclude group: "com.android.support"
}
and I receive this error:
com.android.build.api.transform.TransformException:
java.util.zip.ZipException: duplicate entry:
com/facebook/infer/annotation/Assertions.class
so I try to compile add infe-anotation to not compile
compile (project(':react-native-camera')) {
exclude group: "com.google.android.gms"
exclude group: "com.android.support"
exclude group: "com.facebook.infer.annotation"
}
compile to release but not run the app.

Error:Conflict with dependency 'com.android.support: when update from 23.1.1 to 23.4.0

I have upgrade my build.gradle from
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
to
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
However, the existence of below test libraries cause some gradle sync error
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'support-annotations'
exclude module: 'recyclerview-v7'
}
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2')
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.2'
The error is
Error:Conflict with dependency 'com.android.support:appcompat-v7'. Resolved versions for app (23.4.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
Error:Conflict with dependency 'com.android.support:design'. Resolved versions for app (23.4.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
Error:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.4.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
How could I resolve this conflicts? Should I upgrade my test libraries as well (how to know which version to upgrade to)?
I perform various exclusion to resolve the problem. I hope there's a better answer (e.g. upgrade the test library?).
androidTestCompile ('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test:rules:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'design'
exclude module: 'support-annotations'
exclude module: 'recyclerview-v7'
}
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test.espresso:espresso-web:2.2.2') {
exclude group: 'com.android.support', module: 'support-annotations'
}

app:transformClassesWithJarMergingForDebug FAILED

when I try to run the app I am getting this error
before
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzsk.class
Now
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzqz$zza.class
I referred this,this and this. Tried the solutions mentioned there. Still I am far away from solving the Issue.
Please have a look on the app build gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile('com.android.support:appcompat-v7:23.1.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.android.support:recyclerview-v7:23.1.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.android.support:cardview-v7:23.1.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.android.support:design:23.1.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'com.clevertap.android:clevertap-android-sdk:2.0.11'
compile 'com.android.support:support-v4:23.1.1'
compile('com.google.android.gms:play-services-analytics:8.3.0')
{
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.google.guava'
}
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile "com.squareup.picasso:picasso:2.4.0"
compile('com.google.android.gms:play-services-gcm:8.3.0') {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.google.guava'
}
compile('com.google.android.gms:play-services:8.3.0') {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.google.guava'
}
compile 'de.hdodenhof:circleimageview:1.3.0'
compile project(':volley')
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
transitive = true;
}
compile 'com.android.support:multidex:'
apply plugin: 'com.google.gms.google-services'
}
I am happy to provide more information if needed.
UPDATE
When I comment compile 'com.clevertap.android:clevertap-android-sdk:2.0.11' It is working fine.
please check if some of your dependencies have multidex as dependency and exclude it. For example for Facebook SDK: you have this
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
change to this
compile('com.facebook.android:facebook-android-sdk:4.7.0') {
exclude group: 'com.android.support', module: 'multidex'
}
and check for other also.
Solved the issue by updating the com.google.android.gms:play-services version
from 8.3.0 to 8.4.0

Categories

Resources