What does the ${applicationName} in flutter AndroidManifest.xml means? - android

The AndroidManifext.xml has this code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.skeleton">
<application
android:label="skeleton"
android:name="${applicationName}"
android:icon="#mipmap/ic_launcher">
On what real value the applicationName is interpolated?

This value is set by the Flutter Gradle plugin.
It can have 2 value :
If you have multidex enabled and your app has a minSdk less than 20, this value will be io.flutter.app.FlutterMultiDexApplication.
Else, it will be android.app.Application.
You can override this value by setting the base-application-name property (in the gradle.properties of your android folder for example).
Source : https://github.com/flutter/flutter/blob/master/packages/flutter_tools/gradle/flutter.gradle#L261
Remember that you can always inspect the resulting APK (in build/app/outputs/flutter-apk) to see what value is in the final Manifest. Or you can just read the merged manifest in build/app/intermediates/merged_manifests/debug/AndroidManifest.xml.

Related

Where is ${applicationName}? [duplicate]

The AndroidManifext.xml has this code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.skeleton">
<application
android:label="skeleton"
android:name="${applicationName}"
android:icon="#mipmap/ic_launcher">
On what real value the applicationName is interpolated?
This value is set by the Flutter Gradle plugin.
It can have 2 value :
If you have multidex enabled and your app has a minSdk less than 20, this value will be io.flutter.app.FlutterMultiDexApplication.
Else, it will be android.app.Application.
You can override this value by setting the base-application-name property (in the gradle.properties of your android folder for example).
Source : https://github.com/flutter/flutter/blob/master/packages/flutter_tools/gradle/flutter.gradle#L261
Remember that you can always inspect the resulting APK (in build/app/outputs/flutter-apk) to see what value is in the final Manifest. Or you can just read the merged manifest in build/app/intermediates/merged_manifests/debug/AndroidManifest.xml.

React Native: Error: Package name not found

