Reputation: 2595
My Gradle project contains 4 libraries. In recent builds of my app I found that Android Studio is silently adding "read call log" and "write call log" permissions to the manifest. In the build folder is a "final" manifest that is packaged into the apk and it contains these lines:
<android:uses-permission android:name="android.permission.READ_CALL_LOG" />
<android:uses-permission android:name="android.permission.WRITE_CALL_LOG" />
Is there a way to either disable this weird behavior completely or enable some logging to know where this comes from? I don't like when software tries to be smarter than me.
Upvotes: 9
Views: 3406
Reputation: 1411
You can use "Merge conflict markers" to remove this tag from your Android Manifest.
Then you can setup on your AndroidManifest the next code and they will be removed:
<uses-permission android:name="android.permission.READ_CALL_LOG"
tools:node="remove"/>
<uses-permission android:name="android.permission.WRITE_CALL_LOG"
tools:node="remove"/>
Upvotes: 17
Reputation: 1841
The manifests are merged, so this is not supported yet.
You can archieve this by adding a new gradle task to your build.gradle, and attaching it as a dependence of processDebugResources
and processReleaseResources
gradle tasks.
task('removeExtraPermissionsDebug') << {
//Input the correct manifest file (could be under 'full' folder).
def manifestFile = file("build/intermediates/manifests/full/debug/AndroidManifest.xml")
def patternPermissions = Pattern.compile(".+(android\\.permission\\.ACCESS_NETWORK_STATE|android\\.permission\\.WAKE_LOCK).+")
def manifestText = manifestFile.getText()
def matcherPermissions = patternPermissions.matcher(manifestText)
def newManifestText = matcherPermissions.replaceAll("")
manifestFile.write(newManifestText)
}
tasks.whenTaskAdded { task ->
if(task.name == 'processDebugResources'){
task.dependsOn 'removeExtraPermissionsDebug'
}
}
Notes:
If you have custom flavours and build types, take into account the names of the tasks you need to attach to: process{Flavour}{BuildType}Resources
.
You may need to replicate the task to delete permissions also when generating the release.
Upvotes: 0