Gradle在发布模式下生成可调试的APK

时间:2016-04-11 19:01:21

标签: android gradle

我的build.gradle上有以下代码:

productFlavors {
        juridico {
            applicationId "br.com.eit.appprovaconcursos"
        }
        enem {
            applicationId "com.ioasys.appprova"
        }
    }

    buildTypes {
        defaultConfig {
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            testCoverageEnabled true
        }
        release {
            debuggable false
            testCoverageEnabled true
            //noinspection GroovyAssignabilityCheck
            signingConfig signingConfigs.release
        }
    }

要生成de release APK,我使用以下命令:

./gradlew assembleEnemRelease

在Google Play上传生成的APK(app-enem-release.apk)时出现以下错误:

您上传了可调试的APK。出于安全原因,您需要先禁用调试,然后才能在Google Play中发布。详细了解可调试APK。

我能够通过Android Manifest android:debuggable="false"上的硬编码生成不可调试的APK。但是构建配置仍然像可调试构建一样,你可以在生成Build.config中看到(我仔细检查,这个构建配置来自release文件夹,我也没有收到关于Crashlytics的任何数据,我禁用它调试构建)。

public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String APPLICATION_ID = "com.ioasys.appprova";
  public static final String BUILD_TYPE = "release";
  public static final String FLAVOR = "enem";
  public static final int VERSION_CODE = 20135;
  public static final String VERSION_NAME = "3.0.1";
}

2 个答案:

答案 0 :(得分:8)

我发现这个奇怪的结果来自testCoverageEnabled true

如果您的发布版本启用了测试覆盖率,它会生成覆盖率报告,然后您的APK将成为可调试的APK。

testCoverageEnabled设置为false解决问题,并且在发布版本上不生成覆盖率报告也是有意义的。

答案 1 :(得分:3)

作为解决方法,我在defaultConfig中将debuggable设置为true,在发行版中,我覆盖配置并将debuggable设置为false。