我使用 MapsActivity 创建了一个新的 Android Studio 项目,如果我尝试在我的华为 P8 Lite 设备上启动该应用程序,则会出现此错误:
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
我的 Build.Gradle(模块:应用程序):
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.example.de.maptestdel"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.android.support:design:25.1.0'
testCompile 'junit:junit:4.12'
}
除了启用Multidex之外,还有其他方法可以解决吗? 听说不太好激活。
最佳答案
使用 Google Play 服务库中的特定/个人 API。您已使用 compile 'com.google.android.gms:play-services:10.0.1'
并且此库方法计数为 79958。
请引用此链接:https://developers.google.com/android/guides/setup
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.
例如
对于谷歌地图,使用:
com.google.android.gms:play-services-maps:10.0.1
方法数:17984
对于谷歌云消息:
com.google.android.gms:play-services-gcm:10.0.1
方法数:15784
因此,使用单独的 API 将减少 apk 方法的数量。然后,无需启用 multidex。
关于android - 我该如何解决这个错误?方法 ID 不在 [0, 0xffff] : 65536,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42105328/