【问题标题】:Why is the release build variant always debuggable?为什么发布版本变体总是可调试的?
【发布时间】:2017-06-21 16:06:24
【问题描述】:

我是否通过以下方式创建“发布”APK:

  • 在 Android Studio 中使用 Generate Signed APK
  • 选择 Release 构建变体并使用 Tools -> Build APK
  • 运行 assembleRelease 任务

... 生成的 APK 始终具有 debuggable=true ,我已通过尝试将其上传到 Google Play 确认了这一点,其中显示:

“上传失败。您上传了一个可调试的 APK。出于安全原因,您需要先禁用调试,然后才能在 Google Play 中发布它。”

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

我错过了什么?可调试状态从何而来,为什么发布构建类型声明中的 debuggable=false 会被忽略?我不想在清单中添加 debuggable=false 并且必须继续手动启用/禁用它。

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 Analyzer 将 APK 重新加载到 Android Studio 中,这样可以轻松查看清单,并且它们都包括... debuggable=true。它来自哪里?

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

更新 4:干净的重建(包括删除构建文件夹)和在清除缓存的情况下重新启动 Android Studio 没有区别。

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

【问题讨论】:

  • 您确定您上传的是正确的 APK 吗?
  • 是的,我已经尝试了许多来自以上述各种方式生成的多个文件夹位置的 APK,并在生成新 APK 之前清除文件夹。
  • 如果删除copyReleaseApk 用法会出现这种情况吗?
  • @petey 我尝试禁用此功能,但没有效果 - APK 仍包含调试数据。
  • “假设 debuggable=true 状态可能来自依赖项之一似乎是合理的,但如果是这种情况,如何覆盖?” -- 在 Android Studio 中,打开清单,然后选择“Merged Manifest”子选项卡。另外,如果你使用aaptdoes it also report that the APK is debuggable?

标签: android android-studio android-signing


【解决方案1】:

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

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

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

【讨论】:

  • 清单似乎仍然需要包含明确的 debuggable="false"
【解决方案2】:

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

General Notes of the SDK Tools Revision 8 下,它声明:

支持真正的调试版本。开发人员不再需要添加 清单中标签的 android:debuggable 属性 — 构建工具自动添加属性。在 Eclipse/ADT 中,所有 增量构建被假定为调试构建,因此工具插入 android:debuggable="true"。导出签名的发布版本时, 工具不添加属性。在 Ant 中,一个 ant 调试命令 自动插入 android:debuggable="true" 属性,而 ant release 没有。如果手动设置了 android:debuggable="true", 那么 ant release 实际上会进行调试构建,而不是发布 构建。

【讨论】:

  • “导出签名的发布版本时,工具不会添加属性” - 如果这意味着使用 Generate Signed APK 或 Build APK 那么这不是问题,因为这两种方法仍然会产生可调试的APK。我已经尝试过干净的完整重建,但没有成功。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-27
  • 2020-08-02
相关资源
最近更新 更多