So I have 10 flavors in my android project: fl1, fl2, ..., fl10 with the permissions below. Now I want my fl5 not have the android.permission.REQUEST_INSTALL_PACKAGES
. How to do this?
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
I know that I can have a different manifest file in fl5/AndroidManifest.xml
. And it can include any excessive element for this specific build. But this can be a source of errors and mistakes as I should be careful of syncing every time I add an element to main manifest.
I have searched and found different solutions. But I couldn't implement them in my project because they weren't exact. Any help is appreciated.
Here is my fl5/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mycompany.myapp">
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" tools:node="remove"></uses-permission >
And here it is my flavors in build.gradle
file:
productFlavors {
fl1 {flavorDimensions "in_1"}
fl2 {flavorDimensions "in_2"}
fl3 {flavorDimensions "in_3"}
fl4 {flavorDimensions "in_4"}
fl5 {flavorDimensions "in_5"}
fl6 {flavorDimensions "in_6"}
fl7 {flavorDimensions "in_7"}
fl8 {flavorDimensions "in_8"}
fl9 {flavorDimensions "in_9"}
fl10 {flavorDimensions "in_10"}
}
Add tools:node="remove"
in your element. In your case, add the following line in fl5/AndroidManifest.xml
.
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" tools:node="remove"/>
Take a look at Removing AndroidManifest element with gradle product flavors and How to remove specific permission when build Android app with gradle? questions.