52235

UNEXPECTED TOP-LEVEL EXCEPTION: in Android Studio

Question:

I know it has been asked too many times here but I can't still resolve the issue. I have tried solutions provided in previous questions but they are not working somehow.

Here's my gradle dependency -

compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.google.code.gson:gson:2.3.1' compile 'com.android.support:appcompat-v7:23.1.0' compile 'com.android.support:support-v4:23.1.0' compile 'com.google.android.gms:play-services:8.1.0' compile 'com.facebook.android:facebook-android-sdk:3.22.0' compile project(':IndicatorLib') compile 'com.makeramen:roundedimageview:1.5.0' compile 'com.github.clans:fab:1.5.0' // GMS in the library was causing merging error, we need to exclude the duplicate dependencies compile ('io.nlopez.smartlocation:library:3.2.0') { exclude group: 'com.google.android.gms'}

Here's my gradle dependencies output -

_releaseApk - ## Internal use, do not manually configure ## +--- com.google.code.gson:gson:2.3.1 +--- com.android.support:appcompat-v7:23.1.0 | \--- com.android.support:support-v4:23.1.0 | \--- com.android.support:support-annotations:23.1.0 +--- com.google.android.gms:play-services:8.1.0 | +--- com.google.android.gms:play-services-ads:8.1.0 | | +--- com.google.android.gms:play-services-basement:8.1.0 | | | \--- com.android.support:support-v4:22.2.0 -> 23.1.0 (*) | | \--- com.google.android.gms:play-services-appindexing:8.1.0 | | \--- com.google.android.gms:play-services-basement:8.1.0 (*) | +--- com.google.android.gms:play-services-analytics:8.1.0 | | +--- com.google.android.gms:play-services-basement:8.1.0 (*) | | \--- com.google.android.gms:play-services-ads:8.1.0 (*) | +--- com.google.android.gms:play-services-appindexing:8.1.0 (*) | +--- com.google.android.gms:play-services-appinvite:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 | | \--- com.google.android.gms:play-services-basement:8.1.0 (*) | +--- com.google.android.gms:play-services-appstate:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-basement:8.1.0 (*) | +--- com.google.android.gms:play-services-cast:8.1.0 | | +--- com.google.android.gms:play-services-base:8.1.0 (*) | | \--- com.android.support:mediarouter-v7:22.2.0 | | \--- com.android.support:appcompat-v7:22.2.0 -> 23.1.0 (*) | +--- com.google.android.gms:play-services-drive:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-fitness:8.1.0 | | +--- com.google.android.gms:play-services-base:8.1.0 (*) | | \--- com.google.android.gms:play-services-location:8.1.0 | | +--- com.google.android.gms:play-services-base:8.1.0 (*) | | \--- com.google.android.gms:play-services-maps:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-games:8.1.0 | | +--- com.google.android.gms:play-services-base:8.1.0 (*) | | \--- com.google.android.gms:play-services-drive:8.1.0 (*) | +--- com.google.android.gms:play-services-gcm:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-identity:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-location:8.1.0 (*) | +--- com.google.android.gms:play-services-maps:8.1.0 (*) | +--- com.google.android.gms:play-services-measurement:8.1.0 | | +--- com.google.android.gms:play-services-base:8.1.0 (*) | | \--- com.google.android.gms:play-services-analytics:8.1.0 (*) | +--- com.google.android.gms:play-services-nearby:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-panorama:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-plus:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-safetynet:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-vision:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-wallet:8.1.0 | | +--- com.google.android.gms:play-services-base:8.1.0 (*) | | +--- com.google.android.gms:play-services-identity:8.1.0 (*) | | \--- com.google.android.gms:play-services-maps:8.1.0 (*) | \--- com.google.android.gms:play-services-wearable:8.1.0 | \--- com.google.android.gms:play-services-base:8.1.0 (*) +--- com.facebook.android:facebook-android-sdk:3.22.0 | +--- com.android.support:support-v4:[21,22) -> 23.1.0 (*) | \--- com.parse.bolts:bolts-android:1.1.4 +--- project :IndicatorLib | \--- com.android.support:support-v4:21.0.3 -> 23.1.0 (*) +--- com.makeramen:roundedimageview:1.5.0 +--- com.github.clans:fab:1.5.0 \--- io.nlopez.smartlocation:library:3.2.0 \--- com.android.support:support-annotations:23.0.1 -> 23.1.0 _releaseCompile - ## Internal use, do not manually configure ## +--- com.google.code.gson:gson:2.3.1 +--- com.android.support:appcompat-v7:23.1.0 | \--- com.android.support:support-v4:23.1.0 | \--- com.android.support:support-annotations:23.1.0 +--- com.google.android.gms:play-services:8.1.0 | +--- com.google.android.gms:play-services-ads:8.1.0 | | +--- com.google.android.gms:play-services-basement:8.1.0 | | | \--- com.android.support:support-v4:22.2.0 -> 23.1.0 (*) | | \--- com.google.android.gms:play-services-appindexing:8.1.0 | | \--- com.google.android.gms:play-services-basement:8.1.0 (*) | +--- com.google.android.gms:play-services-analytics:8.1.0 | | +--- com.google.android.gms:play-services-basement:8.1.0 (*) | | \--- com.google.android.gms:play-services-ads:8.1.0 (*) | +--- com.google.android.gms:play-services-appindexing:8.1.0 (*) | +--- com.google.android.gms:play-services-appinvite:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 | | \--- com.google.android.gms:play-services-basement:8.1.0 (*) | +--- com.google.android.gms:play-services-appstate:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-basement:8.1.0 (*) | +--- com.google.android.gms:play-services-cast:8.1.0 | | +--- com.google.android.gms:play-services-base:8.1.0 (*) | | \--- com.android.support:mediarouter-v7:22.2.0 | | \--- com.android.support:appcompat-v7:22.2.0 -> 23.1.0 (*) | +--- com.google.android.gms:play-services-drive:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-fitness:8.1.0 | | +--- com.google.android.gms:play-services-base:8.1.0 (*) | | \--- com.google.android.gms:play-services-location:8.1.0 | | +--- com.google.android.gms:play-services-base:8.1.0 (*) | | \--- com.google.android.gms:play-services-maps:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-games:8.1.0 | | +--- com.google.android.gms:play-services-base:8.1.0 (*) | | \--- com.google.android.gms:play-services-drive:8.1.0 (*) | +--- com.google.android.gms:play-services-gcm:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-identity:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-location:8.1.0 (*) | +--- com.google.android.gms:play-services-maps:8.1.0 (*) | +--- com.google.android.gms:play-services-measurement:8.1.0 | | +--- com.google.android.gms:play-services-base:8.1.0 (*) | | \--- com.google.android.gms:play-services-analytics:8.1.0 (*) | +--- com.google.android.gms:play-services-nearby:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-panorama:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-plus:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-safetynet:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-vision:8.1.0 | | \--- com.google.android.gms:play-services-base:8.1.0 (*) | +--- com.google.android.gms:play-services-wallet:8.1.0 | | +--- com.google.android.gms:play-services-base:8.1.0 (*) | | +--- com.google.android.gms:play-services-identity:8.1.0 (*) | | \--- com.google.android.gms:play-services-maps:8.1.0 (*) | \--- com.google.android.gms:play-services-wearable:8.1.0 | \--- com.google.android.gms:play-services-base:8.1.0 (*) +--- com.facebook.android:facebook-android-sdk:3.22.0 | +--- com.android.support:support-v4:[21,22) -> 23.1.0 (*) | \--- com.parse.bolts:bolts-android:1.1.4 +--- project :IndicatorLib | \--- com.android.support:support-v4:21.0.3 -> 23.1.0 (*) +--- com.makeramen:roundedimageview:1.5.0 +--- com.github.clans:fab:1.5.0 \--- io.nlopez.smartlocation:library:3.2.0 \--- com.android.support:support-annotations:23.0.1 -> 23.1.0

