Android Studio - Unexpected Top-Level Exception:

UNEXPECTED TOP-LEVEL EXCEPTION in Android Studio

As Gabriele says, TopLevel Exception always occur due to conflict of different version of same library.

First of all I would suggest, avoid using adding file dependency as much as possible for you, Always try to add dependency from the jcenter repository. Looks like gradle takes care of conflicting dependencies.

So now, There are some ways to avoid it:

  1. Use only one version which contains all your required classes. like app compact has all v4 support classes, SO you dont need to import v4 support veresion if you're importing appcompact v7.

  2. You can always exclude a package from the compiled dependencies. For Example:

    //for the package:
    dependencies {
    compile("com.android.support:support-v4:21.0.3") {
    exclude group: 'com.android.support', module: 'support-v4'
    }
    }

Android Studio - UNEXPECTED TOP-LEVEL EXCEPTION:

Like everyone else said here, the support library (com.android.support) is being included more than once in your project. Try adding this in your build.gradle at the root level and it should exclude the support library from being exported via other project dependencies.

configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}

If you have more then one support libs included in the dependencies like this, you may want to remove one of them:Android Sample Image 18

About error: UNEXPECTED TOP-LEVEL EXCEPTION in android

I've fixed . If can help someone , this line:

compile fileTree(dir: 'libs', include: ['*.jar'])

...it was doubling the jar.

remove that line and declare the jars in the dependencies:

compile files('libs/easyanimation.jar')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile files('libs/commons-net-3.2.jar')

etc...

Android Studio UNEXPECTED TOP-LEVEL EXCEPTION:

Because it is reporting: bad class file magic (cafebabe) or version (0034.0000) you should check if you are compiling with the same java version that you are trying to use at runtime.
If you are using gradle you should use the following or similar entries in your build.gradle file:

apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7

Use this link for more gradle details.

In Android Studio, from File -> Project Structure -> SDK Location -> JDK Location you should use the jdk 1.7 and not relay on the Project level setting. See this link for a similar Android Studio question.

Android Studio : UNEXPECTED TOP-LEVEL EXCEPTION:

Welcome. You are at the first step of Android gradle hell.

  1. Update your Android SDK components in SDK Manager to latest one including Extra > Google Repository (recommend to add almost all in Extra).

  2. Let's wash up your current file.

    • AndroidManifest.xml: Remove the <uses-sdk ... /> lines. It's redundant as gradle file already defines it.

    • Build.gradle: Comment all compile files('libs/xxxxxxx.jar') lines. The first line compile fileTree(dir: 'libs', include: ['*.jar']) will include all jar files in libs folder. And, use compile from maven repository not jar files in order to maintain your dependencies fresh.

For example, SimpleXML has repository id as below. Place the code below of the compile fileTree(dir: 'libs', include: ['*.jar']) line and remove 'simple-xml-2.7.1.jar' file in libs folder.

compile('org.simpleframework:simple-xml:2.7.1') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
}

Likewise, find repository id of each jar file in your libs folder and replace it below of the compile fileTree(dir: 'libs', include: ['*.jar']) line one by one. Make only jar files which unable to find in maven repository remain in libs folder.

Finally, remove proguardFiles line. You need to find and fix the problem in general condition, then apply progruard afterward.


  1. Set version of buildToolsVersion and compileSdkVersion to latest one.

My recommendation of today is as below,

(numbers may vary when someone will see this post in the future)

android {
compileSdkVersion 22
buildToolsVersion '22.0.1'

dexOptions {
preDexLibraries = false
javaMaxHeapSize "2g"
}
defaultConfig {
...
multiDexEnabled = false
}
lintOptions {
abortOnError false
disable 'InvalidPackage'
}

...
}


dependencies {
compile 'com.android.support:appcompat-v7:22.1.1' // Do NOT use 22.2.0 even it is newer one. It reported to cause some problems with other dependencies.
compile fileTree(dir: 'libs', include: '*.jar')
compile('com.google.android.gms:play-services-gcm:7.5.+')
{
exclude module: 'support-v4'
}
}

  1. command gradle assembleDebug again. (for Windows, gradlew assembleDebug)

  2. If failed again, try to find and fix dependencies version conflict issues one by one. You may see exclude module: ... in my code. These resolve the conflict issue. Detailed instruction is given at the link: https://stackoverflow.com/a/30649660/361100

Unexpected top-level error

add this to your build.gradle (after your buildTypes)

dexOptions {
javaMaxHeapSize "4g"
}

UNEXPECTED TOP-LEVEL EXCEPTION: in Android Studio

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 MultiDexApplication

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.

Android UNEXPECTED TOP-LEVEL EXCEPTION

The Facebook SDK and the appcompact library come with the lbolts-android library that could cause a version mismatch and thus the DexException.

Check this question.

Look at what private libraries are included in your project, especially if there are multiple instances of lbolts.

Weird : UNEXPECTED TOP-LEVEL EXCEPTION: Execution failed for task app:dexDebug

You may have hit the 65k methods limit. To use Google Play Services with more granularity, follow this guide, you can use only the parts that you want. This will possibly fix your problem.



Related Topics



Leave a reply



Submit