Error implementing Vimeo-networking - java

I have tried many different ways of getting Vimeo networking into my app, but nothing has worked. If I remove the implementation it works just fine so I know this is the issue.
compile 'com.vimeo.networking:vimeo-networking:1.1.1'
gives me this error
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
I have searched all over and have yet to find a solution (yes I have tried cleaning and rebuilding the project)

SOLUTION: anthonycr's answer was perfect, but I also had to do this:
implementation ("org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version") {
exclude group: 'org.jetbrains', module: 'annotations'
}
implementation ('com.vimeo.networking:vimeo-networking:1.1.1') {
exclude group: 'org.jetbrains', module: 'annotations'
}

I believe this is the result of the vimeo-networking library including a dependency which you are also separately including in your gradle file. Looking at the gradle file for a hint, a prime suspect is the intellij annotations jar 'com.intellij:annotations:12.0#jar' dependency, which I have seen cause similar problems when also included in your main project as well as a sub-projects.
The solution to this is to exclude the annotations jar when compiling in the vimeo-networking library as follows:
compile ('com.vimeo.networking:vimeo-networking:1.1.1') {
exclude group: 'org.jetbrains', module: 'annotations'
}
Try this and see if it fixes your build exception. Generally I've seen that the cause for the Unable to merge dex error is that there are multiple definitions of the same class in the final dex file, usually resulting from the inclusion of a jar file multiple times.

Related

Duplicate class found in modules (exclude packages)

I have added 2 modules in my project but I got the following error
Duplicate class com.bumptech.glide.GeneratedAppGlideModuleImpl found in modules jetified-XXX-XXX-XXX_XXX_0.2-runtime (com.github.YYY:YYY:YYYY_0.2) and jetified-XXX-XXX-XXX-1.0.24-runtime (com.github.XXX:XXX-XXX-XXX:1.0.24)
Duplicate class com.bumptech.glide.GeneratedRequestManagerFactory found in modules jetified-YYY-YYY-YYY_0.2-runtime (com.github.nithraedu:YYYY-YYY:YYY_0.2) and jetified-XXX-XXX-XXX-1.0.24-runtime (com.github.XXX:XXX-XXX-XXX:1.0.24)
how do I solve this problem?
If you have duplicate classes, it shows that you have added dependencies that use the same modules and classes so you must find these dependencies and exclude the duplicates. In your case I think you want to use glide library so you can simply add:
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
In your app level build.gradle file. This is an issue for some of the dependencies that used same classes before AndroidX. The other option for you is to simply migrate to AndroidX which solves these kinds of problems.
if you want to see your dependency_tree and identify what's causing the duplication you can use this command:
gradle -q dependencies yourProject:dependencies --configuration compile
or you can find your dependency_tree in view -> tool-windows -> gradle -> YourAppName -> tasks -> android -> androidDependencies
after that you must find the duplicated module and exclude it from the library dependency to avoid duplication for example:
implementation('com.example.m:m:1.0') {
exclude group: 'org.unwanted', module: 'x
}
https://bumptech.github.io/glide/doc/configuration.html#avoid-appglidemodule-in-libraries
The libraries which you are using glide and it extends the AppGlideModule instead of LibraryGlideModule.

Multiple dex files define Lorg/apache/http/impl/conn/AbstractClientConnAdapter;

The problem:
Gradle error: "Multiple dex files define Lorg/apache/http/impl/conn/AbstractClientConnAdapter;"
The question:
The error message doesn't include much detail. Is there a way to find out which files it's referring to? How can I narrow this down? I'm hoping there's an easy way to do this.
What I've tried:
Putting this for each library in the Gradle file:
exclude module: 'org.apache.http.impl.conn.AbstractClientConnAdapter'
E.g.
implementation (group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2') {
exclude module: 'org.apache.http.impl.conn.AbstractClientConnAdapter'
}
However this doesn't seem to make a difference as I still get the error. I have a multi module project but I'm only running "assemble" on one module which I believe is the problem. There are only 4 library dependencies and no local jars for this module.
What am I not understanding about how "exclude works"? If they're all excluded then where is it coming from?
Other Info:
This is an Android project but the module I'm having the problem with is a pure Java module.
I'm using Android Studio 3.0.
p.s. what is the "L" before org in the error?

