Customize AndroidManifest in different build types - android

I want to customize AndroidManifest in different build types. For example in debug mode I just want an Activity to be exported.
Assume main manifest:
/main/AndroidManifest.xml
<application>
<activity
android:name="com.example.MainActivity" />
</application>
Debug manifest:
/debug/AndroidManifest.xml
<application>
<activity
android:name="com.example.MainActivity"
android:exported="true" />
</application>
Example manifest (same as debug):
/example/AndroidManifest.xml
<application>
<activity
android:name="com.example.MainActivity"
android:exported="true" />
</application>
In the debug manifest I get Duplicate registration for activity com.example.MainActivity
That's why I created the example build type.
/build.gradle
android {
buildTypes {
example.initWith(buildTypes.debug)
}
}
But it also doesn't work.
[AndroidManifest.xml:17, AndroidManifest.xml:4] Trying to merge incompatible /manifest/application/activity[#name=com.example.MainActivity] element:
<activity
-- #android:name="com.example.MainActivity">
--</activity>
--(end reached)
<activity
++ #android:exported="true"
++ #android:name="com.example.MainActivity">
++</activity>
I'm wondering whether this is a bug, missing feature (will be implemented in the future) or I'm doing something wrong?
I know I can provide different manifest in release and debug (without the one in /main), but I don't think this is a good solution.
EDIT:
The solution so far is to define bool in resources and use it inside main manifest.
In debug resources the bool will be true while in the release false. This solution seems much better than duplicated manifests, but the question is still actual.

As of gradle plugin 0.10 it's finally supported. More info about new manifest merger: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger
At the moment (gradle plugin 0.10) it requires this extra configuration in build.gradle
android {
useOldManifestMerger false
}

I know I can provide different manifest in release and debug (without
the one in /main), but I don't think this is a good solution.
Unfortunately, there's a limitation in the merging of manifests where you can't define the same thing (Activity, Service, Receiver, etc.) in the main manifest and the build type manifest. The solution is to define only the non-buildtype specific stuff in the main manifest and everything else in the build type manifests.

Related

android:exported added but still getting error Apps targeting Android 12 and higher are required to specify an explicit value for android:exported

I have added android:exported="true" to my only activity in manifest but still getting below error after updating compile sdk and target sdk version to 31.I also tried rebuilding the project , invalidating cache and restart but that didn't helped
Error- Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
AndroidManifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xyz.abc">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".framework.presentation.BaseApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="com.xyz.presentation.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Merged manifest error
Other Manifest Files (Included in merge, but did not contribute any
elements) firebase-installations:17.0.0 manifest,
versionedparcelable:1.1.1 manifest, runtime:1.0.1 manifest,
test:core:1.2.0 manifest, loader:1.0.0 manifest, facebook-share:11.1.0
manifest, leakcanary:leaksentry:2.0-alpha-3 manifest,
material-dialogs:input:3.2.1 manifest, material-icons-extended:1.0.0
manifest, play-services-stats:17.0.0 manifest, interpolator:1.0.0
manifest, activity-compose:1.3.1 manifest, material-ripple:1.0.0
manifest, foundation:1.0.0 manifest, asynclayoutinflater:1.0.0
manifest, savedstate-ktx:1.1.0 manifest,
navigation-dynamic-features-fragment:2.3.5 manifest,
firebase-ui-auth:7.2.0 manifest, animation:1.0.1 manifest,
animation-core:1.0.1 manifest, installreferrer:1.0 manifest,
firebase-crashlytics:18.0.0 manifest, ui:1.0.1 manifest,
lifecycle-viewmodel-savedstate:2.3.1 manifest,
play-services-auth-base:17.0.0 manifest, hilt-android:2.35.1 manifest,
material-dialogs:core:3.2.1 manifest, AndroidManifest.xml navigation
file, savedstate:1.1.0 manifest, cursoradapter:1.0.0 manifest,
sqlite-framework:2.0.1 manifest, room-ktx:2.1.0 manifest,
leakcanary-android-core:2.0-alpha-3 manifest, AndroidManifest.xml
navigation file, media:1.0.0 manifest, coordinatorlayout:1.1.0
manifest, legacy-support-core-utils:1.0.0 manifest,
lifecycle-runtime:2.3.1 manifest, coil-kt:coil:1.3.1 manifest,
ui-tooling-preview:1.0.0 manifest, facebook-core:11.1.0 manifest,
core:1.6.0 manifest, material:1.0.0 manifest, firebase-common:20.0.0
manifest, documentfile:1.0.0 manifest,
lifecycle-viewmodel-compose:2.4.0-beta01 manifest,
play-services-base:17.1.0 manifest, ui-tooling-data:1.0.0 manifest,
coil-base:1.3.1 manifest, firebase-analytics-ktx:19.0.0 manifest,
localbroadcastmanager:1.0.0 manifest, swiperefreshlayout:1.1.0-alpha03
manifest, constraintlayout-compose:1.0.0-beta02 manifest,
core-ktx:1.6.0 manifest, firebase-database-collection:18.0.0 manifest,
coil-compose-base:1.3.1 manifest, activity:1.3.1 manifest,
AndroidManifest.xml navigation file, facebook-messenger:11.1.0
manifest, print:1.0.0 manifest, customview:1.1.0 manifest,
material-icons-core:1.0.0 manifest,
play-services-measurement-sdk:19.0.0 manifest, fragment:1.3.4
manifest, firebase-appcheck-interop:16.0.0-beta01 manifest,
facebook-login:11.1.0 manifest, cardview:1.0.0 manifest,
runtime-rxjava2:1.0.0 manifest, viewpager2:1.0.0 manifest,
play-services-ads-identifier:17.0.0 manifest,
play-services-measurement-impl:19.0.0 manifest,
lifecycle-livedata-core:2.3.1 manifest, play-services-safetynet:17.0.0
manifest, AndroidManifest.xml navigation file,
lifecycle-viewmodel-ktx:2.3.1 manifest, transport-backend-cct:3.0.0
manifest, fragment-ktx:1.2.4 manifest, appcompat:1.3.0 manifest,
transport-runtime:3.0.0 manifest, lifecycle-livedata-core-ktx:2.2.0
manifest, firebase-firestore-ktx:23.0.0 manifest,
legacy-support-v4:1.0.0 manifest, play-services-basement:17.1.1
manifest, firebase-storage:20.0.0 manifest,
play-services-auth-api-phone:17.4.0 manifest,
leakcanary-android:2.0-alpha-3 manifest, firebase-auth-interop:20.0.0
manifest, lifecycle-viewmodel:2.3.1 manifest, browser:1.0.0 manifest,
firebase-auth:21.0.1 manifest, material:1.2.1 manifest,
slidingpanelayout:1.0.0 manifest, vectordrawable:1.1.0 manifest,
recyclerview:1.1.0 manifest, play-services-auth:19.0.0 manifest,
room-runtime:2.1.0 manifest, dagger-lint-aar:2.35.1 manifest,
navigation-dynamic-features-runtime:2.3.5 manifest,
play-services-measurement-api:19.0.0 manifest,
firebase-encoders-json:18.0.0 manifest, sqlite:2.0.1 manifest,
facebook-android-sdk:11.1.0 manifest, firebase-components:17.0.0
manifest, transport-api:3.0.0 manifest,
protolite-well-known-types:18.0.0 manifest, markdown-processor:0.1.3
manifest, play-services-measurement-base:19.0.0 manifest,
firebase-common-ktx:20.0.0 manifest, activity-ktx:1.3.1 manifest,
firebase-crashlytics-ktx:18.0.0 manifest, coil-compose:1.3.1 manifest,
multidex:2.0.1 manifest, core-runtime:2.1.0 manifest,
fragment-testing:1.2.0 manifest, ui-graphics:1.0.1 manifest,
AndroidManifest.xml navigation file, ui-tooling:1.0.0 manifest,
grpc-android:1.28.0 manifest, ui-unit:1.0.1 manifest,
play-services-measurement:19.0.0 manifest, play:core:1.9.1 manifest,
annotation-experimental:1.1.0 manifest,
play-services-measurement-sdk-api:19.0.0 manifest,
play-services-tasks:17.0.0 manifest, firebase-analytics:19.0.0
manifest, facebook-common:11.1.0 manifest, drawerlayout:1.1.1
manifest, AndroidManifest.xml navigation file,
navigation-compose:2.4.0-alpha09 manifest,
facebook-gamingservices:11.1.0 manifest, firebase-firestore:23.0.0
manifest, lifecycle-livedata:2.2.0 manifest,
legacy-support-core-ui:1.0.0 manifest, test:monitor:1.2.0 manifest,
AndroidManifest.xml navigation file, facebook-applinks:11.1.0
manifest, viewpager:1.0.0 manifest, ui-geometry:1.0.1 manifest,
lifecycle-runtime-ktx:2.3.1 manifest, constraintlayout:2.0.4 manifest,
ui-text:1.0.1 manifest, AndroidManifest.xml navigation file,
firebase-installations-interop:17.0.0 manifest, transition:1.3.0
manifest, foundation-layout:1.0.1 manifest, appcompat-resources:1.3.1
manifest, runtime-livedata:1.0.0 manifest, runtime-saveable:1.0.1
manifest, firebase-measurement-connector:19.0.0 manifest,
vectordrawable-animated:1.1.0 manifest, main nav_graph.xml navigation
file Merging Errors: Error: android:exported needs to be explicitly
specified for . Apps targeting Android 12 and higher are
required to specify an explicit value for android:exported when the
corresponding component has an intent filter defined. See
https://developer.android.com/guide/topics/manifest/activity-element#exported
for details. Dairy.app main manifest (this file) Error:
android:exported needs to be explicitly specified for . Apps
targeting Android 12 and higher are required to specify an explicit
value for android:exported when the corresponding component has an
intent filter defined. See
https://developer.android.com/guide/topics/manifest/activity-element#exported
for details. Dairy.app main manifest (this file) Error:
android:exported needs to be explicitly specified for . Apps
targeting Android 12 and higher are required to specify an explicit
value for android:exported when the corresponding component has an
intent filter defined. See
https://developer.android.com/guide/topics/manifest/activity-element#exported
for details. Dairy.app main manifest (this file)
androidx.test:core library version 1.3.0. Upgrading to version 1.4.0 fixed the issue.
To solve this error in target sdk 31-
1.First of all set target sdk to 30
2.Then go to the merged manifest
3.Find if there’s any activity, service, receiver or provider that does not have android:exported set.Override all those entries and set their android:exported to true or false.
4.set target sdk back to 31 and run project
See also android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify.
Thanks to #faizy, #Android Developer I made this.
Upgrade these libraries to new versions:
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.fragment:fragment-testing:1.4.1"
androidTestImplementation "androidx.test:core:1.4.0"
I replaced debugImplementation with androidTestImplementation in these dependencies.
Press Sync Project with Gradle Files. Run the project (or rebuild, or run Lint). Probably it won't help. Then you should make this.
Downgrade targetSdkVersion to 30.
Run the project again. Probably it will compile.
In my case all needed android:exported="true" and android:exported="false" presented in activity, service, receiver and provider of merged AndroidManifest where <intent-filter> occured.
To find merged AndroidManifest, switch to Project and expand app module, then build > intermediates > merged_manifest > debug.
If some android:exported was missing, find a corresponding AndroidManifest and add it there.
Upgrade targetSdkVersion to 31.
Run the project again. If it won't compile, probably you should rebuild the project. As usually, Build > Rebuild Project, File > Invalidate Caches > Invalidate and Restart.
After some time (several gradle syncs, restarts of Android Studio) it compiled.
The following in app/build.gradle may be the cause.
dependencies {
debugImplementation androidx.fragment:fragment-testing:<1.4.0-alpha02 or lower>’
}
Solution 1
Update fragment-testing to 1.4.0-alpha03 or higher.
Solution 2
Add the following to AndroidManifest.xml.
<manifest>
<application>
<activity
android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity"
android:exported="false" />
<activity
android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
android:exported="false" />
<activity
android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
android:exported="false" />
</application>
</manifest>
if you are using flutter , upgrading flutter_local_notifications to the latest version (now is 9.3.2) solved this error for me..
In my case the problem was with a dependency that strictly uses version 1.0.0 of androidx.test.core, so i can't upgrade it. what i did is to add android:exported="false" to androidx.test.core activity in my main manifest with tools:node="merge" so it can be merged with origin manifest
<activity
android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
android:exported="false"
tools:node="merge" >
</activity>
<activity
android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
android:exported="false"
tools:node="merge">
</activity>
and add the tools namespace.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
xmlns:tools="http://schemas.android.com/tools">
I had this problem, I add android:exported="true" and also tools:node="merge" to AndroidManifest.xml but however this error was appeared .
I found this is not about my project's Activates rather is about some dependencies, like this:
implementation 'com.najva.sdk:najva-android-sdk:1.3.3'
so check your project dependencies, you will find it surely.
if you use ogury Ads put this in youre AndroidManifest file
<activity
android:name="io.presage.mraid.browser.ShortcutActivity"
android:theme="#style/Presage.AdScreen"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
android { compileSdk 31
It is important to use latest version of Gradle and Gradle Plugin.
Update your all dependencies to latest version also.
If problem still persists.
Go to your manifest file.
Click merged manifest at the bottom.
Check the error at the bottom right side, which dependency is causing the error.
Go to that particular dependency from above mentioned dependencies.
Set android:exported="true" or android:exported="false" where error was mentioned in merged manifest.
Note: Updating that dependency to the latest version will probably also fix that issue. Because in the latest versions of dependenciesexported properties are already set.
This issue originates from dependencies of project. Right click on intent-filter and select find usages option. Now, in all usage places check that if exported assigned value or nor. If not, assign a value (Even in cache folders for libraries). This will fix issue until cache refresh but you have identifies the libraries creating this problem.
I found the answer,
you should add android:exported="true" to all activities, services and receivers in the AndroidManifest.xml file as following.
<activity
android:name="com.ryanheise.audioservice.AudioServiceActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:usesCleartextTraffic="true"
android:windowSoftInputMode="adjustResize">
<service android:name="com.ryanheise.audioservice.AudioService"
android:exported="true"
>
and for receiver
<receiver android:name="com.ryanheise.audioservice.MediaButtonReceiver"
android:exported="true"
Explicitly add the conflicting service to Properties\AndroidManifest.xml file, so that when it is merged in by your plugin it retains the android:exported="true" (or false).
<application>
...
<service android:name="1234.PNFirebaseMessagingService" android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
for me the solution was to add this tools:node="merge" behind each android:exported="true" and add xmlns:tools="http://schemas.android.com/tools" property in your manifest balise.
The solution is very simple, all you have to do is make sure that all of these tags are present...
<activity
android:exported="true"/>
<receiver
android:exported="true"/>
<service
android:exported="true"/>
just add android:exported="true" to all dont change any thing
and If you do not have any of the tags, you must add them all
Got the solution for this one for Nativescript project. [Tried and Tested]
Search intent-filter in the build project directory (./platforms)
Check if each intent-filter parent (activity, service, reciever..) have property android:exported="true".
If it does not have android:exported="true" then copy the whole <service/activity/reciever></service/activity/reciever> block
and put it into AndroidMenifest.xml under App_resource folder, update
the tag with android:exported="true" and again build the project.
Should Work Now.
if you are using flutter , upgrading flutter_local_notifications to the latest version (now is 9.3.2) may solve this error..
solve is the problem :
1- targetSdkVersion if 31 change to 30
2- add line in AndroidManifest inside <activity android:exported="true" />

Manifest merger failed targeting Android 12 [duplicate]

This question already has answers here:
android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify
(35 answers)
Closed 7 months ago.
Using Android Studio 4.2.1, after changing sdk target to Android 12 in my build.gradle file, I am getting a Manifest merger failed with multiple errors, see logs error.
The errors shown in the Merged Manifest tab are as follows:
Merging Errors:
Error: Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. My_App.app main manifest (this file)
Error: Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. My_App.app main manifest (this file)
Error: Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. My_App.app main manifest (this file)
However the android:exported tag is already applied in my AndroidManifest.xml file. I only have one activity. No services or broadcast receivers. See below:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mydomain.myapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="com.mydomain.myapp.MyApplication"
android:allowBackup="false"
tools:replace="allowBackup"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.mydomain.myapp.ui.MainActivity"
android:exported="true">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
</application>
</manifest>
My build.gradle(:app) file:
android {
compileSdkVersion("android-S")
buildToolsVersion "30.0.3"
defaultConfig {
...
minSdkVersion 23
targetSdkVersion("S")
...
}
Any idea how I could resolve this issue?
The issue was caused by 3 activities missing the android:exported attribute in the androidx.test:core library version 1.3.0. Upgrading to version 1.4.0-beta01 fixed the issue.
If you are getting errors after targeting Android 12, the easiest way to debug this is to:
downgrade to a prior sdk version
rebuild project
after a successful build, open your project's AndroidManifest.xml.
at the bottom of the window, click on the Merged Manifest tab
look for any <activity> that includes an <intent-filter> tag and is missing the android:exported attribute
If you want to make sure these activities are the issue, add them directly to your project's AndroidManifest.xml file with the missing android:exported attribute added and try rebuilding the project.
So if <activity android:name="com.domain.ProblemActivity"> is missing the android:exported attribute, add it to your AndroidManifest.xml file like so:
<activity
android:name="com.domain.ProblemActivity"
android:exported="true" >
Rebuild targeting Android 12 and if it works, then you found the bug!
Thanks #MikePenz for pointing me in the right direction.
If your app targets Android 12 or higher and contains activities, services, or broadcast receivers that use intent filters, you must explicitly declare the android:exported attribute for these app components. In order to solve this we need to follow these steps:
We need to locate the AndroidManifest.xml in the main folder.
android>app>src>main>AndroidManifest.xml
We have to add android:exported="" and set a boolean value inside these quotation marks. Now you might ask when do I need to add android:exported="true" or android:exported="false" to the activities, services, or broadcast receivers that use intent filters.
If the app component includes the LAUNCHER category, set android:exported to true. In most other cases, set android:exported to false.
This is an example of how it should look like in your AndroidManifest.xml
<service android:name="com.example.app.backgroundService"
android:exported="false">
<intent-filter>
<action android:name="com.example.app.START_BACKGROUND" />
</intent-filter>
</service>
You can check out more info about this topic by following this link:
Safer component exporting for Android 12
If you upgrade your android studio to Bumblebee 2021.1.1.
The below changes are required to do:
Step 1: Your targetSdkVersion must be 30 or higher
Step 2: Update your appcompat library to implementation 'androidx.appcompat:appcompat:1.4.1'
Step 3: In the AndroidManifest file add android:exported = true to your activity launcher.
I had this issue, find it by:
if there's any activity, service, receiver, or provider that does not have exported attribute in your AndroidManifest file then add the below attribute in that activity, service, receiver, or provider
android:exported="false or true"
I had my Activity setup correctly with 'exported=true' and still had the following issue:
Installation failed due to [...] androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present
So I came across this Github post, which could explain why this happens, and applied the workaround yogurtearl suggests and it worked for me.
https://github.com/android/android-test/issues/832
It basically goes like this:
As a workaround, putting this in the app/src/debug/AndroidManifest.xml it will force the these to launch in the same test process.
<activity
android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity"
android:exported="true"
android:theme="#android:style/Theme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
android:exported="true"
android:theme="#android:style/Theme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
android:exported="true"
android:theme="#android:style/Theme.Dialog" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
And added the 'exported=true' to them.
Don't forget to put it also into service tag
<service
android:name=".service.MyIME"
android:exported="true"
android:permission="android.permission.BIND_INPUT_METHOD">
<meta-data
android:name="android.view.im"
android:resource="#xml/method" />
<intent-filter>
<action android:name="android.view.InputMethod" />
</intent-filter>
</service>
Cleaning and rebuilding the project worked for me
If you're using DexGuard you should update to the latest version which is 9.2.11 (19-01-2022) at the moment.
Quote from the release notes:
Add default configuration for keeping the exported attribute as required by applications targeting Android 12.
As specified in the following link-
https://developer.android.com/about/versions/12/behavior-changes-12#exported ,the components of android that use intent filters must explicitly define component exporting, failing to which your app can't be installed on a device that runs on Android 12 or higher. The app components include activities, services, broadcast receivers and content providers.
If the app component includes the LAUNCHER category, set android:exported to true. In most other cases, set android:exported to false.
Even after setting the android:exported tag, if you are facing the Manifest Merger failed issue, then check all the libraries that you are using in your app. Open the external libraries in the project view of the Android Studio and try to check all the manifests files of the libraries that you have included in your project. Any one of those libraries might have not updated according to Android 12. So if you find any manifest file of the library with exported tag missing, try to edit the file and add this tag there too. Hope that could help in removing Manifest Merger Error.

How to override flutter apk manifest?

I am working on updating Android Manifest configurations on my Flutter project. However, there is one recommended fix that I could not find in the libraries I have used in flutter. But upon analyzing the APK, I found it in the AndroidManifest.xml in the APK via APK Analyzer
Shown above is the config I have to update. A very simple update where I have to replace android:exported to false.
I need help in figuring out a way to actually update this manifest since I do not see any file even after looking through each manifest files of the packages I've included in my project that contains the code/config shown above.
Add this in manifest
<application
tools:replace="android:label"
android:name="io.flutter.app.FlutterApplication"
android:label="flutterwp"
android:icon="#mipmap/ic_launcher">
You can simply edit this AndroidManifest.xml file.
Use tools:replace attr.
Checkout following example from official docs:
In library
<activity android:name="com.example.ActivityOne"
android:theme="#oldtheme"
android:exported="false"
android:windowSoftInputMode="stateUnchanged" />
Your own implementation
<activity android:name="com.example.ActivityOne"
android:theme="#newtheme"
android:exported="true"
android:screenOrientation="portrait"
tools:replace="android:theme,android:exported"

Creating activity-alias for build variants using gradle

I recently merged 4 similar but independent apps into one gradle project and setup gradle to use build variants for deploying each one independently. Because I've merged these projects that were previously independed, I needed to rename some packages, including the package for the launcher activity. In order to preserve the launcher links for my current user base, I wanted to use an activity-alias to point the old launcher links to the new launcher activity. So far so good.
However, since I have multiple build variants, I need several different aliases to link back to the new launch activity. I looked into gradle's new manifest merging solution and looked into using placeholders for the alias name, however, when I drop the placeholder under the alias, it refuses to acknowledge the right package. The app will crash with
Starting: Intent { act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER]
cmp=com.stuart.android.flavor1/${packageName}.NewLauncherActivity }
Error type 3
Error: Activity class {com.stuart.android.flavor1/${packageName}.NewLauncherActivity} does not exist.
Below is the activity-alias from my manifest and the gradle build file. I need to find a way to insert the package name for each build variant into the alias for each build I do. com.stuart.android.main is the common package among all flavors and is the location of the new launch activity. I'm using Android Studio 0.6.1 with the 0.11 Gradle plugin. Any help is appreciated!
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.stuart.android.main"
android:installLocation="auto">
<application android:icon="#drawable/icon" android:label="#string/app_name" android:allowBackup="true" android:theme="#style/appTheme">
<activity android:name=".NewLauncherActivity" android:label="#string/app_name_full"/>
<activity-alias
android:name="${packageName}.OldLauncherActivity"
android:targetActivity="com.stuart.android.main.NewLauncherActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
</application>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19"/>
</manifest>
build.gradle
productFlavors {
flavor1 {
packageName "com.stuart.android.flavor1"
}
flavor2 {
packageName "com.stuart.android.flavor1"
}
flavor3 {
packageName "com.stuart.android.flavor1"
}
flavor4 {
packageName "com.stuart.android.flavor1"
}
}
As You use Gradle to set the "packageName" (or "applicationId"), You may try
android:name="com.stuart.android.main.NewLauncherActivity"
instead of
android:name=".NewLauncherActivity"
in line 7 of Your Manifest

Remove LoginActivity from Manifest - Facebook SDK for Android 3.0

I notice that Facebook SDK 3.0 has to have the LoginActivity declaration in Manifest file.
<activity android:name="com.facebook.LoginActivity"
android:label="#string/app_name" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/applicationId" />
If it's not there, the below exception is thrown.
com.facebook.FacebookException: Cannot use SessionLoginBehavior SSO_WITH_FALLBACK when com.facebook.LoginActivity is not declared as an activity in AndroidManifest.xml
It seems a bad practice when Facebook SDK has to depend on this declaration. I wonder if there is a way to remove it from Manifest file.
About the applicationId missing, I can pass it in code by modifying some functions, LoginButton constructor and Session constructor.
When using the official build stack, you need to reference every Activity (that needs to be started) in your manifest. This is indeed counter-intuitive, since one would expect such things to be inherited from included libraries.
A process known as "manifest merging" is right now possible with the Maven build stack and with the new build system. Since the new build system is still work-in-progress, you just have to wait until it is being rolled out officially.
As the error suggests put the declaration as follow in your manifest:
<activity android:name="com.facebook.LoginActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:label="#string/app_name" />

Categories

Resources