0

I am working on current location tracking but when I am trying to build apk it is showing ERRORS WHILE BUILDING APK.I am not getting the problem.

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_101\bin\java.exe'' finished with non-zero exit value 2

  • `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` it is pointing you to how to solve this issue... – Salem Jul 28 '16 at 11:13

4 Answers4

1

In your build.gradle add this line and try again:

multiDexEnabled true

David
  • 306
  • 6
  • 20
0

Have you tried adding the heap size adjustment to your build.gradle file? For example this will set the max heap size for dexing to 4GB, and it will also enable multiDexEnabled option.

android {
    ...
    dexOptions {
        javaMaxHeapSize "4g"
    }

defaultConfig {
        multiDexEnabled true
     }
}
U.Swap
  • 1,921
  • 4
  • 23
  • 41
0

hi we have 2 ways to handle multidex,

first way we should add this snippet of code in gradle

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

dexOptions {
    javaMaxHeapSize "4g"
}  

Second way we can use this code in our Application class,

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

thanks it may be helpful for you

Saveen
  • 4,120
  • 14
  • 38
  • 41
0

There can be 2 solutions for your problem : 1. As you are developing location tracking app you might have included the whole google play services that includes several libraries.Better you try to include on maps services in you gradle file like

compile 'com.google.android.gms:play-services-maps:8.3.0'
  1. If the above approach doesn't works try to Modify the module-level build.gradle file configuration to include the support library and enable multidex output, as shown in the following code

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

Some of the dependencies's methods cross the 64k limit. Hence you have to introduced a support called as "MULTIDEX SUPPORT".

http://frogermcs.github.io/MultiDex-solution-for-64k-limit-in-Dalvik/

Multidex will allow to have any number of methods in an app (along with its associated third party libraries).

Even though lollipop and above version's do support the app to have any number of methods, pre-lollipop versions support only SINGLE DEX. Due to this, multidex has to be installed(REQUIRED) at the time of app installation. This way, your app can run even on pre-lollipop versions.

Android Studio project works on Lollipop but does not work on Kitkat

This will slow down your app a little bit as multidex will try to extract all the resources from dex files but once this process is done whenever you will open your app it will work fine. In addition it won't give you any problem after you create a signed apk.

Community
  • 1
  • 1
Maniya Joe
  • 761
  • 6
  • 24