apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

edit-config on AndroidManifest.xml overwrite existing plugin configs #801

Closed b1zzu closed 4 years ago

b1zzu commented 4 years ago

Bug Report

Problem

What is expected to happen?

I expect to have bot the configurations applied from the plugin and the one specified inside the config.xml, which means having <application [...] android:usesCleartextTraffic="true"> and <service android:name="com.adobe.phonegap.push.FCMService">[...]</service> in the final AndroidManifest.xml

What does actually happen?

In the final AndroidManifest.xml is only present the configuration from the config.xml <application [...] android:usesCleartextTraffic="true">

Information

Command or Code

create a new cordova app:

cordova create app
cd app

overwrite the config.xml with this one:

<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
    <name>HelloCordova</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
        <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:usesCleartextTraffic="true" />
        </edit-config>
        <resource-file src="google-services.json" target="app/google-services.json" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

create a fake google-services.json

{
  "project_info": {
    "project_number": "1",
    "firebase_url": "https://a.firebaseio.com",
    "project_id": "a",
    "storage_bucket": "a.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:1:android:a",
        "android_client_info": {
          "package_name": "io.cordova.hellocordova"
        }
      },
      "oauth_client": [
        {
          "client_id": "1-a.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "a"
        }
      ],
      "services": {
        "appinvite_service": {
          "other_platform_oauth_client": [
            {
              "client_id": "1-a.apps.googleusercontent.com",
              "client_type": 3
            }
          ]
        }
      }
    }
  ],
  "configuration_version": "1"
}

add the phonegap-plugin-push

cordova plugin add phonegap-plugin-push

add android

cordova platform add android

build the android app

cordova build android

verify the AndroidManifest.xml

cat platforms/android/app/src/main/AndroidManifest.xml

<service android:name="com.adobe.phonegap.push.FCMService">[...]</service> should be present inside the AndroidManinfest.xml but it isn't.

Environment, Platform, Device

# cat /etc/redhat-release
Fedora release 30 (Thirty)

Version information

# cordova --version
9.0.0 (cordova-lib@9.0.1)
# node --version                 
v10.16.0
# ls $ANDROID_HOME/build-tools                            
28.0.3
# $JAVA_HOME/bin/java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-b04)
OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)

Checklist

breautek commented 4 years ago

Thank you for your well written issue report. Confirmed this is an issue. My command line output states:

Conflict found, edit-config changes from config.xml will overwrite plugin.xml changes

But comparing config.xml to phonegap-push-plugin plugin.xml what is conflicting isn't very obvious. Perhaps it is one of phonegap-push-plugin's dependencies?

b1zzu commented 4 years ago

Hi @breautek I don't think something is conflicting, and I found out that changing edit-config in this way

[...]
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
[...]

will make the conflict disappear

danielpassos commented 4 years ago

@b1zzu You should use the full path for AndroidManifest.xml in edit-config

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
    <application android:usesCleartextTraffic="true"/>
</edit-config>
b1zzu commented 4 years ago

@danielpassos cordova official documentation suggests using only the file name: https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html#edit-config

image

and in cordova 8 it works using only the name.

zieglerphilipp commented 4 years ago

Do you have an idea, what am I doing wrong:

https://stackoverflow.com/questions/61074885/cordova-android-avd-access-apache-server-xampp-config-xml-permission

Venegrad commented 1 month ago

Same issue, not working