多版本共存问题
首先使用applicationIdSuffix修改applicationId,完成这个修改即可使开发和线上版本共存,但是这是最最初步的修改,可以配合变体文件夹,创建不同环境的代码和运行资源,区分开发和线上版本,可以达到很多目的。
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard-rules.txt'
shrinkResources true //注意增加keep
signingConfig signingConfigs.release
}
debug {
minifyEnabled false
proguardFiles 'proguard-rules.txt'
shrinkResources false //注意增加keep
signingConfig signingConfigs.release
//
applicationIdSuffix ".debug"
}
}
-
在AndroidManifest中用到applicationId的地方尤其是fileProvider,使用占位符
${applicationId}
代替,编译器会自动将替换为真实的值 -
builde.gradle中没有定义applicationId的话会使用AndroidManifest的packagename
-
修改下安装包的名称(AndroidStudio 3)
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "app-${variant.baseName}-${variant.versionName}.apk"
}
}
Gradle 自定义插件编译过程中读取配置报错问题
遇到问题,主要是关于Gradle脚本的执行过程的问题,根源是读取配置的时机问题
A Gradle build has three distinct phases.
InitializationGradle
supports single and multi-project builds. During the initialization phase, Gradle determines which projects are going to take part in the build, and creates a Project instance for each of these projects.
Configuration
During this phase the project objects are configured. The build scripts of all projects which are part of the build are executed.
ExecutionGradle
determines the subset of the tasks, created and configured during the configuration phase, to be executed. The subset is determined by the task name arguments passed to the gradle command and the current directory. Gradle then executes each of the selected tasks.
配置过程中获取相关配置信息的值就会为空,正确的获取时机是在Configuration完成后(project.afterEvaluate)执行获取逻辑
网友评论