Mis*_*ith 20 debugging android build gradle android-studio
我想创建第二个构建类型,它应该与现有的调试类型完全一样.目前我有两种构建类型:调试和发布.可以通过单击运行调试版本,并使用调试密钥库自动签名.我通过Build -> Generate signed APK向导手动编译发布版本.
因此,为了克隆调试构建类型,我首先在app build.graddle文件中添加了名为"local"的第二个构建类型:
buildTypes {
...
debug {
debuggable true
minifyEnabled false
}
local {
debuggable true
minifyEnabled false
}
}
Run Code Online (Sandbox Code Playgroud)
然后我创建app/src/local/res并添加了一些文件.
然后我执行gradle resync并在左侧选项卡中选择新的构建类型:

最后我点击了运行按钮,我希望它能正常工作.这篇IntelliJ帮助文章说调试签名配置是默认的:
这意味着如果您未手动配置工件并在"运行/调试配置:Android应用程序"对话框中选择"部署默认APK"选项,则IntelliJ IDEA将使用证书中的预定义值生成
而是显示此对话框:
当我单击修复按钮时,它会打开整个应用程序模块的签名配置对话框.但是,我不想签署这个apk用于发布,我需要使用调试证书签名.另外我注意到assembleLocal已经创建了一个新的gradle任务,但它生成了一个未对齐的apk.在这个文件夹中,我可以看到常规调试apks在未对齐和最终版本中正确生成.
我怎样才能克隆调试版本类型?
Gab*_*tti 32
您可以在build.gradle文件中指定signingConfig应该使用的文件buildType.
要使用与signingConfig默认调试相同的签名buildType,请使用以下命令:
buildTypes {
local {
signingConfig signingConfigs.debug
}
/* NOTE: the debug block is not required because it is a default
* buildType configuration; all of its settings are defined implicitly
* by Android Studio behind the scenes.
*/
}
Run Code Online (Sandbox Code Playgroud)
如果您更喜欢使用本地系统上的自定义密钥库,请使用以下代码:
signingConfigs {
local {
storeFile file("/path/to/custom.keystore")
storePassword "password"
keyAlias "MyLocalKey"
keyPassword "password"
}
}
buildTypes {
local {
signingConfig signingConfigs.local
}
}
Run Code Online (Sandbox Code Playgroud)
iva*_*iuk 28
此外,您可以使用类似于调试的Build类型:
initWith(buildTypes.debug)
Run Code Online (Sandbox Code Playgroud)
这是一个例子:
...
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"'
}
}
...
Run Code Online (Sandbox Code Playgroud)
对于 Kotlin 构建脚本,上述答案的等效内容如下:
android {
buildTypes {
create("local") {
initWith(buildTypes["debug"])
buildConfigField("String", "URL_API_BASE_SERVICE", """"http://..."""")
buildConfigField("Boolean", "IS_CI", "${System.getenv("CI") == "true"}") // boolean example
isDebuggable = true
}
testBuildType = "local"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7067 次 |
| 最近记录: |