I want to have ONE Android Studio (AS) 1.1.0 project create TWO APK files: one for pay version and one for free version of my Google Play Store (GPS) app. Using gradle build variants ("flavors"). I'm VERY close. I have uploaded from one AS project both versions--free and pay.
The only relatively-minor problems: I can't make the two versions have different icons and I can't make the action bar display different titles for the different apps.
Since we're dealing with flavors, there are three AndroidManifest.xml
files: one I CAN edit and two that gradle generates, one for each flavor. If I edit those, the edits are lost with the next build.
Here's "my" AndroidManifest.xml
:
package="com.dslomer64.kakurocombosbuildvariants" >
<application
android:icon="@drawable/kc_icon_free">
android:label="@string/app_name"
android:allowBackup="true"
>
<activity
android:screenOrientation="portrait"
android:icon="@drawable/kc_icon_free"
android:name=".MyActivity"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Except for package name, the generated AndroidManifest.xml
files are identical (here's one):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dslomer64.kakurocombosbuildvariants.pro"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:label="KC" >
<activity
android:name="com.dslomer64.kakurocombosbuildvariants.MyActivity"
android:icon="@drawable/kc_icon_free"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I'm basing what I'm doing on this build.gradle
file listed here, which has outdated content, flagged with ///////////:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+' /////////(wrong version)
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 18
}
productFlavors {
production {
packageName "be.tamere.gradlebuildtypesexample" ////// packageName should be applicationId
}
staging {
packageName "be.tamere.gradlebuildtypesexample.staging"
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:18.0.0'
}
Also basing my effort on this sketch of the associated file structure:
+-- main
¦ +-- AndroidManifest.xml
¦ +-- ic_launcher-web.png
¦ +-- java
¦ ¦ +-- be
¦ ¦ +-- tamere
¦ ¦ +-- gradlebuildtypesexample
¦ ¦ +-- MainActivity.java
¦ +-- res
¦ +-- drawable-hdpi
¦ ¦ +-- ic_launcher.png
¦ +-- drawable-mdpi
¦ ¦ +-- ic_launcher.png
¦ +-- drawable-xhdpi
¦ ¦ +-- ic_launcher.png
¦ +-- drawable-xxhdpi
¦ ¦ +-- ic_launcher.png
¦ +-- layout
¦ ¦ +-- activity_main.xml
¦ +-- menu
¦ ¦ +-- main.xml
¦ +-- values
¦ ¦ +-- dimens.xml
¦ ¦ +-- strings.xml
¦ ¦ +-- styles.xml
¦ +-- values-v11
¦ ¦ +-- styles.xml
¦ +-- values-v14
¦ +-- styles.xml
+-- production
¦ +-- java
¦ +-- be
¦ +-- tamere
¦ +-- gradlebuildtypesexample
¦ +-- Constants.java
+-- staging
+-- java
¦ +-- be
¦ +-- tamere
¦ +-- gradlebuildtypesexample
¦ +-- Constants.java
+-- res
+-- drawable-hdpi
¦ +-- ic_launcher.png
+-- drawable-mdpi
¦ +-- ic_launcher.png
+-- drawable-xhdpi
¦ +-- ic_launcher.png
+-- drawable-xxhdpi
¦ +-- ic_launcher.png
+-- values
+-- string.xml
I don't know if lack of "|" symbols from staging on down is significant. If so, that could be where I'm diverging.
When I try to create both APKs, I eventually get this screen, which is great news:
Inside AS, I see this, which is great news:
And in Windows 7 Explorer I see:
Here's my structure inside AS:
This corresponds to the structure shown in the link. Note especially NO res
folder in the free
version. The res
folder in main
contains the icon for free
version. The res
folder in pro
contains the icon for pro
version.
How can I get different icons for the two different APKs?
Why does the title in the action bar for both versions show as a fully-qualified package name?
Is there a way to edit the generated AndroidManifest.xml
files? Or to make each flavor have its own editable AndroidManifest.xml
?