'How to remove unneeded permissions on Ionic 5 capacitor Android app?
I am setting up my first Ionic React app. I created an app with Ionic 5 and used the In-app Purchase 2 plugin.
I wanted to test this, so I uploaded the signed APK to the Play Store.
When I check the app bundle details on the Play Store, I see that it requires several unneeded permissions:
Required permissions (13)
android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION, android.permission.ACCESS_NETWORK_STATE, android.permission.CAMERA, android.permission.INTERNET, android.permission.MODIFY_AUDIO_SETTINGS, android.permission.READ_EXTERNAL_STORAGE, android.permission.RECEIVE_BOOT_COMPLETED, android.permission.RECORD_AUDIO, android.permission.WAKE_LOCK, android.permission.WRITE_EXTERNAL_STORAGE, com.android.vending.BILLING, com.google.android.c2dm.permission.RECEIVE
For example, it doesn't need ACCESS_COARSE_LOCATION, RECORD_AUDIO, READ_EXTERNAL_STORAGE, and so on.
I didn't set any of this up; apparently "Capacitor apps ship with all the core plugins included."
How do I remove these?
Solution 1:[1]
The permissions are stored in /android/app/src/main/AndroidManifest.xml
. You can delete them and then rebuild the app to remove them.
Solution 2:[2]
I'm using cordova, and the plugin fileOpener2 uses the permission REQUEST_INSTALL_PACKAGES, however it isn't necessary in my app context.
so I had do write a hack, that removes this line from /android/app/src/main/AndroidManifest.xml just after the command cordova prepare.
Those commands are located in a build.sh that I use to generate the app version targeting each environment.
sed '/REQUEST_INSTALL_PACKAGES/d' platforms/android/app/src/main/AndroidManifest.xml > platforms/android/app/src/main/AndroidManifest_new.xml
rm -rf platforms/android/app/src/main/AndroidManifest.xml
mv platforms/android/app/src/main/AndroidManifest_new.xml platforms/android/app/src/main/AndroidManifest.xml
hope it helps you!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Patrick Kenny |
Solution 2 | Najib El Alam |