Open breautek opened 4 years ago
I believe we should remove this from documentation.
We don't set the uses-sdk
setting anymore and try to keep everything inside the Gradle.
If you try and set the minSDK, like the example you wrote above, Android Studio will complain:
The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file. Move minSdkVersion to build file and sync project Affected Modules: app
I think the other settings does not get these sync warnings but managing the settings in Gradle and in the Manifest was maybe a bit excessive maybe? So I believe it was decided to do only Gradle.
Yah, the documentation could have been removed.
But <uses-sdk>
tag itself isn't deprecated and there is still some potential use cases for it. Such as overriding libraries via tools:overrideLibrary attribute. Which may be necessary depending libraries being imported into the android project.
@breautek facing similar issue
Unable to graft xml at selector "/manifest/application/activity[@android:theme='@style/Theme.AppCompat.NoActionBar']" from "/Users/bhuminbhandari/Desktop/projects/app/platforms/android/app/src/main/AndroidManifest.xml" during config install
First time works but second time when we run cordova build android
it will show above error.
Script
<edit-config mode="merge or try overwrite" file="app/src/main/AndroidManifest.xml" target="/manifest/application/activity[@android:theme='@style/Theme.AppCompat.NoActionBar']" >
<activity android:theme="@style/RemoveSystemSplashScreen"></activity>
</edit-config>
Have similar issue 11:52:55 Android project created with cordova-android@12.0.0 11:52:55 Unable to graft xml at selector "/manifest/uses-permission[@android:name='android.permission.WRITE_EXTERNAL_STORAGE']" from "/private/var/folders/wv/d7j3q171735794lxc610xqy80000gp/T/tmp.gO8bxWCU/mobile/cordova/platforms/android/app/src/main/AndroidManifest.xml" during config install
XML code:
`
</edit-config>`
@VeaceslavB this could be off topic but by any chance, does this happens to you because of the last release of cordova-plugin-camera ? In my case I just upgraded to 7.0.0 which requires this permission with android:maxSdkVersion
attribut set, while other plugins within my project require the permission as is without any attributes. This seems to cause conflicts in the AndroidManifest.xml
To resolve the issue and workaround edit-config, you could write a custom hook to manually modify the file and resolve those conflicts
Faced similar issue recently. Made the following update in my config.xml
several months ago:
<!-- add required XML namespace -->
<edit-config file="app/src/main/AndroidManifest.xml" target="/manifest" mode="merge">
<manifest xmlns:tools="http://schemas.android.com/tools"/>
</edit-config>
<!-- add replace attr for permission tag -->
<edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/uses-permission[@android:maxSdkVersion='32']" mode="merge">
<uses-permission tools:replace="android:maxSdkVersion"/>
</edit-config>
Also I have the following string replacement in Android after_prepare
hook (as a workaround recommended in this comment):
manifest = manifest.replace(/^(\s)+<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" \/>$/gm, '');
For some time it worked well. Yesterday I've updated my Android SDK, Build Tools and Command-line Tools to latest, and received Unable to graft xml at selector "/manifest/uses-permission[@android:maxSdkVersion='32']" from "/Users/.../platforms/android/app/src/main/AndroidManifest.xml" during config install
while executing cordova prepare android
.
Rolling back Android-related staff didn't help.
Adding update to my previous comment.
Since I first faced this issue, I did several updates (macOS, Node.js, Cordova, cordova-android, etc.) Not sure what helped, but now I sometimes don't see Unable to graft xml at selector
error. <edit-config>
in config.xml
works as expected. I've noted that removing platforms
and plugins
folders (not platforms
or platforms/android
only) leads to correct generation of Android project. Otherwise error may occure again.
Here is my setup (partial cordova info
output).
Cordova Packages:
cli: 12.0.0
common: 5.0.0
create: 5.0.0
lib: 12.0.2
common: 5.0.0
fetch: 4.0.0
serve: 4.0.1
Project Installed Platforms:
android: 13.0.0
Environment:
OS: macOS Sequoia 15.0.1 (24A348) (darwin 24.0.0) x64
Node: v18.17.0
npm: 9.6.7
Bug Report
Problem
What is expected to happen?
<edit-config>
to apply changes toAndroidManifest.xml
What does actually happen?
An error occurs and the build fails.
Information
Error stacktrace:
Command or Code
Use
cordova create
to build a simple hello world project.Inside the
config.xml
add:This is a copied and paste example from the docs. But this appears to occur when having
target="/manifest/uses-sdk"
, regardless of the body of<edit-config>
block. This also fails ifmode="merge"
is set.Do note that the following does not fail:
This leads me to believe perhaps this occurs if the
AndroidManifest.xml
does not have the target node.Finally run:
cordova build android
to observe the failure.Environment, Platform, Device
Windows 10 Cordova-Android 9
Version information
Windows 10 cordova: 9.0.0 (cordova-lib@9.0.1)
Checklist