Android Studio Execution Failed for task ':app:dexDebug' Error code: 1

192 views Asked by At

I'm trying to start my first Android Studio app and coming across the same error when I try to run or debug. This is the error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\Andreas\AppData\Local\Android\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output C:\Users\Andreas\Desktop\workspace-androidstudio-mooc\MOOC\app\build\intermediates\dex\debug --input-list=C:\Users\Andreas\Desktop\workspace-androidstudio-mooc\MOOC\app\build\intermediates\tmp\dex\debug\inputList.txt

Error Code:
1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1 mins 3.035 secs

build gradle (app):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "uk.ac.reading.sis05kol.mooc"
        minSdkVersion 8
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

Can anyone please help me? I have search for the same error throughout the internet but nothing solved my problem. Thank you in advance.

1

There are 1 answers

0
Defuera On

You run out of 65k methods limit, please look here, for more info https://developer.android.com/tools/building/multidex.html

To make your app work again enable multidex:

in your app.build file:

android {
    ...
    defaultConfig {
       ...
       multiDexEnabled true
    }

In your 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="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

Or you can override the attachBaseContext() method and call MultiDex.install(this) to enable multidex. For more information, see the MultiDexApplication reference documentation.