Reputation: 35
I am trying to change my applicationId by appending it the original id with the branch name of the GIT branch. The Script renameID.sh does the work of renaming applicationID.
Although I can successfully rename the ApplicationID while running build, but I want that applicationID is restored after build.
The script restoreID is to restore the applicationID to original name, but doesn't seems to work.
Can someone point what am I doing wrong or suggest some better way to perform my objective task?
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'
}
Upvotes: 2
Views: 2958
Reputation: 66
There is an applicationIdSuffix function which you can apply to your buildType. Something like this
buildTypes {
debug {
applicationIdSuffix branch_name
}
}
In addition, you can get current branch name by this way
def branch_name = ""
try {
branch_name = "git rev-parse --abbrev-ref HEAD".execute().text.trim();
} catch (ignored) {
println "Git not found"
}
Upvotes: 4
Reputation: 5709
I think you can achieve your goal using product flavour. In your app build.gradle, under android, you can add some flavour like this
productFlavors {
full {
applicationId "com.mycomp.myapp"
}
gitBranch {
applicationId "com.mycomp.myapp.git_branch"
}
}
Then remove applicationId from defaultConfig Now when you build, you can choice which build variant (builtype + flavour) to use by the panel on bottom left of android studio. In this case they should be debugFull, debugGitBranch, releaseFull and releaseGitBranch. You final apk will have applicationId accordingly with the one you have inserted in the used flavour.
Hope this helps
Upvotes: 0