举例:<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
需求:debug有这个权限,release没有这个权限
一. 第一种是第三方库没有引入MANAGE_EXTERNAL_STORAGE权限,实现如下
app的AndroidManifest.xml
XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.demo">
<uses-permission android:name="${MANAGE_EXTERNAL_STORAGE}"
tools:node="merge"/>
<application.../>
</manifest>
app模块下build.gradle
Groovy
android {
...
buildTypes {
debug {
...
//debug提供真实权限
manifestPlaceholders = [MANAGE_EXTERNAL_STORAGE: "android.permission.MANAGE_EXTERNAL_STORAGE"]
}
release {
...
//release提供com.example.demo.permission占位,有值才能编译过
manifestPlaceholders = [MANAGE_EXTERNAL_STORAGE: "com.example.demo.permission"]
}
}
}
二.第二种是第三方库已经引入了MANAGE_EXTERNAL_STORAGE权限,实现如下
app的AndroidManifest.xml
XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.demo">
<uses-permission android:name="${MANAGE_EXTERNAL_STORAGE}"
tools:node="remove"/>
<application.../>
</manifest>
app模块下build.gradle
Groovy
android {
...
buildTypes {
debug {
...
//debug提供com.example.demo.permission占位,有值才能编译过
manifestPlaceholders = [MANAGE_EXTERNAL_STORAGE: "com.example.demo.permission"]
}
release {
...
//release提供真实权限
manifestPlaceholders = [MANAGE_EXTERNAL_STORAGE: "android.permission.MANAGE_EXTERNAL_STORAGE"]
}
}
}