6

I'm relatively new to Android programming and I am trying to create a Google Maps project. I used the template option in Android Studio, and I added the key for the API.

I haven't added any of my own code and left the template code as is because I just wanted to run the code and see what it looks like, however, I keep getting a multi dex error when I try to run this on the emulator causing the build to fail. It's weird to me that I am getting this error because I haven't added ANY code at all and am using what the Google Maps template has from Android Studio.

Anyone know why this error shows up on a brand new project? The error I see is pasted below.

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

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 2

shong
  • 121
  • 1
  • 9
  • 3
    Your probably compiling all of the play-services API's using compile 'com.google.android.gms:play-services:9.2.0'... Now we can selectively compile API's to avoid dex limit of 64K. For Google Maps use com.google.android.gms:play-services-maps:9.2.0... – LokiDroid Jul 01 '16 at 19:01
  • 1
    ^ above comment worked like a charm. thanks. – shong Sep 01 '16 at 04:54
  • Funny even google screws up the DEX limit, which I never understood why they can't fix this issue. – JPM Dec 02 '16 at 20:32

7 Answers7

4

as quoted below:

Your probably compiling all of the play-services API's using compile 'com.google.android.gms:play-services:9.2.0'... Now we can selectively compile API's to avoid dex limit of 64K. For Google Maps use com.google.android.gms:play-services-maps:9.2.0... – Loki Jul 1 at 19:01

Answer from Loki worked and was very simple to do.

shong
  • 121
  • 1
  • 9
2

setting up google play services

Go through this link just add the dependencies which you want in your application. This will prevent 64k exceeding error.

Happy coding.

Basheer Kohli
  • 154
  • 2
  • 11
2

For those who tried all the above methods and failed. Try changing the mini sdk version to 21 in the build.gradile file. For me it was on 16 and when I changed it to 21 the multidex error was gone for good.

minSdkVersion 21

0

The issue is you currently have a high number of methods. There can only be 65536 methods for dex. You can try enabling multiDex by editing your build.gradle file.

android {
          //stuff

defaultConfig {
    ...

       // Enable multiDex support. 
       multiDexEnabled true
    }

}

dependencies {
   compile 'com.android.support:multidex:1.0.0'
}

Also, oops as the poster above mentioned in your manifest you also need to add that you are using the multidex class from the multidex support library.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.dexapp">
<application
    ...
    android:name="android.support.multidex.MultiDexApplication">
    ...
</application>

basic
  • 3,348
  • 3
  • 21
  • 36
0

Change your Gradle build configuration to enable multidex

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0 rc2"

    defaultConfig {
        applicationId "com.try.app"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

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>

Note: Visit https://developer.android.com/studio/build/multidex.html for more info.

Abhinay Reddy Keesara
  • 9,763
  • 2
  • 18
  • 28
0

Set property multiDexEnabled to true in defaultConfig. This error occurs when method references increase the limit of 65k. Check Google Play Service APIs.

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

Here is a good source to get started with Google Maps Android API

0

I removed the dependencies as suggested by Loki and it works.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.google.android.gms:play-services-maps:9.4.0'
}
shekh
  • 116
  • 8