apache / cordova-android

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

Android INTERNET access permissions not being added in AndroidManifest.xml using Cordova 9.0.0 #857

Closed bandhavya closed 1 year ago

bandhavya commented 5 years ago

Bug Report

Problem

Android INTERNET access permissions not being added in AndroidManifest.xml using Cordova 9.0.0

What is expected to happen?

in the previous cordova versions, uses-permission was added directly in the AndroidManifest.xml file without any explicity permission addition in the config.xml

What does actually happen?

Now, the permissions are not added in the AndroidManifest.xml. We should explicitly add them from the config.xml. This does not occur with phonegap build.

Information

Just try to add a plugin which will make use of INTERNET access. On adding this plugin with cordova version less than 8.1.0 there are no conflicts. But with cordova 9.0.0, we observe that network calls are failing as there is no internet access permission included in AndroidManifest.xml file.

Command or Code

Environment, Platform, Device

Version information

Cordova cli 9.0.0 cordova-android 8.0.0

plugins used are

cordova-plugin-app-version 0.1.9 cordova-cookie-emperor cordova-plugin-customurlscheme 4.3.0 cordova-plugin-device 2.0.3 cordova-plugin-file 6.0.1 cordova-plugin-file-opener2 cordova-plugin-file-transfer 1.7.1 cordova-plugin-inappbrowser 3.0.0 cordova-plugin-mediascanner 0.1.3 cordova-plugin-splashscreen 5.0.2 cordova-plugin-statusbar 2.4.2 cordova-plugin-transport-security 0.1.2 cordova-plugin-whitelist 1.3.3 cordova-plugin-zeep 0.0.4

Checklist

Similar issue found https://github.com/apache/cordova/issues/95

bandhavya commented 5 years ago

One observation, in config.xml just include one plugin for example "phonegap-plugin-barcodescanner" and then execute " cordova platform add android@8.0.0" After this check the AndroidManifest.xml file in platforms > android > app > src > main We see that there are no uses-permission related to camera and flashlight being added in the AndroidManifest.xml. Hence issue is replicable.

Now, remove plugins and platform. Do not include any plugin in config.xml. Add android platform as mentioned above. Now, manually add plugin using "cordova plugin add phonegap-plugin-barcodescanner" Then permissions in AndroidManifest.xml file are update properly

breautek commented 5 years ago

Creating a base app using cordova 9, and cordova-android 8.1.0 produces the following manifest for me:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.breautek.i66" xmlns:android="http://schemas.android.com/apk/res/android">
    <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" />**
    <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="@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>
</manifest>

I've tried adding platform first and then plugin as well as plugin first then platform, and I saw the same results.

Adding the plugin does add the 2 other permissions for camera and flashlight.

Perhaps there is a specific plugin conflicting? I'd suggest you create a new app, confirm that the permission is set, then add your plugins one at a time to determine if there is a specific plugin that is causing the issue.

bandhavya commented 5 years ago

Creating a base app using cordova 9, and cordova-android 8.1.0 produces the following manifest for me:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.breautek.i66" xmlns:android="http://schemas.android.com/apk/res/android">
    <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" />**
    <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="@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>
</manifest>

I've tried adding platform first and then plugin as well as plugin first then platform, and I saw the same results.

Adding the plugin does add the 2 other permissions for camera and flashlight.

Perhaps there is a specific plugin conflicting? I'd suggest you create a new app, confirm that the permission is set, then add your plugins one at a time to determine if there is a specific plugin that is causing the issue.

While adding plugins manually after the adding platform will work. But issue is when plugins are already listed in the config.xml. Now, add platform which will also add the plugins simultaneously. Here we see the permissions are not added in the AndroidManifest.xml file

bandhavya commented 5 years ago

This issue happens where there is config-file element REQUEST_INSTALL_PACKAGES in the config.xml

`

    </config-file>`

Without this config-file element all the permissions are properly added to AndroidManifest.xml

Domvel commented 4 years ago

I had the same problem. In this screenshot you see the AdronidManifest.xml of two builds. The permission INTERNET is sometimes overwritten by BLUETOOTH_ADMIN. In this case you see the bluetooth one twice. (Left: Good, Right: Bad)

image

Solution

Not sure if this is your problem, but I think there is a problem with "merge" in this case. See the config.xml:

This does not work (edit-config merge):

<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/uses-permission" xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
</edit-config>

This works (config-file):

<config-file target="AndroidManifest.xml" parent="/manifest" xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
  <uses-permission android:name="android.permission.INTERNET"/>
</config-file>

Not sure if this was added manually or automatically by Cordova. (Have to check this by creating a new project.) And not sure if this is the perfect solution.

cordova-android: 9.0.0

mbaileys commented 3 years ago

This is an ongoing issue. It took us a while to figure out INTERNET permission had to be added manually in cordova-android 9.

Joannanas commented 3 years ago

I just struggled for a few days with a related and pretty annoying issue, and my conclusion might help to isolate the case. Everytime I run the "cordova run android" command line, it detects some non-existent conflict for the AndroidManifest and deletes one by one every permission added by the phonegap-barcodescanner used by my app, along with one of the "edit-config" from the cordova-plugin-push (this is what made me question everything)

I thought that maybe I add something written in my config.xml file that really made a conflict, but I have no permission change in it, so the content of the config.xml alone is not the issue here.

I tried the verbose option but it does not explicitly tell what is in conflict, so i tried to comment everything I have in my config.xml file, and I figured out that the conflict comes from trying to merge config into the application as follow :

<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:theme="@style/AppTheme"/>
</edit-config>

It seems also relevant to say that I do not use the option "--force" when adding a plugin, but I still only have this small warning line "Conflict found, edit-config changes from config.xml will overwrite plugin.xml changes" everytime I use the "cordova run android" command, ONLY when I have the previous merge in my config.xml file. If I comment it, no conflict is detected and all my permissions/edit-config stay in the generated AndroidManifest.

So, TLDR, my permissions are deleted when doing cordova run androidcommand by the fact that I have an edit-config trying to merge an atrribute to my application tag. The edit-config is then done, but every run command deletes some line from the generated AndroidManifext.xml.

EDIT To solve my problem, but it might not be possible for everybody, I moved my "faulty" edit-config from the config.xml, to the plugin.xml of one of my home made utils plugin. With that and so far, I have no warning when adding the plugin and everything is in my generated AndroidManifest.

breautek commented 1 year ago

Closing as stale.