安卓工作室 : how to create a second debug build type

标签 android debugging android-studio gradle build

我想创建第二个构建类型,它应该与现有的调试类型完全一样。目前我有两种构建类型:调试和发布。只需单击即可运行调试,并使用调试 keystore 自动签名。 我通过 Build -> Generate signed APK 向导手动编译发布版本。

所以为了克隆调试构建类型,我首先在 app build.graddle 文件中添加了第二个名为“local”的构建类型:

buildTypes {
    ...
    debug {
        debuggable true
        minifyEnabled false
    }
    local {
        debuggable true
        minifyEnabled false
    }
}

然后我创建了 app/src/local/res 并添加了一些文件。

然后我执行 gradle resync 并在左侧选项卡中选择新的构建类型: build type tab

最后我点击了运行按钮,我希望它能够正常工作。这个IntelliJ help article说调试签名配置是默认的:

This means that if you do not configure an artifact manually and select the Deploy default APK option in the Run/Debug Configuration: Android Application dialog box, IntelliJ IDEA will use the predefined values in the certificate for the generated

而是显示此对话框:

run dialog

当我单击修复按钮时,它会打开整个应用模块的签名配置对话框。但是,我不想签署此 apk 以进行发布,我需要使用调试证书对其进行签名。我还注意到已经创建了一个新的 assembleLocal gradle 任务,但它会生成一个未对齐的 apk。在此文件夹中,我可以看到常规调试 apk 在其未对齐版本和最终版本中正确生成。

到底如何才能克隆调试构建类型?

最佳答案

此外,您可以使用以下命令使您的构建类型类似于调试:

initWith(buildTypes.debug)

这是一个例子:

...
buildTypes {

    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        buildConfigField 'String', 'URL_API_BASE_SERVICE', '"http://theidasworld.com"'
    }
    debug {
        versionName 'APP BETA'
        buildConfigField "Integer", "PIN", "0000"  
        buildConfigField 'String', 'URL_API_BASE_SERVICE', '"http://debug.theidasworld.com"'
    }
    inspection {
        initWith(buildTypes.debug) // keep versionName and PIN from 'debug'
        buildConfigField 'String', 'URL_API_BASE_SERVICE', '"http://inspection.theidasworld.com"'
    }
}
...

关于安卓工作室 : how to create a second debug build type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35033748/

相关文章:

android - Firebase App Distribution 找到超过 1 个此变体的输出文件

android - 如何编译并启动Android内核

android - 检查布局是否包含任何 ImageView 或 TextView android

android - 使用 HashMap<String,List<String>> 创建 ExpandableListView 时出错

debugging - 如何在 lazarus 调试窗口中禁用 AT&T/启用 Intel 语法?

android - 异常(exception):重复条目:android/support/v7/widget/CardViewApi21.class

java - 将签名 key 的证书导出到 Android Studio 中的 .pem 扩展名

android - android studio 中的 Kotlin 插件错误

javascript - 在 Chrome 中使用 React Native 调试 ES6 import 语句

delphi - 即使不在 Delphi IDE 中逐步调试,也可以访问监视项