how to get current selected product flavors in app/build.gradle file
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Example, I have area1 and area2 flavors, but just area2 have google gms dependency, and I just want apply gms plugin to area2, so I need decide
current flavors as area == 'area2'
, obvious this can't succeed, so how can I to do ?
flavorDimensions "area"
productFlavors {
area1 {
dimension "area"
applicationId 'com.sample.area1'
}
area2 {
dimension "area"
applicationId 'com.sample.area2'
}
}
dependencies {
area2Implementation 'com.google.android.gms:play-services-auth: 16.0.1'
}
if(area == 'area2') {
apply plugin: 'com.google.gms.google-services'
}
android gradle
add a comment |
Example, I have area1 and area2 flavors, but just area2 have google gms dependency, and I just want apply gms plugin to area2, so I need decide
current flavors as area == 'area2'
, obvious this can't succeed, so how can I to do ?
flavorDimensions "area"
productFlavors {
area1 {
dimension "area"
applicationId 'com.sample.area1'
}
area2 {
dimension "area"
applicationId 'com.sample.area2'
}
}
dependencies {
area2Implementation 'com.google.android.gms:play-services-auth: 16.0.1'
}
if(area == 'area2') {
apply plugin: 'com.google.gms.google-services'
}
android gradle
add a comment |
Example, I have area1 and area2 flavors, but just area2 have google gms dependency, and I just want apply gms plugin to area2, so I need decide
current flavors as area == 'area2'
, obvious this can't succeed, so how can I to do ?
flavorDimensions "area"
productFlavors {
area1 {
dimension "area"
applicationId 'com.sample.area1'
}
area2 {
dimension "area"
applicationId 'com.sample.area2'
}
}
dependencies {
area2Implementation 'com.google.android.gms:play-services-auth: 16.0.1'
}
if(area == 'area2') {
apply plugin: 'com.google.gms.google-services'
}
android gradle
Example, I have area1 and area2 flavors, but just area2 have google gms dependency, and I just want apply gms plugin to area2, so I need decide
current flavors as area == 'area2'
, obvious this can't succeed, so how can I to do ?
flavorDimensions "area"
productFlavors {
area1 {
dimension "area"
applicationId 'com.sample.area1'
}
area2 {
dimension "area"
applicationId 'com.sample.area2'
}
}
dependencies {
area2Implementation 'com.google.android.gms:play-services-auth: 16.0.1'
}
if(area == 'area2') {
apply plugin: 'com.google.gms.google-services'
}
android gradle
android gradle
edited Jan 4 at 3:20
user6915871
asked Jan 4 at 2:53
user6915871user6915871
85
85
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Just add the following android.applicationVariants.all
configuration in your Android block:
android {
// Flavor definitions here
productFlavors {
// ...
}
android.applicationVariants.all { variant ->
if (variant.flavorName == "area2") {
apply plugin: 'com.google.gms.google-services'
}
}
}
==== Updated 7/1/2019 ====
Just realize the above block of android.applicationVariants.all
is executed for all build variants each time (i.e. if you have 2 build types plus 3 flavors it will be hit by all of the 6 variants). And it's actually to prepare different configurations for individual variants to build later.
So in order to achieve the purpose we need to apply the plugin during the build phase. Not sure if there's a better way but I managed to do something tricky like:
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Area2")) {
apply plugin: 'com.google.gms.google-services'
}
I put this at the end of the Gradle file, out of the Android block (where the "apply plugin" block originally is). Also note that you need to have your flavor keyword's first character in upper case because it's part of the task name string like [:app:assembleArea2Debug]]
if you use println to check it out in gradle console.
this can't, when I build area1 (./gradlew assembleArea1Debug), apply plugin gms also execute.
– user6915871
Jan 4 at 10:12
Just updated the answer.
– Wei WANG
Jan 6 at 23:56
Thank you, Your solution is working fine. also, I found another solution that have writed to second answer.
– user6915871
Jan 9 at 7:02
add a comment |
I found a solution:
gradle.taskGraph.whenReady { taskGraph ->
def tasks = taskGraph.getAllTasks()
for(task in tasks) {
if(task.getName().startsWith('assembleArea2')) {
apply plugin: 'com.google.gms.google-services'
break
}
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54032562%2fhow-to-get-current-selected-product-flavors-in-app-build-gradle-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just add the following android.applicationVariants.all
configuration in your Android block:
android {
// Flavor definitions here
productFlavors {
// ...
}
android.applicationVariants.all { variant ->
if (variant.flavorName == "area2") {
apply plugin: 'com.google.gms.google-services'
}
}
}
==== Updated 7/1/2019 ====
Just realize the above block of android.applicationVariants.all
is executed for all build variants each time (i.e. if you have 2 build types plus 3 flavors it will be hit by all of the 6 variants). And it's actually to prepare different configurations for individual variants to build later.
So in order to achieve the purpose we need to apply the plugin during the build phase. Not sure if there's a better way but I managed to do something tricky like:
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Area2")) {
apply plugin: 'com.google.gms.google-services'
}
I put this at the end of the Gradle file, out of the Android block (where the "apply plugin" block originally is). Also note that you need to have your flavor keyword's first character in upper case because it's part of the task name string like [:app:assembleArea2Debug]]
if you use println to check it out in gradle console.
this can't, when I build area1 (./gradlew assembleArea1Debug), apply plugin gms also execute.
– user6915871
Jan 4 at 10:12
Just updated the answer.
– Wei WANG
Jan 6 at 23:56
Thank you, Your solution is working fine. also, I found another solution that have writed to second answer.
– user6915871
Jan 9 at 7:02
add a comment |
Just add the following android.applicationVariants.all
configuration in your Android block:
android {
// Flavor definitions here
productFlavors {
// ...
}
android.applicationVariants.all { variant ->
if (variant.flavorName == "area2") {
apply plugin: 'com.google.gms.google-services'
}
}
}
==== Updated 7/1/2019 ====
Just realize the above block of android.applicationVariants.all
is executed for all build variants each time (i.e. if you have 2 build types plus 3 flavors it will be hit by all of the 6 variants). And it's actually to prepare different configurations for individual variants to build later.
So in order to achieve the purpose we need to apply the plugin during the build phase. Not sure if there's a better way but I managed to do something tricky like:
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Area2")) {
apply plugin: 'com.google.gms.google-services'
}
I put this at the end of the Gradle file, out of the Android block (where the "apply plugin" block originally is). Also note that you need to have your flavor keyword's first character in upper case because it's part of the task name string like [:app:assembleArea2Debug]]
if you use println to check it out in gradle console.
this can't, when I build area1 (./gradlew assembleArea1Debug), apply plugin gms also execute.
– user6915871
Jan 4 at 10:12
Just updated the answer.
– Wei WANG
Jan 6 at 23:56
Thank you, Your solution is working fine. also, I found another solution that have writed to second answer.
– user6915871
Jan 9 at 7:02
add a comment |
Just add the following android.applicationVariants.all
configuration in your Android block:
android {
// Flavor definitions here
productFlavors {
// ...
}
android.applicationVariants.all { variant ->
if (variant.flavorName == "area2") {
apply plugin: 'com.google.gms.google-services'
}
}
}
==== Updated 7/1/2019 ====
Just realize the above block of android.applicationVariants.all
is executed for all build variants each time (i.e. if you have 2 build types plus 3 flavors it will be hit by all of the 6 variants). And it's actually to prepare different configurations for individual variants to build later.
So in order to achieve the purpose we need to apply the plugin during the build phase. Not sure if there's a better way but I managed to do something tricky like:
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Area2")) {
apply plugin: 'com.google.gms.google-services'
}
I put this at the end of the Gradle file, out of the Android block (where the "apply plugin" block originally is). Also note that you need to have your flavor keyword's first character in upper case because it's part of the task name string like [:app:assembleArea2Debug]]
if you use println to check it out in gradle console.
Just add the following android.applicationVariants.all
configuration in your Android block:
android {
// Flavor definitions here
productFlavors {
// ...
}
android.applicationVariants.all { variant ->
if (variant.flavorName == "area2") {
apply plugin: 'com.google.gms.google-services'
}
}
}
==== Updated 7/1/2019 ====
Just realize the above block of android.applicationVariants.all
is executed for all build variants each time (i.e. if you have 2 build types plus 3 flavors it will be hit by all of the 6 variants). And it's actually to prepare different configurations for individual variants to build later.
So in order to achieve the purpose we need to apply the plugin during the build phase. Not sure if there's a better way but I managed to do something tricky like:
if (getGradle().getStartParameter().getTaskRequests().toString().contains("Area2")) {
apply plugin: 'com.google.gms.google-services'
}
I put this at the end of the Gradle file, out of the Android block (where the "apply plugin" block originally is). Also note that you need to have your flavor keyword's first character in upper case because it's part of the task name string like [:app:assembleArea2Debug]]
if you use println to check it out in gradle console.
edited Jan 9 at 22:46
answered Jan 4 at 3:22
Wei WANGWei WANG
1,0901117
1,0901117
this can't, when I build area1 (./gradlew assembleArea1Debug), apply plugin gms also execute.
– user6915871
Jan 4 at 10:12
Just updated the answer.
– Wei WANG
Jan 6 at 23:56
Thank you, Your solution is working fine. also, I found another solution that have writed to second answer.
– user6915871
Jan 9 at 7:02
add a comment |
this can't, when I build area1 (./gradlew assembleArea1Debug), apply plugin gms also execute.
– user6915871
Jan 4 at 10:12
Just updated the answer.
– Wei WANG
Jan 6 at 23:56
Thank you, Your solution is working fine. also, I found another solution that have writed to second answer.
– user6915871
Jan 9 at 7:02
this can't, when I build area1 (./gradlew assembleArea1Debug), apply plugin gms also execute.
– user6915871
Jan 4 at 10:12
this can't, when I build area1 (./gradlew assembleArea1Debug), apply plugin gms also execute.
– user6915871
Jan 4 at 10:12
Just updated the answer.
– Wei WANG
Jan 6 at 23:56
Just updated the answer.
– Wei WANG
Jan 6 at 23:56
Thank you, Your solution is working fine. also, I found another solution that have writed to second answer.
– user6915871
Jan 9 at 7:02
Thank you, Your solution is working fine. also, I found another solution that have writed to second answer.
– user6915871
Jan 9 at 7:02
add a comment |
I found a solution:
gradle.taskGraph.whenReady { taskGraph ->
def tasks = taskGraph.getAllTasks()
for(task in tasks) {
if(task.getName().startsWith('assembleArea2')) {
apply plugin: 'com.google.gms.google-services'
break
}
}
}
add a comment |
I found a solution:
gradle.taskGraph.whenReady { taskGraph ->
def tasks = taskGraph.getAllTasks()
for(task in tasks) {
if(task.getName().startsWith('assembleArea2')) {
apply plugin: 'com.google.gms.google-services'
break
}
}
}
add a comment |
I found a solution:
gradle.taskGraph.whenReady { taskGraph ->
def tasks = taskGraph.getAllTasks()
for(task in tasks) {
if(task.getName().startsWith('assembleArea2')) {
apply plugin: 'com.google.gms.google-services'
break
}
}
}
I found a solution:
gradle.taskGraph.whenReady { taskGraph ->
def tasks = taskGraph.getAllTasks()
for(task in tasks) {
if(task.getName().startsWith('assembleArea2')) {
apply plugin: 'com.google.gms.google-services'
break
}
}
}
answered Jan 9 at 7:08
user6915871user6915871
85
85
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54032562%2fhow-to-get-current-selected-product-flavors-in-app-build-gradle-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown