gpt4 book ai didi

java - 方法 ID 不在 [0, 0xffff] 中构建错误

转载 作者:行者123 更新时间:2023-12-01 06:49:50 24 4
gpt4 key购买 nike

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

我尝试了这里提到的解决方案 DexIndexOverflowException issue after updating to latest appcompat and support library

但是我收到了这个错误

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

我也尝试了这里的解决方案 You need to use a Theme.AppCompat theme (or descendant) with this activity

但也没有用

此外,我认为我的应用程序没有那么大,无法包含 65536 个方法另一方面,当我用一些简单的方法创建新类时,我得到了这个错误

我试图追踪它

    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.

所有代码之前都正确运行,因此特定类或 Activity 没有错误

那么我该如何解决这个问题呢?谢谢

最佳答案

您的代码库包含的方法超过 65,536 个,并且无法将其 bundle 在一个 dex 文件中。

在这种情况下,您必须添加 multidex 支持。

您需要做的就是添加:

android {
...

defaultConfig {
...

// Enabling multidex support.
multiDexEnabled true
}
}

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

并将其添加到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>

或者,如果您有自己的 Application 类实现,请重写 Application 内的 attachBaseContext 方法,如下所示:

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

*MultiDex 仅适用于 Android 5.0 及以上版本。它没有向后兼容性。

关于java - 方法 ID 不在 [0, 0xffff] 中构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39135925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com