After integrating RN into an existing Android project, I get the following error:
Error: Package name not found in /home/.../AndroidManifest.xml at Object.projectConfig (/home/.../rn_integrated_app/node_modules/#react-native-community/cli-platform-android/build/config/index.js:74:11) at Object.get project [as project]
As I understand the problem is that there is no package attribute in the relevant AndroidManifest.xml file. Since my project has many flavors, the package attribute is added dynamically, while compiling, through app/build.gradle:
def pkgDataEntry = getRightValue(packagesData, variantMap)
variant.getMergedFlavor().applicationId = pkgDataEntry.pkg
So that the final merged manifest file does have the package attribute.
The error occurs here(#react-native-community/cli-platform-android/build/config/index.js):
const packageName = userConfig.packageName || getPackageName(manifest);
if (!packageName) {
throw new Error(`Package name not found in ${manifestPath}`);
}
Is there a way to make RN read the merged manifest file?
If not, how can I modify userConfig to contain the package name? I couldn`t find anything about it in the docs.
Thank you
For me, the solution was to add the "package" tag to the manifest tag.
I didn't have to create another dummy folder.
The manifest open tag now looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourProjectName">
If anybody encounters the same issue, when having multiple flavors and AndroidManifest.xml files,here`s my conclusion:
RN has some kind of a bug that it requires the first folder alphabetically, in android/app/src, which has AndroidManifest.xml file,to have the package attribute. Otherwise, it will throw an error.
A simple solution would be to create a dummy folder, e.g aaa (first alphabetically) and to create AndroidManifest.xml inside of it, with the following attribute - package:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="aaa"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission
android:name="android.permission.GET_ACCOUNTS"
tools:node="remove"/>
</manifest>
For me, this error start after upgrade the sdkVersion from 31 to 33 and gradle version.
I did check the changes in git, and notice that the package attribute was removed from AndroidManifest.xml.
So I did add this attribute again.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.yourpackage">

Android Studio debug/android manifest doesn't change & giving error

I worked on a android project all day today. Now I am trying to load a project into android studio. It gives me error on > debug/android manifest
even though I corrected the error . It keeps repeating the same error on same place. It looks like coding doesn't change
Error:(45) Tag attribute authorities has invalid character '#'.
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider#string/facebook_app_id"
android:exported="true" />
It automatically inserted between permissions on debug/android manifest. original manifest file has no error nor any unnecessary coding between permissions
In Android Studio, try File -> Invalidate Cache and Restart.
I'd similar problem where changes in res/AndroidManifest.xml were not being reflected in debug\AndroidManifest.xml and above step did the trick for me.
Did you checked sample project on facebook-android-sdk repo?
https://github.com/facebook/facebook-android-sdk/blob/master/samples/RPSSample/AndroidManifest.xml
Here
<provider android:authorities="com.facebook.app.FacebookContentProvider157578437735213"
android:name="com.facebook.FacebookContentProvider"
android:exported="true" />
app_id is entered as hard-coded instead of string parameter. You can try this or ensure that you have "facebook_app_id" parameters in strings.xml.
It's failing because you're accessing an #string reference in the middle of the value of the authorities attribute, and references need to appear by themselves to be interpreted correctly. There are a couple approaches around this.
First, you can hardcode the facebook app id by appending it to the end of FacebookContentProvider like so (assume 22222222 is the facebook app id):
<provider android:authorities="com.facebook.app.FacebookContentProvider22222222"
android:name="com.facebook.FacebookContentProvider"
android:exported="true" />
But this is not ideal if you have different facebook app ids (for example, one for development, one for staging, and one for production). To set the authorities attribute dynamically, you first need to set the specific values in your build.gradle file:
...
buildTypes {
release {
resValue "string", "facebook_content_provider_app_id", "\"com.facebook.app.FacebookContentProvider55555555555\""
}
debug {
resValue "string", "facebook_content_provider_app_id", "\"com.facebook.app.FacebookContentProvider22222222222\""
}
}
Once you have that in place, you can reference the facebook app id regardless of the build type dynamically in the AndroidManifest.xml:
<provider android:authorities="#string/facebook_content_provider_app_id"
android:name="com.facebook.FacebookContentProvider"
android:exported="true" />

Is it possible to mock locations for release build type

I'd like to mock locations in release build type of Android app. I've created a special flavour "mockable" manifest in app/src/mockable/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
</manifest>
But it seems that Android lint blocks from using this permissions in release build type. For command:
./gradlew assembleRelease
I got output:
:app:lintVitalMockableRelease
/home/fr/app/src/mockable/AndroidManifest.xml:3: Error: Mock locations should only be requested in a debug-specific manifest file (typically src/debug/AndroidManifest.xml) [MockLocation]
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Explanation for issues of type "MockLocation":
Using a mock location provider (by requiring the permission
android.permission.ACCESS_MOCK_LOCATION) should only be done in debug
builds. In Gradle projects, that means you should only request this
permission in a debug source set specific manifest file.
To fix this, create a new manifest file in the debug folder and move the
<uses-permission> element there. A typical path to a debug manifest
override file in a Gradle project is src/debug/AndroidManifest.xml.
1 errors, 0 warnings
Is it possible to generate release app with location mocking permission?
Disable the MockLocation lint check for that particular permission, i.e.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission
android:name="android.permission.ACCESS_MOCK_LOCATION"
tools:ignore="MockLocation" />
</manifest>
(Refer to http://tools.android.com/tips/lint-checks)
The only solution I know for sure is to let lint report errors but don't let that abort the build process:
To enable that just add
lintOptions {
abortOnError false
}
inside the android block.
You will still get lint errors and warnings but the build will continue.
I am not sure if you can put that inside the flavor definition or use a custom buildType for that. I have no project where I could test that.
This is a caution. If you want a user to "mock location" then the user must enable mock locations in Android.
A production release is definitely possible, I have done this. You need to prompt the user to allow for "Mock Locations" like a developer/debug would.

Android Studio 6.0 merger fail

Just updated to the latest version of Android Studio and i get this error in the AndroidManifest file
Manifest merger failed : Attribute application#icon value=(#drawable/project_launcher_icon) from AndroidManifest.xml:48:9
is also present at com.github.anupcowkur:reservoir:1.1.1:6:45 value=(#drawable/ic_launcher)
Suggestion: add 'tools:replace="icon"' to element at AndroidManifest.xml:44:5 to override
I tried adding tools:replace="#drawable/ic_drawer" in my manifest but i get this error:
Error:(44, 5) tools:replace specified at line:44 for attribute tools:drawable/ic_drawer, but no new value specified
Any ideas?
Following Android Studio's suggestion and adding the following attribute tools:replace="icon" should allow it to build your app successfully, without resorting to using the old manifest merger (which isn't a very forward-looking solution indeed).
Of course, you'll first have to declare the namespace "tools" in order to use it:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.sample.app" >
You should add tools:replace="icon", just like the error message says.
Additional attributes can be replaced using the syntax tools:replace="icon,name,theme"
look here:
All markers belong to the Android tools namespace, therefore you must declare the namespace in any AndroidManifest.xml containing at least one marker :
xmlns:tools="http://schemas.android.com/tools"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.tests.flavorlib.app"
**xmlns:tools="http://schemas.android.com/tools"**>
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
**tools:replace=”icon, label”**/>
</manifest>
you should add xlms:tools and tools:replace those two lines in manifest file.
Android Studio 0.6 use the new manifest merger tool. This new merger was introduced in version 0.10 of the plugin. As of 0.11, this tool is used by default by the gradle plugin.
In order to revert to the old manifest merger, please add to your build.gradle the following configuration :
android {
useOldManifestMerger true
}
For me this worked. Try adding the code in the main module(project) manifest file:
add
xmlns:tools="http://schemas.android.com/tools" in your manifest tag
add
tools:replace="android:icon,android:label,android:theme" in your application tag
These will let Android Studio know that the icon, label and theme to be used are from that manifest and not from other projects included.

Categories

Resources