dpa99c / cordova-custom-config

Cordova/Phonegap plugin to update platform configuration files based on preferences and config-file data defined in config.xml
318 stars 84 forks source link

Ionic - The prefix "tools" for attribute "tools:node" associated with an element type "uses-permission" is not bound. #178

Closed fbertini closed 1 year ago

fbertini commented 1 year ago

Bug report

Current behavior:

I am using ionic cordova plugin + cordova-custom-config. Below you can find the part of the config.xml that is producing the error:

<?xml version='1.0' encoding='utf-8'?>
<widget id="my.id" version="1.0.0" 
    xmlns="http://www.w3.org/ns/widgets" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:cdv="http://cordova.apache.org/ns/1.0" 
    xmlns:tools="http://schemas.android.com/tools">
    <!-- [...] -->
    <preference name="ScrollEnabled" value="false" />
    <preference name="android-minSdkVersion" value="22" />
    <preference name="android-targetSdkVersion" value="33" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="FadeSplashScreenDuration" value="300" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="3000" />
    <platform name="android">
        <custom-config-file parent="/*" target="AndroidManifest.xml">
            <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
            <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove" />
        </custom-config-file>
        <custom-preference name="android-manifest/application/@android:hardwareAccelerated" value="true" />
        <custom-preference name="android-manifest/application/@android:icon" value="@mipmap/ic_launcher" />
        <custom-preference name="android-manifest/application/@android:label" value="@string/app_name" />
        <custom-preference name="android-manifest/application/@android:supportsRtl" value="true" />
        <custom-preference name="android-manifest/application/activity/@android:configChanges" value="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" />
        <custom-preference name="android-manifest/application/activity/@android:exported" value="true" />
        <custom-preference name="android-manifest/application/activity/@android:label" value="@string/activity_name" />
        <custom-preference name="android-manifest/application/activity[@android:name='MainActivity']/@android:launchMode" value="singleTop" />
        <custom-preference name="android-manifest/application/activity/@android:theme" value="@style/Theme.AppCompat.Light" />
        <custom-preference name="android-manifest/application/activity/@android:windowSoftInputMode" value="adjustResize" />
        <!-- [...] -->
    </platform>
    <plugin name="cordova-plugin-device" spec="~2.0.2" />
    <plugin name="cordova-plugin-splashscreen" spec="~5.0.2" />
    <plugin name="cordova-plugin-ionic-webview" spec="~1.1.19" />
    <plugin name="cordova-plugin-ionic-keyboard" spec="~2.0.5" />
    <plugin name="cordova-plugin-inappbrowser" spec="~3.0.0" />
</widget>

Running the following command produce an unwanted result: ionic cordova build android --prod --release --aot

Expected behavior: The following XML is expected:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" 
    android:versionCode="1000" 
    android:versionName="1.0.0" 
    package="my.id" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.AppCompat.Light" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

Steps to reproduce:

  1. load config.xml as above
  2. run ionic cordova platform add android
  3. run ionic cordova build android --prod --release --aot

Screenshots N/A

Environment information

Android build issue:

Related code: N/A

Console output

console output ```text Subproject Path: CordovaLib Subproject Path: app > Task :app:createReleaseCompatibleScreenManifests FAILED FAILURE: Build failed with an exception. Execution failed for task ':app:createReleaseCompatibleScreenManifests'. > Error while evaluating property 'variantOutputs.$0.versionName' of task ':app:createReleaseCompatibleScreenManifests' > org.xml.sax.SAXParseException; systemId: file:/C:/Users/user/Documents/workspaces/myapp/myapp-app/platforms/android/app/src/main/AndroidManifest.xml; lineNumber: 13; columnNumber: 99; The prefix "tools" for attribute "tools:node" associated with an element type "uses-permission" is not bound. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec:command_line_warnings BUILD FAILED in 1s 8 actionable tasks: 3 executed, 5 up-to-date Command failed with exit code 1: C:\Users\user\Documents\workspaces\myapp\myapp-app\platforms\android\gradlew :app:bundleRelease -b C:\Users\user\Documents\workspaces\myapp\myapp-app\platforms\android\build.gradle [ERROR] An error occurred while running subprocess cordova. ```


**Other information:** N/A
fbertini commented 1 year ago

Hello,

I have found a solution for this issue. It was my mistake and I would suggest to add this to the documentation if missing. Basically we need to add xmlns:tools to the manifest section of AndroidManifest.xml via config.xml configuration.

Adding the following XML code within the <platform name="android"> section, solved the issue:

<custom-preference name="android-manifest/@xmlns:tools" value="http://schemas.android.com/tools" />

This issue can be closed. Thank you.