Error: json defines classes that conflict with classes now provided by Android

I got the following error when doing a release build on Android Studio 3
Error:Error: json defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
The following is my dependencies:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:support-v4:26.0.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile 'com.evernote:android-job:1.2.0'
compile 'com.amitshekhar.android:android-networking:1.0.0'
compile 'com.facebook.stetho:stetho:1.5.0'
compile "me.tatarka.redux:redux-core:0.10"
compile "me.tatarka.redux:redux-android:0.10"
compile "me.tatarka.redux:redux-android-lifecycle:0.10"
compile "me.tatarka.redux:redux-thunk:0.10"
annotationProcessor "org.immutables:value:2.5.5" // <-- for annotation processor
provided "org.immutables:value:2.5.5" // for annotations
provided "org.immutables:builder:2.5.5" // for annotations
compile "me.tatarka.redux:redux-monitor:0.10"
testCompile 'junit:junit:4.12'
}
It's saying json but I can't find which of the the above dependencies is causing the problem.
Here is what I get when I run
gradlew assembleRelease
Task :app:lintVitalRelease
/Users/kruyvanna/Projects/key/HappyKey_Android2/app/build.gradle: Error: json defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
Explanation for issues of type "DuplicatePlatformClasses":
There are a number of libraries that duplicate not just functionality of
the Android platform but using the exact same class names as the ones
provided in Android -- for example the apache http classes. This can lead
to unexpected crashes.
To solve this, you need to either find a newer version of the library which
no longer has this problem, or to repackage the library (and all of its
dependencies) using something like the jarjar tool, or finally, rewriting
the code to use different APIs (for example, for http code, consider using
HttpUrlConnection or a library like okhttp.)
1 errors, 0 warnings
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:lintVitalRelease'.
Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
...
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Get more help at https://help.gradle.org
I fixed it by adding:
configurations {
all {
exclude group: 'org.json', module: 'json'
}
}
to module gradle file, no removal of dependencies was needed.
Add this in your app/build.gradle
configurations {
all {
exclude module: 'commons-logging'
}
}
Go to the commandline and look at the dependency tree. This will give you a list of everything that your app uses:
./gradlew dependencies
I added dependencies one by one and found this one causing the error
compile "me.tatarka.redux:redux-monitor:0.10"

"Ill-advised or mistaken usage of a core class" error when adding xml-apis-1.4.01.jar as a dependency

I am trying to use HtmlUnit which lists xml-apis-1.4.01.jar as a dependency. Though whenever I include this file in the libs/ directory I get the following error:
Error: trouble processing "javax/xml/XMLConstants.class":
Error: Ill-advised or mistaken usage of a core class (java.* or javax.*)
...
Could anyone help me resolve this.
Thanks!
First of all, don't put .jars into libs folder, as you will quickly run into dependency hell. Use gradle build system for that. In your app module build.gradle file declare such dependency:
compile ('net.sourceforge.htmlunit:htmlunit:2.23') {
exclude module: 'commons-logging'
exclude module: 'httpclient'
}
And everything will build correctly.

UNEXPECTED TOP-LEVEL EXCEPTION while building android app

I have checked multiple times for duplicate dependencies but cannot find anything. Here are the screenshots.
Here is my build.gradle file
Here is my file structure.
Here is the error
Please help. It was running perfect since this morning.
try this and let me know
configurations.all {
exclude group: 'com.google.android', module: 'support-v4'
// other configurations
}
When I have same issue, I replaced compile with provided.
And recommendation - use concrete library that need your app like described here - http://android-developers.blogspot.com/2014/12/google-play-services-and-dex-method.html

Categories