It seems PhoneGap generates that file automatically when config.xml is modified.
I wish to add Ad network's activities, services, etc in AndroidManifest.xml but I can't find the correct way to edit that file.
Phonegap uses config.xml to create androidmanifest.xml when you add the android platform to a project.
It is also modified when you add plugins and build the project (for example, it adds the required permission for the plugin).
But you can also manually edit the file in platforms/android/AndroidManifest.xml to add permissions, configure the activity or the application... it will not be lost when you rebuild your project.
Typically this is found in the "res" directory ( - src - gen [Generated Java Files] - Android - Android Dependencies - Referenced Libraries - assets - bin - libs - res - AndroidManifest.xml - proguard-project.txt - project.properties) of course this is depending on what version of Cordova you are using. Typically most of these things are specified in the config.xml for newer Phonegap builds from my understanding which is why you don't need to include an AndroidManifest.xml file when using Phonegap Build. I would recommend trying Configap to edit the main config.xml and see if any of the settings/services you need to access are options. Configap can be found here!
forgot to mention I use Notepad++ to edit my .xml on the fly but you can also open in the sdk
You probably want to check out cordova-custom-config.
It supports many extra settings in the cordova config.xml to customise the AndroidManifest.xml.
I'm using it to change the android:configChanges setting (adding uiMode to stop it from reloading when docking/undocking) and it works great.
The cordova-custom-config github page shows a full example with all supported options so it's very easy to setup.
Nowadays in Cordova, we can use <config-file> and <edit-config> in our config.xml to make simple custom changes to AndroidManifest.xml.
Examples copied from the docs:
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:name="com.foo.Foo" android:label="#string/app_name">
<intent-filter>
</intent-filter>
</activity>
</config-file>
<edit-config file="AndroidManifest.xml" target="/manifest/uses-sdk" mode="merge">
<uses-sdk android:minSdkVersion="16" android:maxSdkVersion="23" />
</edit-config>
<edit-config file="AndroidManifest.xml" target="/manifest/application/activity[#android:name='MainActivity']" mode="overwrite">
<activity android:name="MainActivity" android:label="NewLabel" android:configChanges="orientation|keyboardHidden" />
</edit-config>
Note: to use the android: namespace in your config.xml, you need to add xmlns:android="http://schemas.android.com/apk/res/android" to the root <widget> element.
Related
I am creating a card reader integration that uses and Android Service for part of the integration. The standard Android implementation includes an android service definition in the AndroidManifest.xml
<service
android:name="com.anywherecommerce.android.sdk.services.CardReaderConnectionService"
android:stopWithTask="false" />
https://github.com/dazza5000/any-pay-android-sample/blob/4f7ca7af79f2494e3ec408b025446be6020c0aa4/src/main/AndroidManifest.xml#L43-L45
How do I define that in a Flutter Plugin so that the service definition will be added to the AndroidManifest of the app that uses it? Do I just include it as part of the library and leave it up to the user to register the service in their app AndroidManifest.xml?
Haven't tried this with a service, but creating a skeleton manifest in the plugin's folders does seem to merge the skeleton into the app's manifest at build time.
For example, with the following skeleton, the application meta-data definition is merged fine.:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.plugin.restrictions_manager">
<application>
<meta-data android:name="android.content.APP_RESTRICTIONS"
android:resource="#xml/app_restrictions" />
</application>
</manifest>
[Edit]
This approach does indeed work with a service declaration. And to see the merged AndroidManifest.xml, look in my_plugin/build/app/outputs/apk/debug/app-debug.apk, which can be browsed in Android Studio.
I was unable to determine how to include a service definition in a Flutter plugin that would be added to the plugin consuming app.
What I had to do was add the service definition in the AndroidManifest.xml file of the plugin consuming app.
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"
A have installed my Ionic application on real device. The app is released, signed and has android:debuggable="false".
I faced some problems on that specific device and I need to debug it (not to create and install new --debug build).
Is there some way to debug it? To "attach" it somehow to a keystore to be authorised, or something else...? Any ideas?
I am still trying to find a better way, but so far I am able to debug my Ionic app (a signed --release build) running on a real device via the Chrome (desktop) console, by specifying:
<application android:debuggable="true">
directly in the AndroidManifest.xml file. The attribute in not overwritten when I build the project with the Ionic CLI.
What I would prefer is to set the attribute from the config.xml file, so I don't have to add it again manually in AndroidManifest.xml when I remove/add the platform.
You can add this in your config.xml to solve it.
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:debuggable="true" />
</edit-config>
Then, you can debug in Chrome.
I've just faced a similar issue (I wanted to create a debuggable Cordova app with cordova build android --release) and I've also wanted to add something to the Cordova config.xml instead of directly editing AndroidManifest.xml, which is generally a bad idea.
The following piece of code worked for me on Cordova 8.1.2, Cordova Android platform version 7.1.4. Just put this inside your config.xml file (somewhere inside the widget tag) and you should be good to go:
<config-file mode="merge" parent="/manifest" platform="android" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:debuggable="true" />
</config-file>
This will also cause the :app:lintVitalRelease linter to give you a [HardcodedDebugMode] error (and for good reason), but the APK will build fine regardless.
I'm trying to create bindings for Zendesk library and I faced with a problem.
Zendesk Belvedere library (belvedere-1.0.2.1.aar) contains a file provider in its manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
...
<application>
<provider
android:name="com.zendesk.belvedere.BelvedereFileProvider"
android:authorities="${applicationId}.belvedere.attachments"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/belvedere_attachment_storage" />
</provider>
</application>
</manifest>
When Gradle is used as build tool, it puts this aar to the APK file and it replaces ${applicationId}.belvedere.attachments with com.your_package_name_here.belvedere.attachments in the merged manifest file. It's fine.
However, Xamarin handles it differently. Here is what I found in the manifest of my final APK:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
...
<application
...
...
<provider
android:name="com.zendesk.belvedere.BelvedereFileProvider"
android:exported="false"
android:authorities="dollar_openBracket_applicationId_closeBracket"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/belvedere_attachment_storage" />
</provider>
...
...
</application>
</manifest>
Obviously, dollar_openBracket_applicationId_closeBracket is not what I need.
Seems everything works, however it makes impossible to install several Xamarin applications that use these bindings, because all of them would have conflicting providers with the same authority (and user would get INSTALL_FAILED_CONFLICTING_PROVIDER error).
Is there a way to change dollar_openBracket_applicationId_closeBracket in the manifest?
Edit: A small sample that shows the problem: https://gitlab.com/lassana/ZendeskXamarin/
The current Xamarin.Android manifest merge build task, up to and including
version 7.1.0.19, does not provide any bundeID/ApplicationID (${}} substitution in the merged manifest like gradle does.
This is just a limitation in the manifest processing/merge task, thus you are ending up with dollar_openBracket_applicationId_closeBracket in your final manifest and will have to correct both manifests yourself.
The only current solution know to me to avoid the manifest merge task and it's limitation is to:
Remove the file provider entry from the '.aar`'s manifest
Add the complete file provider entry your app's manifest
Note: You have to do both steps
Depending upon how often the .aar is changing and where you are sourcing the .aar file from:
Manually unzip the aar, remove the entry and re-zip the aar (the quickest way)
Automated this in a build step via a shell script using bash or powershell cmds
Write a MSBuild C#-based Task to do it.
Request that the aar manifest be changed upstream (not likely to happen ;-) since it works fine w/ gradle)
FYI: Personally I have seen the ${applicationId} issue you are having a few times. I have written build scripts (bash/.ps1) to do the manifest fix-up as it seems to always be some special case in the .arr's manifest that I am dealing with.
According to Microsoft team, Xamarin.Build.Download (0.4.12-preview) finally fixes this bug.
So, you should follow these steps:
Update the Nuget Package to 0.4.12-preview3
Restart the IDE
Delete all cached locations of NuGet Packages
Delete bin/obj
Rebuild
The main manifest file of your project is the higher priority manifest, so if you add the provider element to main manifest file and apply a merge rule marker for android:authorities attribute, the merger tools replaces the android:authorities value that you declare in the main manifest.
Declare provider element in main manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
...
...
<application>
<provider
android:name="com.zendesk.belvedere.BelvedereFileProvider"
android:authorities="com.example.belvedere.attachments"
tools:replace=”android:authorities” >
</provider>
</application>
I'd like to set androids permissions to use geolocation in config.xml.
I don't want to use cordova-plugin-geolocation which would set these settings as a side-effect because the webviews I am targeting (crosswalk) support GeoLocation out of the box. The Plugin would just be bloatware.
I don't want to write it directly in AndroidManifest.xml because I am using cordova prepare to prevent having any plattform-specific stuff inside my repository. Everybody is currently able to build the plattforms from scratch without any plattform-specific stuff from our git-repo.
What I tried
I took a look at cordova-plugin-geolocation to see how they would achieve this.
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
</config-file>
</platform>
This returns the following in my build-phase
Error: Command failed: /bin/sh -c cordova build android
/Users/sven/.../cordova/platforms/android/build/intermediates/res/armv7/debug/xml/config.xml:34: error: Error parsing XML: unbound prefix
What my next step would be
I am unsure about why the 'rob-from-cordova-plugin-geolocation'-approach does not work, but maybe it would help to just put above into a new plugin? Is it worth a try?
Your error is "unbound prefix", have you provided a definition for the "android" prefix that you're using in "android:name"?
Looking at cordova-plugin-geolocation plugin.xml you may need to add this to your XML:
xmlns:android="http://schemas.android.com/apk/res/android"
So that the android namespace is defined.
You will be able to add permissions (and many other extra configuration actions) in Cordova straight from CLI's config.xml by adding the plugin cordova-custom-config to your environment. It will add nothing in your application and consists only in a group of Cordova hooks.
So, only add the XML chuck in your config.xml (<config-file...), and also add what #SimonPrickett say in his answer.