Using tastes in the Android studio and - an error with the wrong AndroidManifest, selected or not combined

I'm trying to customize the flavors, so I can create different applications in the same project that have the same code ... But I'm not sure if I am doing this completely correctly ...

I created a com.sharedid.app project in the W: \ android-studio-projects \ sharedid \ folder

For this i

1) Created by AndroidManifest.xml in W: \ android-studio-projects \ sharedid \ app \ src \ main looks 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 the shared and / or dummy resources

For my flavor , I have:

1) I created AndroidManifest.xml in W: \ android-studio-projects \ sharedid \ app \ src \ myflavour (this file determines that everything is independent for each flavor)

2) In W: \ android-studio-projects \ sharedid \ app \ src \ myflavour \ res I have one drawable-hdpi folder containing variois graphics

3) In W: \ android-studio-projects \ sharedid \ app \ src \ myflavour \ assets I have all kinds of data, configuration and graphic files for which the application indicates. (read by 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 this:

 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 select "module = app" and "build-variant = com.myflavour.appDebug" in the "build" options and click "Run> Debug ...", I get a dialog that says: "Error: default activity not found"

From my research on flavorings, I don’t need to determine the paths to the sources, since I use standard conventenion files for flavorings ... If I'm right, this is not so - then why doesn’t he see the Androidmanifest file for the selected taste?

Links for reference I base my understanding on:

Additional troubleshooting

In an attempt to find the root of this problem, I began to suspect that the merge was not working. The reason for this suspicion was that if I ignored the inactivity error and tried to pull the compiled application onto my mobile phone, I would get a warning that the version number is less than the one installed on the mobile device. file was used.

So I also tried to remove src / main / AndroidManifest.xml, which leads to an error:

A problem was detected with the task configuration ': Application: checkmyflavourDebugManifest. file W: \ Android-studio-projects \ sharedid \ SRC \ main \ AndroidManifest.xml "specified for the 'manifest' property does not exist

This makes me think that Android Studio completely ignores the fact that I actually indicate that it uses a different manifest file ... And at the same time, although it would seem that I built the correct construction of the changes.

I would appreciate any comment / analysis on this subject, even if I just confirmed my thinking about the reason.

Screenshot of my current installation

(in this screenshot, I experimented with deleting the main / shared androidmanifest file, but otherwise it ends)

Last update

I conclude that the flyers are not working / the gradle setting should be wrong. If, for example, select building change myflavourDebug Android studio does not use the manifest file defined in gradle. This should be enough to conclude what the problem is.

Maybe my gradle file is wrong, I don’t know, but I really cared to get it right. If someone puts in asnwer while generosity is active, I will try to rush and appoint him.

+5
source share
3 answers

I think the problem is here:

 applicationId "com.myflavour.app" 

You define your applications as com.myflavour.app in your build.gradle. In your AndroidManifest you specify

 <activity android:name="com.shared.app.SharedMain" android:label="@string/MicMainName" > 

as the main activity. Your main action should be named after your application, if I'm not mistaken. So basically you should try to change either your manifest to declare your activity as com.myflavour.app , and arrange your packaging accordingly, or just use the same applicationId for your taste.

+3
source

use flavors. There is no need to create manifest files for each of them. Just put all your classes in the src / mani / AndroidManifest.xml file. If you still want to use both files, delete the conflicts without blocking the intent filter block:

 <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> 

Use it only once.

And finally, you can find a lot of useful information about http://developer.android.com/tools/building/manifest-merge.html

A quick quote from there:

During the build process, the manifest merge process stores a record of each merge transaction in the manifest-merger file - report.txt in the build / output / logs module. A different log file is created for each module build option.

+2
source

It is not possible to combine manifests with different package names.
I think this is a problem.
Just remove package="com.myflavour.app" from the myflavour manifest.

0
source

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


All Articles