From what I think, smartlocation library is the main culprit which is causing the issue since if I remove this library, the app is building correctly. According to the <a href="https://github.com/mrmans0n/smart-location-lib/blob/master/library/build.gradle" rel="nofollow">build.gradle</a> of the library, the only thing I think which can conflict is GMS library, for which I have added exclude but this is also giving the same error. What else can I do to resolve the problem?

<strong>Update :-</strong>

Here's the error log -

Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.internal.LoggedErrorException: Failed to run command: F:\Android SDK\build-tools\21.1.2\dx.bat --dex --no-optimize --output F:\Android Projects\Office Projects\Git Synced\new\app\build\intermediates\dex\debug --input-list=F:\Android Projects\Office Projects\Git Synced\new\app\build\intermediates\dex\debug\inputList.txt Error Code: 2 Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502) at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277) at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168) at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303) at com.android.dx.command.dexer.Main.run(Main.java:246) at com.android.dx.command.dexer.Main.main(Main.java

:215) at com.android.dx.command.Main.main(Main.java:106)

Answer1:

The error means your application and the libraries it references reach a certain size, you encounter build errors that indicate your app has reached a limit of the Android app build architecture.

So you have to make it <a href="https://developer.android.com/tools/building/multidex.html" rel="nofollow">MultiDexApplication</a>

