Problem with dex on Android

2

Hello, has anyone had this problem in your android application?

  

Error: The number of method references in a .dex file can not exceed   64K. Learn how to solve this issue at

I have read in link what it is about but in my development nothing of this that could throw the error.

The only thing I did in the application was to update in the Gradle app the version of play services from 8.3.0 to 10.0.1 and when I run the application it sends me that error.

I do not have many methods as in the documentation indicates, I already did what they suggest but still sending the same error.

I hope and can help.

    
asked by Hector 19.01.2017 в 21:37
source

1 answer

0
  

Error: The number of method references in a .dex file can not exceed   64K. Learn how to solve this issue at

This is solved by enabling multidex from your build.gradle :

android {

    defaultConfig {
        ...
        ...
        multiDexEnabled = true
    } 
}

Review the documentation document: Set up your app for Multidex with gradle .

  

The Android application files (APK) contain files for   Byte code executable in the form of Dalvik Executable files   (Dex), which contain the compiled code used to execute your   app The Dalvik Executable specification limits the total amount   of methods that can be referenced in a Dex file to 65   536, including the methods of the Android framework, library and   of your own code. In the context of computing, the term   Kilo, K, denotes 1024 (or 2 ^ 10). Because 65 536 equals 64 X   1024, this limit is called "64K reference limit" .

     

To overcome this limit, you must configure the compilation process   of your app to generate more than one Dex file, which is known as   MultiDex configuration.

The problem as I commented is an incorrect configuration should be

multiDexEnabled = true

Wrote incorrectly

multiDexEnabled true

This would be your% corrected% file:

apply plugin: 'com.android.application' android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
            applicationId "com.kofh.mx.tae"
            minSdkVersion 16
            targetSdkVersion 25
            versionCode 6
            versionName "1.5"
            // Enabling multidex support.
            //multiDexEnabled true
            multiDexEnabled = true
    }
    dexOptions {
         javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile 'com.android.support:multidex:1.0.1'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/volley.jar')
    compile files('libs/ksoap2-android-assembly-3.5.0-jar-with-dependenc‌​ies.jar')
    compile files('libs/usbsdk.jar')
    compile files('libs/jasypt-1.9.2.jar')
    compile 'com.google.android.gms:play-services:10.0.1'
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:design:25.0.0'
    compile 'com.google.firebase:firebase-core:9.6.1'
    compile 'com.google.firebase:firebase-messaging:9.6.1'
}
apply plugin: 'com.google.gms.google-services'

Update: , another problem arose that is:

  

Error: UNEXPECTED TOP-LEVEL ERROR: Error: java.lang.OutOfMemoryError: GC   overhead limit exceeded Error: Execution failed for task

For this, more memory has to be assigned, therefore the Heap size in the file build.gradle is configured by means of the variable build.gradle :

  dexOptions {
         javaMaxHeapSize "4g"
    }
    
answered by 20.01.2017 в 00:37