Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep certain Build Variant selected in Android Studio?

I understand from the documentation (reproduced below) that the Build Variants are generated during Gradle sync, but how could I keep a particular one "active" or selected in Android Studio?

Problem is that after checking out a branch I find the selected Build Variant has been reset.

I can not find an "active Build Variant" setting in any project (idea) files.

Have already seen this possibly related question.

Thanks.

Documentation from developer.android.com:

After the [Gradle] sync completes, Gradle automatically creates build variants based on your build types and product flavors, and names them according to . For example, if you created "demo" and "full" product flavors, and kept the default "debug" and "release" build types, Gradle creates the following build variants:

demoDebug, demoRelease, fullDebug, fullRelease

You can change the build variant to whichever one you want to build and run—just go to

Build > Select Build Variant and select one from the drop-down menu.

like image 505
TT-- Avatar asked Nov 28 '18 23:11

TT--


People also ask

How do I change a variant in build?

You can change the build variant to whichever one you want to build and run—just go to Build > Select Build Variant and select one from the drop-down menu. To start customizing each build variant with its own features and resources, however, you'll need to know how to create and manage source sets.

How can I get flavor on my Android?

You can add a config file, say 'Appconfig. java' to your productFlavor specific source folders i.e. src/<productflavor>/java/<packagename>/Appconfig. java ; you can then use Appconfig. PRODUCT_FLAVOR in your app.

What is productFlavors Android?

Android Product Flavors are used to create different app versions. App versions can be free or paid. They can have different themes and texts. They can use different environments or APIs. Let's assign two product flavors free and paid in our application.

What is a Buildtype in Gradle?

A build type determines how an app is packaged. By default, the Android plug-in for Gradle supports two different types of builds: debug and release . Both can be configured inside the buildTypes block inside of the module build file.


1 Answers

Updates:

Probably Android Studio 3.3+ is the way to go, as a new feature Syncing only active variant was introduced.

FileSettingsExperimentalGradleOnly sync the active variant


Here it is. The one circulated by red rectangle is the active build variant.

enter image description here


For how to disable the enforced gradle sync:

Go to "Settings" -> "Appearance & Behavior" -> "System Settings"

Uncheck "Synchronize files on frame or editor tab activation"

But remember to click on the "Sync Project with Gradle Files" button whenever you make changes to Gradle.

like image 190
shizhen Avatar answered Oct 02 '22 18:10

shizhen