Kareem Elsayed Kareem Elsayed - 3 months ago 36
Java Question

method ID not in [0, 0xffff] build error

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

Answer

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