Monday, 28 May 2018

Product flavors in Android Studio

I can not get product flavours working. I have this gradle
apply plugin: 'com.android.application'
android {
    defaultConfig {
      minSdkVersion 14
      targetSdkVersion 24
      compileSdkVersion 27
    }
    signingConfigs {
        release {
      }
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
            signingConfig signingConfigs.release
        }
    }
    repositories {
        maven { url "https://jitpack.io" }
    }
    flavorDimensions "dim1", "dim2", "dim3"
    productFlavors {
        flavor1 {
            dimension "dim1"
            applicationId "com.example.dim1.app"
        }
        flavor3 {
            dimension "dim2"
            applicationId "com.example.dim2.app"
        }
        flavor3 {
            dimension "dim3"
            applicationId "com.example.dim3.app"
        }
    }
    sourceSets {
        flavor1 {
          java.srcDirs = ["W:/android-studio-projects/sharedid/app/src/main/java/"]
          manifest.srcFile "W:/android-studio-projects/sharedid/app/src/example1/AndroidManifest.xml"
          assets.srcDirs = ["W:/android-studio-projects/sharedid/app/src/example1/assets/"]
          resources.srcDirs = ["W:/android-studio-projects/sharedid/app/src/main/res/", "W:/android-studio-projects/sharedid/
app/src/example1/res/"]
        }
        flavor2 {
          java.srcDirs = ["W:/android-studio-projects/sharedid/app/src/main/java/"]
          manifest.srcFile "W:/android-studio-projects/sharedid/app/src/example2/AndroidManifest.xml"
          assets.srcDirs = ["W:/android-studio-projects/sharedid/app/src/example2/assets/"]
          resources.srcDirs = ["W:/android-studio-projects/sharedid/app/src/main/res/", "W:/android-studio-projects/sharedid/
app/src/example2/res/"]
        }
        flavor3 {
          java.srcDirs = ["W:/android-studio-projects/sharedid/app/src/main/java/"]
          manifest.srcFile "W:/android-studio-projects/sharedid/app/src/example3/AndroidManifest.xml"
          assets.srcDirs = ["W:/android-studio-projects/sharedid/app/src/example3/assets/"]
          resources.srcDirs = ["W:/android-studio-projects/sharedid/app/src/main/res/", "W:/android-studio-projects/sharedid/
app/src/example3/res/"]
        }
    }
}
dependencies {
    api 'com.google.android.gms:play-services-maps:15.0.0'
    api 'com.google.android.gms:play-services-location:15.0.0'
    api 'com.android.support:appcompat-v7:27.1.1'
    api 'com.github.PhilJay:MPAndroidChart:v2.0.8'

}

...
When I got to "Build | Select variant" I can only select
Module:app Build Variant:flavor1Flavor2Flavor3Debug,flavor1Flavor2Flavor3Release
I would have liked to get
  • the following build variants: flavor1Debug,flavor2Debug,flavor3Debug,flavor1Release,flavor2Release,flavor3Release
I have tried "File | Sync project with gradle file"
...
I get this error
Caused by: java.lang.RuntimeException: Cannot read packageName from W:\android-studio-projects\sharedid\app\src\main\AndroidManifest.xml
I have tried to both
  • have no such file (hoping it would take the product flavor one?)
  • have the "main" manifest only define shared stuff between all product flavors


from Product flavors in Android Studio

No comments:

Post a Comment