Skip to content Skip to sidebar Skip to footer

Android Studio Importing Unity Project Error(Error:Execution Failed For Task ':app:dexDebug' : UNEXPECTED TOP-LEVEL EXCEPTION)

This error is bothering me for two days. So I need to import a Project from unity into android studio but gives me this error: Error:Execution failed for task ':app:dexDebug'. >

Solution 1:

In your build.gradle file try adding the following block inside your android block.

dexOptions {
        incremental true
        javaMaxHeapSize "4g"
        preDexLibraries = false
}

And your defaultConfig add this

multiDexEnabled true

defaultConfig {
        applicationId "com.example"
        minSdkVersion 17
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        renderscriptTargetApi 21
        renderscriptSupportModeEnabled true;
    }

In you gradle dependency add,

compile 'com.android.support:multidex:1.0.1'

dependencies {
    //compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.android.support:multidex:1.0.1'
}

In Application class, attachBaseContext method include this line,

MultiDex.install(this);

public class ExampleApp extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

In your AndroidManifest.xml file,

Add attribute "name" and assign above mentioned Application Class.

 <application
        android:name="com.ExampleApp">

<!--- Activities -->

</application>

Now try to run your project after clean and build your project.

Hope it will help you my dear friend !


Post a Comment for "Android Studio Importing Unity Project Error(Error:Execution Failed For Task ':app:dexDebug' : UNEXPECTED TOP-LEVEL EXCEPTION)"