Seal is a gradle plugin to do precheck of Android Manifest.
English | 中文说明
As we all know, Android provides a tool names AndroidManifest Merger to manage manifests-merge. But these rules are not enough for some situation like below:
- Warning: AndroidManifest.xml already defines debuggable (in http://schemas.android.com/apk/res/android); using existing value in manifest.
That's because some out-of-date libraries set debuggable
at AndroidManifest, but now we use build.gradle
to do it.
- Multiple entries with same key: @android:theme=REPLACE and android:theme=REPLACE / Multiple entries with same key: @android:allowBackup=REPLACE and android:allowBackup=REPLACE.
There is a library which defined android:allowBackup=true
conflicts with yours (android:allowBackup=false
). You wanna to override it using tools:replace="android:allowBackup"
, but find that tools:replace="android:allowBackup"
is also present at lib's manifest, finally the conflict shows above. (Also see this)
...
All of these are what we face with, and Seal trying to solve.
- Compile&apply Seal plugin:
// project's build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'me.xx2bab.gradle:seal-manifest-precheck-plugin:1.0.0'
}
}
...
// app's build.gradle
apply plugin: 'seal'
- Configurations:
def projectRoot = project.getRootProject().rootDir.absolutePath
// Folders may include AndroidManifest.xml files
// 1. For gradle plugin 2.3.0 or higher, build-cache is default choice,
// 2. But we should make sure snapshot-libs will be checked too.
// 3. Free to add your folders for more customization
def manifestPath = [
// for AAR of Release
// see note below
projectRoot + '/build-cache',
// for AAR of SNAPSHOT
projectRoot + '/app/build/intermediates/exploded-aar'
]
def removeAttrs = [
'android:debuggable'
]
def replaceValues = [
'android:allowBackup'
]
seal {
enabled = true
manifests = manifestPath
appAttrs {
enabled = true
attrsShouldRemove = removeAttrs
}
appReplaceValues {
enabled = true
valuesShouldRemove = replaceValues
}
}
Note: If build-cache
is enable, Seal recommends that custom build cache folder placed in the Project Folder.
//gradle.properties
android.buildCacheDir=./build-cache
...
before:
<application
android:allowBackup="true"
android:debuggable="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
tools:replace="android:allowBackup" >
</application>
after:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
</application>
- Support Removing Application Attributes
- Support Removing Application's
tools:replace
value
Copyright 2017 2BAB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.