首页 > 解决方案 > “错误:无法在单个 dex 文件中容纳请求的类(# 方法:66653 > 65536)”生成签名的 apk 时

问题描述

我正在尝试生成一个签名的 apk,以便我可以将我的应用程序导出到 Google Play 商店。但是我不断收到同样的错误。有什么可以解决这个问题。

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.example.sean.monacoball"
            minSdkVersion 15
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner 
    "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 
    'proguard-rules.pro'
            }
        }
    }

    dependencies {
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation 'com.android.support:appcompat-v7:12.0.1'
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.android.gms:play-services:12.0.1'
    }
}

深度错误:

错误

标签: javaandroid

解决方案


根据Google Play 服务设置指南

注意:不要使用组合play-services目标。它引入了数十个库,使您的应用程序膨胀。相反,只指定您的应用使用的特定 Google Play 服务 API。

当您使用com.google.android.gms:play-services:12.0.1时,您正在提取每个Google Play 服务库。您应该切换到仅使用您实际使用的库。这几乎肯定会将您置于单个 dex 文件的64k 方法限制之下。


推荐阅读