1

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

Jay
  • 4,873
  • 7
  • 72
  • 137
  • See http://stackoverflow.com/questions/15471772/how-to-shrink-code-65k-method-limit-in-dex/28018547#28018547 – mattm Jan 12 '16 at 17:27

1 Answers1

2

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">
Blo
  • 11,903
  • 5
  • 45
  • 99
  • Followed these steps but I got this new error though. EDITED the question – Jay Jan 12 '16 at 17:07
  • @Earthling, you'd try to follow this [answer/comment](http://stackoverflow.com/questions/31605291/gradle-finished-with-non-zero-exit-value-3#comment51487848_31605291). It might resolve your issue. – Blo Jan 12 '16 at 17:16