0
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.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

i tried with the solutions mentioned here DexIndexOverflowException issue after updating to latest appcompat and support library

but i got this error

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

i also tried the solution for it from here You need to use a Theme.AppCompat theme (or descendant) with this activity

but didn't work either

beside i don't think my application is that big to contains 65536 methods on the other side i got that error when i created new class with some simple methods

i tried to trace it

    Error:D:\games\games\ANDROID\HealMe\app\src\main\java\com\kareem\healme\Gui\DoctorMain.java:56: warning: [deprecation] setDrawerListener(DrawerListener) in DrawerLayout has been deprecated
    drawer.setDrawerListener(toggle);
          ^
D:\games\games\ANDROID\HealMe\app\src\main\java\com\kareem\healme\Gui\DoctorPersonalInformation.java:52: warning: [deprecation] getPreferenceScreen() in PreferenceActivity has been deprecated
    getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
    ^
D:\games\games\ANDROID\HealMe\app\src\main\java\com\kareem\healme\Gui\DoctorPersonalInformation.java:58: warning: [deprecation] getPreferenceScreen() in PreferenceActivity has been deprecated
    getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    ^
D:\games\games\ANDROID\HealMe\app\src\main\java\com\kareem\healme\Gui\DoctorPersonalInformation.java:124: warning: [deprecation] findPreference(CharSequence) in PreferenceActivity has been deprecated
            findPreference(s).setSummary(sharedPreferences.getString(s, ""));
            ^
D:\games\games\ANDROID\HealMe\app\src\main\java\com\kareem\healme\Gui\DoctorPersonalInformation.java:128: warning: [deprecation] findPreference(CharSequence) in PreferenceActivity has been deprecated
            findPreference(s).setSummary(sharedPreferences.getString(s, ""));
            ^
D:\games\games\ANDROID\HealMe\app\src\main\java\com\kareem\healme\Gui\DoctorPersonalInformation.java:132: warning: [deprecation] findPreference(CharSequence) in PreferenceActivity has been deprecated
            findPreference(s).setSummary(sharedPreferences.getString(s, ""));
            ^
D:\games\games\ANDROID\HealMe\app\src\main\java\com\kareem\healme\Gui\DoctorPersonalInformation.java:136: warning: [deprecation] findPreference(CharSequence) in PreferenceActivity has been deprecated
            findPreference(s).setSummary(sharedPreferences.getString(s, ""));
            ^
D:\games\games\ANDROID\HealMe\app\src\main\java\com\kareem\healme\Gui\DoctorPersonalInformation.java:140: warning: [deprecation] findPreference(CharSequence) in PreferenceActivity has been deprecated
            findPreference(s).setSummary(sharedPreferences.getString(s, ""));
            ^
D:\games\games\ANDROID\HealMe\app\src\main\java\com\kareem\healme\Gui\DoctorPersonalInformation.java:158: warning: [deprecation] findPreference(CharSequence) in PreferenceActivity has been deprecated
            findPreference(s).setSummary(name);
            ^
D:\games\games\ANDROID\HealMe\app\src\main\java\com\kareem\healme\Gui\DoctorPersonalInformation.java:162: warning: [deprecation] findPreference(CharSequence) in PreferenceActivity has been deprecated
            findPreference(s).setSummary(sharedPreferences.getString(s, ""));
            ^
  D:\games\games\ANDROID\HealMe\app\src\main\java\com\kareem\healme\Gui\DoctorPersonalInformation.java:166: warning: [deprecation] findPreference(CharSequence) in PreferenceActivity has been deprecated
            findPreference(s).setSummary(sharedPreferences.getBoolean(s, false) + "");
            ^
 D:\games\games\ANDROID\HealMe\app\src\main\java\com\kareem\healme\Gui\PatientMain.java:84: warning: [deprecation] setDrawerListener(DrawerListener) in DrawerLayout has been deprecated
    drawer.setDrawerListener(toggle);
          ^
  D:\games\games\ANDROID\HealMe\app\src\main\java\com\kareem\healme\Gui\PatientMain.java:325: warning: [deprecation] isLocationProviderEnabled(ContentResolver,String) in Secure has been deprecated
            .isLocationProviderEnabled(contentResolver,
            ^
13 warnings
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

all the code ran before correctly so no errors with specific class or activity

so how can i fix this? thanks

Community
  • 1
  • 1
Kareem Elsayed
  • 295
  • 6
  • 22

4 Answers4

4

Your codebase has more method than 65,536 and it cannot be bundled in one dex file.

In this case, you have to add multidex support.

All you need to do is add:

android {
    ...

    defaultConfig {
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
}

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

and this to AndroidManifest.xml:

<?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>

or if you have your own implementation of Application class, override attachBaseContext method inside Application like that:

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

*MultiDex only applicable for Android 5.0 and above. There is no backward compatibility for it.

Amad Yus
  • 2,856
  • 1
  • 24
  • 32
klimat
  • 24,711
  • 7
  • 63
  • 70
3

According to Android developer documentation:

If you have built an Android app and received this error, then congratulations, you have a lot of code! This document explains how to move past this limitation and continue building your app.

Sometimes, importing libraries using gradle dependency can lead to this error. Is there google play services library in your app? If any, instead of compile com.google.android.gms:play-services:9.4.0, you can import libraries that you only want to use for example if you want to use google map, just import com.google.android.gms:play-services-maps:9.4.0 instead com.google.android.gms:play-services:9.4.0. It will help reducing the number of dex generated. You also can use proguard to eliminate unused code.

In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.

From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:

You can refer to Android Guide on how to selectively compiling APIs into your executable

Amad Yus
  • 2,856
  • 1
  • 24
  • 32
2

If you are using multiDex ...:

In your manifest ... If you do not override the Application class then:

<application android:name="android.support.multidex.MultiDexApplication" >

If you override it, make sure that you are not extending from Application, instead you should extend from MultiDexApplication and in your manifest should be something like this :

<application android:name="yourOverridingClass" >
0

Check what Google Play Services you are compiling. For me what fixed this was changing from

compile 'com.google.android.gms:play-services:10.2.0'

which includes the entire play services library, to

compile 'com.google.android.gms:play-services-places:10.2.0'

which only includes the Places API.

Airwavezx
  • 323
  • 1
  • 9