I need to play sounds in my game, so I added org.apache.cordova.media plugin to my application. Now platforms/android/AndroidManifest.xml contains 2 entries I don't need:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
If I remove those lines, this file regenerated and permissions are added again. What is correct way to remove these permissions? I use apache cordova 3.5.0
Create a file in root directory of your project and rename it to remove_permissions.js then put the following code into it:
var permissionsToRemove = [ "RECORD_AUDIO", "MODIFY_AUDIO_SETTINGS"];
var fs = require('fs');
var path = require('path');
var rootdir = "";
var manifestFile = path.join(rootdir, "platforms/android/app/src/main/AndroidManifest.xml");
fs.readFile( manifestFile, "utf8", function( err, data )
{
if (err)
return console.log( err );
var result = data;
for (var i=0; i<permissionsToRemove.length; i++)
result = result.replace( "<uses-permission android:name=\"android.permission." + permissionsToRemove[i] + "\" />", "" );
fs.writeFile( manifestFile, result, "utf8", function( err )
{
if (err)
return console.log( err );
} );
} );
Open config.xml and add the bellow line in Android part:
<platform name="android">
...
<hook type="after_prepare" src="remove_permissions.js"/>
...
</platform>
Now rebuild APK file.
The approach in @codevision's response used to work for me, but in more recent (I don't know exactly what cutoff) versions of the cordova-android platform, I found that permissions were still being merged into the final AndroidManifest.xml in the APK.
The cause of this was the Merge Multiple Manifest Files build step that caused permissions declared from various plugin dependencies (including .aar files) to sneak back into the final AndroidManifest.xml.
What worked for me was creating an after-prepare script that modified platforms/android/AndroidManifest.xml
as follows:
<manifest>
tag xmlns:tools="http://schemas.android.com/tools"
tools:node="remove"
, e.g.:<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" tools:node="remove">
This prevents any dependencies from sneaking their MODIFY_AUDIO_SETTINGS
permission into the final APK.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With