I am trying to set up flavours, so I can build different apps in he same project that share the same code... But I am not sure I am doing it fully correct...
I have created a project called com.sharedid.app in folder W:\android-studio-projects\sharedid\
For this I have
1) Created AndroidManifest.xml in W:\android-studio-projects\sharedid\app\src\main looking like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sharedid.app"
android:versionCode="1"
android:versionName="1.0"
>
<activity android:name="com.shared.app.SharedMain" android:label="@string/MicMainName" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</manifest>
2) In W:\android-studio-projects\sharedid\app\src\main\java ... I have all .java files
3) In W:\android-studio-projects\sharedid\app\src\main\res I have all shared and/or dummy resources
For my flavour I have:
1) I have created AndroidManifest.xml in W:\android-studio-projects\sharedid\app\src\myflavour (this file is what defines everything - it is unqiue for each flavour)
2) In W:\android-studio-projects\sharedid\app\src\myflavour\res I have a single folder drawable-hdpi conttaining variois graphics
3) In W:\android-studio-projects\sharedid\app\src\myflavour\assets I have all sorts of data, configuration and graphic files for that specifc app. (read by the code at runtime)
4) In *W:\android-studio-projects\sharedid\app\src\myfavlour* I have the following AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myflavour.app"
android:versionCode="2"
android:versionName="2.0"
>
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17"
/>
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/app_logo__forlarge"
android:label="@string/MicAppName"
android:theme="@style/MicTheme_myflavour"
android:name="com.shared.app.MicApp"
>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.myflavour.app.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_filepaths" />
</provider>
<activity android:name="com.shared.app.SharedMain" android:label="@string/MicMainName" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity>...more...</activity>
</application>
</manifest>
Here's how "Gradle Scripts" - "Build Gradle" (Module: app) looks like:
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.sharedid.app"
minSdkVersion 9
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
repositories {
maven { url "https://jitpack.io" }
}
productFlavors {
myflavour {
applicationId "com.myflavour.app"
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
myflavour {
manifest.srcFile 'src/myflavour/AndroidManifest.xml'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:21.1.2'
compile 'com.github.PhilJay:MPAndroidChart:v2.0.8'
}
My problem is this
When I in "build variants" select "module=app" and "build-variant=com.myflavour.appDebug" and click "Run > Debug..." I get a dialog that states: "Error: Default activity not found"
From my studies of flavours I should not need to define sourcesets paths since I use the default conventenion of files for flavours... If I am right abnout that - then why does it not see the Androidmanifest file for the flavour selected?
Links for reference I base my understanding on:
- https://developer.android.com/tools/building/manifest-merge.html
- Gradle flavors for android with custom source sets - what should the gradle files look like?
Additional troubleshooting
In my attempt to find the root of this problem, I begun to suspect manifest merging was not working. The reason for this suspicion was that if I ignored the error about no activity and tried to push the compiled app out on the mobile, I would get a warning about the version number being smaller than the one installed on the mobile - clear indication wrong manifest file was being used.
So i have also tried to delete src/main/AndroidManifest.xml which results in error:
A problem was found with the configuration of task ':app:checkmyflavourDebugManifest'. File W:\android-studio-projects\sharedid\src\main\AndroidManifest.xml' specified for property 'manifest' does not exist
This leads me to believe Android Studio is completely ignoring that I am actually specifying it to use another manifest file... And the same time though it would seem i an building the correct variation build.
I would apreciate any comment/analysis on this - even if just to confirm my thinking of the cause
Screenshot of my current setup
(in this screenshot I have experiemented deleting main/shared androidmanifest file, but otherwise it complete)
Latest update
I conclude flavors is not working / my gradle setup must be wrong. If I e.g. select building variation myflavourDebug Android studio does not use the manifest file defined in gradle. This alone should be enough to conclude where the problem relies.
Maybe my gradle file is wrong somehow, I don't know, but I have taken great care in getting i right. If someone posts an asnwer while bounty is active I will try hurry and assign it.