我正在尝试通过将原始 id 附加到 GIT 分支的分支名称来更改我的 applicationId 。剧本重命名ID.sh完成重命名applicationID的工作。
虽然我可以在运行构建时成功重命名ApplicationID,但我希望在构建后恢复applicationID。
脚本restoreID是将applicationID恢复为原始名称,但似乎不起作用。
有人可以指出我做错了什么或建议一些更好的方法来执行我的目标任务吗?
apply plugin: 'com.android.application'
class Config{
String name
}
task renameAppId(type:org.gradle.api.tasks.Exec) {
commandLine 'sh', 'renameID.sh'
}
preBuild.dependsOn renameAppId
task finaltask(type:org.gradle.api.tasks.Exec){
commandLine 'sh', 'restoreID.sh'
}
build.finalizedBy(finaltask)
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.abc.xyz"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:support-v4:24.0.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:design:22.2.1'
}
有一个 applicationIdSuffix 函数,您可以将其应用于您的 buildType。像这样的东西
buildTypes {
debug {
applicationIdSuffix branch_name
}
}
另外,您可以通过这种方式获取当前分支名称
def branch_name = ""
try {
branch_name = "git rev-parse --abbrev-ref HEAD".execute().text.trim();
} catch (ignored) {
println "Git not found"
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)