Stu*_*ing 4 android gradle android-studio
我有两个构建类型的项目设置: debug和release。
在我的应用模块中,我有三个不同的目录:debug,release和main。
我想做的是测试 release目录中但是我似乎唯一能做的就是生成一个签名的apk并将其加载到模拟器上。这意味着我无法正确调试它。
当我将app模块的构建变体更改为release为时,在“编辑配置”弹出窗口中出现以下错误。
错误:您当前选择的变体(app-release-unsigned.apk_未签名的apk。请为此变体(release)指定签名配置。
我希望做的是延长了release一个名为构建变量debugRelease中build.gradle的文件app模块然后将继承在代码release目录,但我将能够在IDE中运行它。
我可能会以错误的方式看待这个问题,并且很高兴听到其他技术。
我可以做我想做的事吗?如果不是,最好的解决方案是什么?
经过大量研究,我决定继续执行我的debugRelease想法,并且看起来效果很好。
我在app/src名为下创建一个新目录debugRelease/java。在其中,我生成了签名的apk或发行版时,我希望将其与众不同的任何代码放入其中。
这样做使我能够测试代码的运行情况并能够对其进行调试。当然,这不是很经常执行,只是崩溃报告和记录差异而已,但是,在一个偶然的机会,我需要修复错误或类似的东西,我可以。
在我的build.gradle文件中,我具有以下设置。
buildTypes {
release {
}
debug {
}
debugRelease {
signingConfig signingConfigs.debug
}
}
sourceSets {
debugRelease {
res.srcDirs = ['src/debug/res'] // this uses the debug's res directory which contains a "debug" icon
}
release {
java.srcDirs = ['src/debugRelease/java'] // this avoids copying across code from the debugRelease java directory
}
}
Run Code Online (Sandbox Code Playgroud)
因此,现在当我要测试发布代码时,只需将build变体更改为debugRelease。
您可以构建应用的发布变体(例如,使用您的生产环境),具有以下属性:
对您的app/build.gradle 进行以下临时更改:
/* ADD THIS BLOCK, IF NOT ALREADY THERE */
lintOptions {
// When you make a Release Build, the Android Lint tool will run to check many things.
// It is set to abort the build on a single Lint error/warning. Disable this.
abortOnError false
}
buildTypes {
release {
//minifyEnabled true // <-- COMMENT OUT
//proguardFiles ... // <-- COMMENT OUT
//shrinkResources true // <-- COMMENT OUT
signingConfig signingConfigs.debug // <-- ADD THIS TO SIGN WITH YOUR DEBUG CERTIFICATE
debuggable true // <-- ADD THIS
minifyEnabled false // <-- ADD THIS
}
}
Run Code Online (Sandbox Code Playgroud)
那么 Android Studio 呢?看法 ?工具窗口 ? 构建变体 ? 选择appRelease或任何你的名字,然后按运行按钮来构建和安装它。
更多信息/相关文章:
| 归档时间: |
|
| 查看次数: |
4033 次 |
| 最近记录: |