4

I am having troubles understanding Build Flavors in Android Studio. I am trying to achieve a simple thing: buidling 2 signed APK's with a minor code change. The "pro" APK just has a different drawer.xml in res/layout/. I've read a few things in the Documentation and here on StackOverflow but I don't see anything happen with my build.gradle changes.

my 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 my build.gradle file above.

After resetting my whole Android Studio because of some other instabilities I am now able to choose in the bottom left corner my build variants (lite-debug, lite-release, pro-debug, pro-release) Why even those debug AND release variants?

This seems to work now as it should.

I added a answer below

mike.b93
  • 1,929
  • 2
  • 17
  • 30

3 Answers3

6

After resetting my whole Android Studio because of some other instabilities I am now able to choose in the bottom left corner my build variants (lite-debug, lite-release, pro-debug, pro-release) Why even those debug AND release variants?

I created a whole new Project with Module and copy&pasted everything from my old project which I exported from eclipse a while back in there.

NOW it works.

My Android-Studio was kinda broken before my reinstall. More crashes than there should be, some strange behaviors ans such stuff.

mike.b93
  • 1,929
  • 2
  • 17
  • 30
1

What you're doing wrong is that you are putting your file in /src/main/res_pro/layout/drawer.xml and not setting it in the gradle. the default location for the flavor that you created would be:

/src/pro/res/layout/drawer.xml
maclir
  • 2,938
  • 22
  • 33
0

With this build script you are using build types AND flavors. For changing the xml file you only need the flavors. Try to delete buildTypes and use the productFlavor block as child of android. The changing of the res folder of the pro flavor should go into the sourceSets Block right after all the changes of the main sourceSet

rivare
  • 817
  • 8
  • 6
  • okay I just found out something that could be the root of all evil. `[PROJECT] is not backed by gradle` How the hell? I imported the Project from Eclipse as described in the docs. How do I fix this? – mike.b93 Jul 02 '13 at 15:00
  • 1
    see this [answer](http://stackoverflow.com/a/17168175/1237841). Maybe not related to your problems, but you should use "gradle:0.4.3" for the current version or "gradle:0.4.+" to always get the latest. – rivare Jul 02 '13 at 15:38
  • my android studio was kinda messed up and I reinstalled it. Now, gradle seems totally broken haha. – mike.b93 Jul 02 '13 at 15:44
  • Where should I set `Gradle Home`?? Android Studio can't seem to find it and I can't find anything about that – mike.b93 Jul 02 '13 at 15:52
  • You are better off just using the gradle wrapper instead of pointing to an installed gradle then you don't even have to install gradle. –  Jul 02 '13 at 16:30