Part of gradle

android { compileSdkVersion 21 buildToolsVersion "21.1.0" defaultConfig { minSdkVersion 14 targetSdkVersion 21 // Enabling multidex support. multiDexEnabled true } } dependencies { compile 'com.android.support:multidex:1.0.0' }

Create a class that extends MultiDexApplication and define that class in manifest

class

public class CustomMultiDexApplication extends MultiDexApplication { @Override public void onCreate() { super.onCreate(); } }

manifest

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.multidex.myapplication"> <application android:name="your.package.name.CustomMultiDexApplication"> </application> </manifest>

One tip as support v7 includes support v4 so don't need to add dependency of v4 library.

Recommend

  • Android app fullscreen with no Title bar and no Action bar
  • Issue in implementing the Ngrx Store service into my component
  • Disable Clock App in Windows 6.5
  • Android: How can I use the new Chromecast icons with CastCompanionLibrary
  • IBM Worklight 5.0.6.1 - Push Notification through Proxy Server
  • android device specific push notifications by using azure mobile services
  • AsyncTask: ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[]
  • Is it possible to encrypt data with AES (256 bit) GCM mode in .net framework 4.7?
  • Can I use GCM for a new application based on Android 2.2 FroYo?
  • Why is Java drawing slow on a new PC? - VSYNC?
  • Error while delivering the message: ServiceIntent not found
  • Least Common Multiple of an array values using Euclidean Algorithm
  • Mobx Inject, Observer and HoC together
  • NullInjectorError: No provider for ReducerManager
  • AWS SNS - Push for GCM showing as sent from Cloudwatch but not received in Mobile Device
  • Do android scheduled jobs survive an app upgrade?
  • Error when setting up google analytics in swift 2 and xcode 7 beta 4
  • Which API key for android GCM server
  • How to stop casting when another app starts casting?
  • Could not find the gcm.jar error when creating App Engine backend => suggests installing deprecat
  • strategy for syncing Android app database with a remote API
  • “start” command in .bat batch file
  • Failed to resolve: support-core-ui
  • Google Analytics with jQuery - show pathname in label
  • youtube analytics api rows empty
  • Flush google analytics events manually with Google Play Services
  • Can I have the market update an app that was installed from else where?
  • multiplayer game with bluetooth [iphone]
  • Android GCM push notification without server OR GCM push notification using Microsoft SQL(Not Mysql)
  • RavenDB indexing errors
  • Multiple Left Join LINQ-to-entities
  • Suqueries in select clause with JPA
  • In matplotlib, how do you change the fontsize of a single figure?
  • Spring: No transaction manager has been configured
  • Default parameter as generic type
  • accepts_nested_attributes_for practical form use for in Rails 3
  • Object and struct member access and address offset calculation
  • Android Google Maps API v2 start navigation
  • Jenkins: How To Build multiple projects from a TFS repository?
  • using HTMLImports.whenReady not working in chrome