0

I downloaded all the files that were needed according to the admob website. I had some issues along the way, but i found ways to deal with each of them. But i cannot get past this one and i do not know why? when I tried to compile my app, it failed and showed the following code in the "message" area

Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

I do not have ANY idea how to get past this, if ANYONE can help please do!

sorry if this question is badly asked or something!

  • http://stackoverflow.com/a/36786721/5212133 check this answer – Mayank Bhatnagar Oct 27 '16 at 12:54
  • 2
    Possible duplicate of [The number of method references in a .dex file cannot exceed 64k API 17](http://stackoverflow.com/questions/36785014/the-number-of-method-references-in-a-dex-file-cannot-exceed-64k-api-17) – Murat Karagöz Oct 27 '16 at 12:54
  • So, you have the clean error and also a LINK to solution.... And also there are a lot of questions about 64k methods limit on SO have already answered... – Beloo Oct 27 '16 at 12:57

1 Answers1

1

Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536—including Android framework methods, library methods, and methods in your own code. In the context of computer science, the term Kilo, K, denotes 1024 (or 2^10). Because 65,536 is equal to 64 X 1024, this limit is referred to as the '64K reference limit'.

Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration

Change your Gradle build configuration to enable multidex

    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'
}

In your manifest add the MultiDexApplication class from the multidex support library to the application element.

    <?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>
Community
  • 1
  • 1
Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56
  • Thanks, I added the code you gave me above but it now gives me a LOT of errors, ending with this one : **Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_91\bin\java.exe'' finished with non-zero exit value 3** – Johan De waal Oct 27 '16 at 13:39
  • Thanks anyway, I'm gonna do the whole admob thing from the start and see if I can get it right this time :) – Johan De waal Oct 27 '16 at 13:52
  • Did u add `multiDexEnabled true` in your gradile? – Alex Chengalan Oct 30 '16 at 05:54