为什么发布构建变体总是可调试的?

Why is the release build variant always debuggable?

我是否通过以下方式创建 "release" APK:

... 生成的 APK 始终具有 debuggable=true,我已通过尝试将它们上传到 Google Play 来确认这一点,上面写着:

"Upload failed. You uploaded a debuggable APK. For security reasons you need to disable debugging before it can be published in Google Play."

(唯一的)清单没有指定可调试的属性。 Gradle 为发布指定 debuggable=false,为调试指定 true,见下文。

我错过了什么?可调试状态从何而来,为什么发布构建类型声明中的 debuggable=false 被忽略?我不想将 debuggable=false 添加到清单中,也不想手动保留它 enabling/disabling。

app/build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.0'
    defaultConfig {
        applicationId "com.myapp.android"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 5
        versionName 5
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        release {
            storeFile rootProject.file("keystore.jks")
            if (storeFile.exists()) {
                def config = new Properties()
                config.load(new FileInputStream(rootProject.file("keystore.passwords")))
                storePassword config.KeystorePassword
                keyAlias config.KeyAlias
                keyPassword config.KeyPassword
            }
        }
    }

    buildTypes {
        release {
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            debuggable true
            applicationIdSuffix ".debug"
        }
    }

    dataBinding {
        enabled = true
    }

    lintOptions {
        disable 'RtlHardcoded'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    // Copy release APK to project root
    task copyReleaseApk(type: Copy) {
        from 'build/outputs/apk'
        into '..'
        include '**/*release.apk'
    }

    afterEvaluate {
        if (tasks.findByPath("packageRelease") == null) {tasks.create("packageRelease")}
        tasks.findByPath("packageRelease").finalizedBy(copyReleaseApk)
    }

}

ext {
    // Single place to specify the support library version
    supportLibraryVersion = '26.0.0-beta2'
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.google.code.findbugs'
        exclude module: 'espresso-idling-resource'
        exclude group: "javax.inject"
    })
    implementation 'com.android.support.test.espresso:espresso-contrib:2.2.2'

    // Dagger dependency injection
    implementation 'com.google.dagger:dagger:2.10'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.10'
    implementation 'com.google.dagger:dagger-android:2.10'
    implementation 'com.google.dagger:dagger-android-support:2.10'
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.10'

    implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
    implementation "com.android.support:design:$supportLibraryVersion"
    implementation "com.android.support.constraint:constraint-layout:1.0.2"

    implementation "com.jakewharton.timber:timber:4.5.1"
    implementation "com.squareup.phrase:phrase:1.1.0"
    implementation "com.squareup.retrofit2:retrofit:2.2.0"
    implementation "com.squareup.retrofit2:converter-gson:2.2.0"
    implementation "com.squareup.okhttp3:logging-interceptor:3.7.0"
    implementation 'net.danlew:android.joda:2.9.9'

    testImplementation 'junit:junit:4.12'
    implementation 'com.google.firebase:firebase-crash:11.0.0'
    androidTestImplementation 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

更新 1:我尝试将 debuggable=false 添加到清单中,但没有任何区别,生成的 APK 仍然无法上传到 Google Play。

更新 2:我使用 APK 分析器将 APK 加载回 Android Studio,这使得查看清单变得很容易,它们都包含.... debuggable=true。它来自哪里?

更新 3:assembleRelease 在我的本地计算机和 CI 服务器 (BuddyBuild) 上生成可调试的 APK。

更新 4:完全重建(包括删除构建文件夹)并在清除缓存后重新启动 Android Studio 没有任何区别。

更新 5:假设 debuggable=true 状态可能来自其中一个依赖项似乎是合理的,但如果是这种情况,如何覆盖它?

这是因为您可能有增量构建,默认情况下假定所有增量构建 debuggable

General Notes of the SDK Tools Revision 8 下,它指出:

Support for a true debug build. Developers no longer need to add the android:debuggable attribute to the tag in the manifest — the build tools add the attribute automatically. In Eclipse/ADT, all incremental builds are assumed to be debug builds, so the tools insert android:debuggable="true". When exporting a signed release build, the tools do not add the attribute. In Ant, a ant debug command automatically inserts the android:debuggable="true" attribute, while ant release does not. If android:debuggable="true" is manually set, then ant release will actually do a debug build, rather than a release build.

由于该项目的目标是 API 26 并使用 android gradle 插件的 3.0.0-alpha4、26.0.0-beta2 构建工具和 gradle 4.0-rc1 我认为我应该检查该问题是否与这些预发布工具的问题无关。所以我恢复到 API 25 和 gradle 3.3 的稳定版本,gradle 插件 2.3.3 和构建工具 25.0.3。这有点乏味,因为我不得不将所有 Java 8 语法从源代码降级为 Java 7。但是在这样做之后,构建过程现在按预期工作并生成发布 APK 工件不包含 debuggable="true" 标志,可以上传到 Google Play。

我不清楚具体原因在哪里,但我已将其记录在 Android 工具错误跟踪器中,因为这似乎是一个错误: https://issuetracker.google.com/issues/62899843

更新:工具团队的回应是这是预期的行为,因为该应用程序针对 API 26 并且处于预览状态。我认为 26 APIs 是最终版本,可以针对它构建 APK 并发布到 Google Play,但显然不是。