简体   繁体   中英

Cordova Android not adding all xml from Custom URL Scheme plugin to AndroidManifest when rebuilding app

I added the plugin https://github.com/EddyVerbruggen/Custom-URL-scheme to my cordova project.

The plugin has this in the plugin.xml file for Android:

<config-file target="AndroidManifest.xml" parent="/manifest/application/activity">
  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="$URL_SCHEME"/>
  </intent-filter>
  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="$ANDROID_SCHEME"
          android:host="$ANDROID_HOST"
          android:pathPrefix="$ANDROID_PATHPREFIX" />
  </intent-filter>
</config-file>

When installing the plugin I provide the value for the CUSTOM_URL variable:

cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME=appscheme

Then I run the app in emulator with cordova run android --emulator. The Android Manifest is generated correctly including both intent filter blocks:

  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="appscheme"/>
  </intent-filter>
  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme=" " android:host=" " android:pathPrefix="/" />
  </intent-filter>

And things work as expected.

But if I then make any change to my project, and rebuild the app by running cordova run android again, then one of the intent filter blocks is missing from the Android Manifest file, and the plugin functionality doesn't work.

  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme=" " android:host=" " android:pathPrefix="/" />
  </intent-filter>

I need to remove the plugin, and then add it back, for the AndroidManifest.xml to be generated correctly.

Any idea why it would remove one of the intent-filter blocks when rebuilding?

Thanks for any help!

I found a solution after reading the first comment to the accepted solution at this post: Cordova Change AndroidManifest using Config.xml file

I needed to remove an this from my config.xml file:

    <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application/activity[@android:name='MainActivity']">
        <activity android:theme="@style/Full" />
    </edit-config>

and instead use the cordova-custom-config plugin in the project and this in config.xml:

<custom-preference name="android-manifest/application/activity/@android:theme" value="@style/Full" />

Now everything is making it to the AndroidManifest.xml file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM