我使用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


  在6.5之前的Google Play服务版本中,您必须将整个API包编译到您的应用中。在某些情况下,这样做会使将应用程序中的方法(包括框架API,库方法和您自己的代码)的数量保持在65,536个限制以下变得更加困难。
  
  从6.5版开始,您可以选择编译Google Play
  服务API集成到您的应用中。


例如

对于Google地图,请使用:

com.google.android.gms:play-services-maps:10.0.1


方法计数:17984

对于Google Cloud Messaging:

com.google.android.gms:play-services-gcm:10.0.1


方法数量:15784

因此,使用单独的API将减少apk方法的数量。然后,无需启用multidex。

09-11 20:17
查看更多