Jay
Jay

Reputation: 5084

Android Error: Your app has more methods references than can fit in a single dex file

Gradle Build is successful but when I try to run my app, I get this error:

Error:Your app has more methods references than can fit in a single dex file. See https://developer.android.com/tools/building/multidex.html

I got this after I implemented 'Sign-in using Google Account' feature to my app.

Why am I getting this? I don't understand the problem in order to fix this. Do any of you have a solution for this?

EDIT

I Followed the steps, however it's showing another error:

Copying resources from program jar [/Users/Earthling/AndroidStudioProjects/GoogleTestProject/app/build/intermediates/transforms/jarMerging/debug/jars/1/1f/combined.jar] :app:transformClassesWithDexForDebug FAILED Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin/java'' finished with non-zero exit value 3

Upvotes: 1

Views: 849

Answers (1)

Blo
Blo

Reputation: 11978

You have to use multidex because your projet exceeds the limit of methods authorized in one app (it's about ~56000 or almost, I don't remember). See this quote in Documentation (the link you provided by the way):

As the Android platform has continued to grow, so has the size of Android apps. When 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.

In order to build and run, you have to configure your build.gradle as follows:

android {
    defaultConfig {
        ...
        // enabling multidex
        multiDexEnabled true
    }
}

// add the dependencie
dependencies {
    compile 'com.android.support:multidex:1.0.0'
}

Then, create your own Application class as follows:

public class MyApplication extends MultiDexApplication {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this); // install multidex
    }
}

Finally, add this class in the Manifest:

<application
    ...
    android:name=".MyApplication">

Or you can just use the android.multidex.application by default instead of creating one like this:

<application
    ...
    android:name="android.support.multidex.MultiDexApplication">

Upvotes: 2

Related Questions