cordova-common icon indicating copy to clipboard operation
cordova-common copied to clipboard

Config changes not properly applied if paths differ but resolve to same file

Open Lindsay-Needs-Sleep opened this issue 6 years ago • 5 comments

Bug Report

Problem

config-file and edit-config options in config.xml do not work properly.

I am trying to make 3 modifications to AndroidManifest.xml:

  • Add WAKE_LOCK permission (and add uses-feature for touchscreen)
<config-file parent="/manifest" target="AndroidManifest.xml">
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-feature android:name="android.hardware.touchscreen" android:required="true" />
</config-file>
  • Modify activity tag's theme property
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application/activity[@android:label='@string/activity_name']">
    <activity android:theme="@style/Theme.FullScreen.Splash" />
</edit-config>
  • Modify application tag's usesCleartextTraffic property
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
    <application android:usesCleartextTraffic="true" />
</edit-config>

Depending on the order these config-file and edit-config tags appear in config.xml the result is different.

What is expected to happen?

Expected AndroidManifest.xml to have all 3 updates:

<application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:usesCleartextTraffic="true">
    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.FullScreen.Splash" 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>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature android:name="android.hardware.touchscreen" android:required="true" />

What does actually happen?

Depending on the order these config-file and edit-config tags appear in config.xml the result is different. I can only get either: [WAKE_LOCK and Theme], or [clearText].

[WAKE_LOCK and Theme]:

    <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:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.FullScreen.Splash" 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>
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-feature android:name="android.hardware.touchscreen" android:required="true" />

[clearText]:

    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:usesCleartextTraffic="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" 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>

Summary of the different order combinations > results: image

Information

Command or Code

I have tried refreshing AndroidManifest.xml with:

  • cordova platform rm android && cordova platfrom add android
  • Deleting /platforms, /node_modules, and /plugins, and running cordova prepare android

Environment, Platform, Device

Windows 10

Version information

cordova -v
10.0.0-dev ([email protected])

In particular, cordova-cli commit 11ce340a47719060b57bcfe18852b20f21a69c65 [email protected]

Checklist

  • [x] I searched for existing GitHub issues
  • [x] I updated all Cordova tooling to most recent version
  • [x] I included all the necessary information above

Lindsay-Needs-Sleep avatar Nov 11 '19 23:11 Lindsay-Needs-Sleep

Could you test if the problem persists with cordova@nightly? Also do a cordova platform rm android && cordova platfrom add android@nightly using the nightly, before testing.

raphinesse avatar Nov 12 '19 00:11 raphinesse

Yep! I’ll do it in the morning! (~14hrs)

Lindsay-Needs-Sleep avatar Nov 12 '19 04:11 Lindsay-Needs-Sleep

I have tried it with cordova@nightly, the result is the same.

I created a new cordova project that demonstrates it: https://github.com/Lindsay-Needs-Sleep/cordova-cli_Issue-491

Lindsay-Needs-Sleep avatar Nov 12 '19 20:11 Lindsay-Needs-Sleep

Sorry for taking so long to come back to this. I could reproduce the problem, and finally I could figure out that it works if you ensure that all three edit-config/config-file tags have their file/target attributes set to the same value. While AndroidManifest.xml is expanded to app/src/main/AndroidManifest.xml in cordova-common, I guess that the following is happening:

  • the config changes are grouped by target file to prevent conflicts
  • this is done before the file name expansion, leaving your original config edit jobs in separate groups for AndroidManifest.xml and app/src/main/AndroidManifest.xml respectively
  • changes from both groups are applied to the original AndroidManifest.xml with the result written to the destination. Last group wins.

Fortunately you can work around the issue, while we try to fix it.

raphinesse avatar Nov 27 '19 14:11 raphinesse

@raphinesse Thanks so much! (Np, about the time. I totally get that.)

I didn't even realize I had used two different targets. Thanks for providing the work around!!

Lindsay-Needs-Sleep avatar Nov 29 '19 05:11 Lindsay-Needs-Sleep