Android Studio Gradle Build Flavors

I'm having trouble understanding Build Flavors in Android Studio. I am trying to achieve a simple thing: buidling 2 signed an APK with a slight code change. The "pro" APK has only drawer.xml in res/layout/ . I read a few things in the documentation and here in StackOverflow, but I don't see anything with my build.gradle changes.

current current build.gradle file:

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.4.+' } } apply plugin: 'android' dependencies { compile files('libs/android-support-v4.jar') compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar') } android { compileSdkVersion 17 buildToolsVersion "17.0.0" defaultConfig { minSdkVersion 14 targetSdkVersion 17 } productFlavors { lite { packageName = 'com.mikebdev.refuel' } pro { packageName = 'com.mikebdev.refuelpro' } } sourceSets{ android.sourceSets.pro { res.srcDirs = ['src/main/res_pro'] } } } 

I created a new folder:

 /src/main/res_pro/layout/drawer.xml 

What am I doing wrong here?

EDIT

I updated the build.gradle file above.

After resetting my entire Android studio due to some other instabilities, I can now select build options (lite-debug, lite-release, pro-debug, pro-release) in the lower left corner. Why even those debugs AND release options?

It now seems to work as it should.

I added the answer below

+4
source share
3 answers

After resetting my entire Android studio due to some other instabilities, I can now select build options (lite-debug, lite-release, pro-debug, pro-release) in the lower left corner. Why even those debugs AND release options?

I created a completely new Project with a module and copied everything that was from an old project that I exported from eclipse a while ago.

Now it works.

My Android-Studio was broken before I reinstalled. More glitches than it should be, some weird behaviors and such things.

+6
source

What you are doing wrong is that you put your file in /src/main/res_pro/layout/drawer.xml and do not set it in gradle. The default location for the fragrance you create will be as follows:

 /src/pro/res/layout/drawer.xml 
+1
source

With this build script, you use build types and flavors. To change the xml file you only need tastes. Try removing buildTypes and use the productFlavor block as a child of android. Changing the res pro pro folder should go into the SourceSets block immediately after all changes to the main source set

0
source

Source: https://habr.com/ru/post/1489289/


All Articles