UNEXPECTED TOP-LEVEL EXCEPTION while building android app - java

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

Related

How do I fix this "Duplicate class error" in Android Studio

I updated implementation com.google.android.gms:play-services-ads:19.8.0 to implementation com.google.android.gms:play-services-ads:20.4.0 and now I get this error:
Duplicate class com.google.android.gms.internal.measurement.zzbs found in modules jetified-play-services-measurement-18.0.2-runtime (com.google.android.gms:play-services-measurement:18.0.2) and jetified-play-services-measurement-sdk-api-18.0.3-runtime (com.google.android.gms:play-services-measurement-sdk-api:18.0.3)
Duplicate class com.google.android.gms.internal.measurement.zzl found in modules jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2) and jetified-play-services-measurement-sdk-api-18.0.3-runtime (com.google.android.gms:play-services-measurement-sdk-api:18.0.3)
Duplicate class com.google.android.gms.measurement.internal.zzfh found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzgn found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzgo found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzgp found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzgq found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
Duplicate class com.google.android.gms.measurement.internal.zzhs found in modules jetified-play-services-measurement-18.0.2-runtime (com.google.android.gms:play-services-measurement:18.0.2) and jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3)
Duplicate class com.google.android.gms.measurement.internal.zzhx found in modules jetified-play-services-measurement-base-18.0.3-runtime (com.google.android.gms:play-services-measurement-base:18.0.3) and jetified-play-services-measurement-impl-18.0.2-runtime (com.google.android.gms:play-services-measurement-impl:18.0.2)
How to fix this error?
I ran into the same issue today, and after many trial and errors, I finally found that it was caused by a firebase dependency. If you're using firebase in your project, make sure to use the latest BoM version in app/build.gradle:
dependencies{
// implementation platform('com.google.firebase:firebase-bom:25.12.0') <-- Produces errors
implementation platform('com.google.firebase:firebase-bom:29.0.0') //<-- This works
}
If you are not using firebase and still get this error, you can try excluding the offending classes directly in app/build.gradle:
android {
defaultConfig {
...
}
buildTypes {
...
}
configurations {
all {
exclude group: "com.google.android.gms", module: "play-services-measurement-impl"
exclude group: "com.google.android.gms", module: "play-services-measurement"
}
}
}
I am having the same issue and I fixed it by downgrading play-services-ads dependency like this. So you can try.
def ads_version = "20.3.0"
implementation "com.google.android.gms:play-services-ads:$ads_version"
The error is being produced due to the conflicts between firebase & google service dependency. So you have 2 options.
You can change the versions and keep doing that until you find the perfect working combination which is time consuming or you can find a solution that works every time so you don't have to play with the versions every time. You just use that solution wherever you get such error.
Here, you need to use the updated method of injecting the firebase dependency as shown in the official documentation.
Put this line in your dependency :
implementation platform('com.google.firebase:firebase-bom:28.1.0')
Then, You can use any firebase dependency without specifying the versions, and it will work flawlessly all the time!
The final code looks like this,
implementation platform('com.google.firebase:firebase-bom:28.1.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-config'
implementation 'com.google.firebase:firebase-crashlytics'
And it won't produce any duplication related errors with the play-services dependency.
Best way to fix this and prepare your project for later is to migrate completely to AndroidX. First check if your project is ready, Refactor > Migrate to AndroidX. Once your project is independent of jcenter or any other older library/repo and compatible with AndroidX you won't need Jetifier anymore, so either comment it out or remove it. This should possibly fix the problem.
...
#android.enableJetifier=false
...
In my case this wasn't enough to solve the problem, if you still receive the same error but from a different library, it's possibly because of other existing dependencies, avoid using bundled libraries or wildcard ones (in which system is left to guess) make sure you update them all and clean rebuild the project.
If you still have to keep some conflicting library, try excluding individual classes to avoid the error like this from build.gradle:
android {
...
defaultConfig {
...
}
buildTypes {
...
}
configurations {
all { // You should exclude one of them not both of them
exclude group: "com.android.support", module: "support-core-ui"
exclude group: "com.android.support", module: "support-compat"
}
}
}
Official docs on module exclusion - Excluding transitive dependencies
I also tried few more things before figuring the solution, like deleting .gradle from local machine, incase some old libraries got cached and causing the error, or resetting Android Studio, it just won't work.
Repo I tested the solution here, as you can see in this line I had to comment out the bundle module and specify latest updates to individual dependencies.
You can read more on module dependency errors for reference.
Add this line android.enableJetifier=true to your gradle.properties

resource android:style/TextAppearance.Material not found

I am trying to write a Hello World program for android. This is my first experience of Java. Gradle is not running properly, and whenever I try to rerun it, it comes up with 24 error messages:
resource android:style/TextAppearance.Material not found
and then lots of attributes of android:style/TextAppearance.Material which are also not found. I have tried searching online for how to put something in styles.xml to fix this, but can't find anything useful.
Try to change you theme to an Android Support Library's material design theme.
Don't forget to include the Support Library as well.
Manifest:
<application android:theme="#style/Theme.AppCompat">
Gradle Build file:
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.0'
}
I would also recommend to you that you read the Styles and Themes documentation. https://developer.android.com/guide/topics/ui/look-and-feel/themes.html
In my case the problem was this:
configurations {
compile.exclude group: 'androidx.annotation', module: 'annotation'
compile.exclude group: 'androidx.core', module: 'core'
}
had to comment this block out and it worked.

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 implementing Vimeo-networking

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.

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"

Categories