The best ways to solve UNEXPECTED TOP-LEVEL EXCEPTION?
I will suggest you for this Two step to solve this.
- Check the attached libraries Dependency/hierarchy
- Check which library class or files are cause of the duplication
files or methods count exceed 65k
- How to Check attached libraries Dependency/hierarchy ?
First found the dependency which is used in library which is attached/compiled from the maven/jcenter/mavencentral.Major issue will come with support because it may possible that support-v4 & appcompact already contains in library which is attached from maven (like play service contains v4 ,appcompact attached then no need to attach support-v4 as it already contains.)
How to check Dependency/hierarchy of the attached library in gradle
Gradle menu > :modulename >> Tasks >> android >> Run "androidDependcies"
OR
Gradle menu > :app >> Tasks >> android >> Run "androidDependcies"
By doing so in Gradle Console you will get something like below as a output(output may depends on libraries attached) .Which can give idea about duplication/hierarchy of the libraries
release
+--- LOCAL: picasso-2.5.2.jar
+--- LOCAL: YouTubeAndroidPlayerApi.jar
+--- LOCAL: commons-lang-2.6.jar
+--- LOCAL: signpost-core-1.2.1.1.jar
+--- LOCAL: kxml2_2.3.0.jar
+--- LOCAL: classes.jar
+--- LOCAL: signpost-commonshttp4-1.2.1.1.jar
+--- LOCAL: json-simple-1.1.1.jar
+--- LOCAL: universal-image-loader-1.9.3.jar
+--- LOCAL: linkedin-j-.jar
+--- LOCAL: maps.jar
+--- LOCAL: nineoldandroids-2.4.0.jar
+--- com.android.support:multidex:1.0.1
+--- com.android.support:multidex:1.0.1
+--- com.android.support:appcompat-v7:23.1.1
| --- com.android.support:support-v4:23.1.1
| --- LOCAL: internal_impl-23.1.1.jar
+--- com.google.android.gms:play-services-maps:7.3.0
| --- com.google.android.gms:play-services-base:7.3.0
| --- com.android.support:support-v4:23.1.1
| --- LOCAL: internal_impl-23.1.1.jar
+--- com.google.android.gms:play-services-gcm:7.3.0
| --- com.google.android.gms:play-services-base:7.3.0
| --- com.android.support:support-v4:23.1.1
| --- LOCAL: internal_impl-23.1.1.jar
+--- com.google.android.gms:play-services-location:7.3.0
| +--- com.google.android.gms:play-services-base:7.3.0
| | --- com.android.support:support-v4:23.1.1
| | --- LOCAL: internal_impl-23.1.1.jar
| --- com.google.android.gms:play-services-maps:7.3.0
| --- com.google.android.gms:play-services-base:7.3.0
| --- com.android.support:support-v4:23.1.1
| --- LOCAL: internal_impl-23.1.1.jar
+--- com.google.android.gms:play-services-ads:7.3.0
| +--- com.google.android.gms:play-services-base:7.3.0
| | --- com.android.support:support-v4:23.1.1
| | --- LOCAL: internal_impl-23.1.1.jar
| --- com.google.android.gms:play-services-analytics:7.3.0
| --- com.google.android.gms:play-services-base:7.3.0
| --- com.android.support:support-v4:23.1.1
| --- LOCAL: internal_impl-23.1.1.jar
+--- com.google.android.gms:play-services-analytics:7.3.0
| --- com.google.android.gms:play-services-base:7.3.0
| --- com.android.support:support-v4:23.1.1
| --- LOCAL: internal_impl-23.1.1.jar
+--- com.google.android.gms:play-services-plus:7.3.0
| --- com.google.android.gms:play-services-base:7.3.0
| --- com.android.support:support-v4:23.1.1
| --- LOCAL: internal_impl-23.1.1.jar
--- com.android.support:recyclerview-v7:23.1.1
--- com.android.support:support-v4:23.1.1
--- LOCAL: internal_impl-23.1.1.jar
You can also check this from terminal for the above process .
gradlew app:dependencies
You can check below image as "picture is worth a thousand words"
How to check which class or files causing duplicate entry/or method count exceed 65k ?
Rather than checking on message or error which you are getting Message tab of android studio check it in Gradle Console
If in message error is like while transferring classes to dex :app:transformClassesWithDexForDebug
or :app:transformClassesWithDexForRelease
maximum chances are like because of Multiple dex (method excess 65k limit).
Or if any other error than it will specify like duplicate entry related etc.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…