近日测试的小美眉开始对Apk做安全测试,测出有个安全隐患问题,问题如下图
image.png
对于allowBackup属性的解释如下
android:allowBackup
是否允许应用参与备份和恢复基础架构。如果将此属性设为 false,则永远不会为该应用执行备份或恢复,即使是采用全系统备份方法也不例外(这种备份方法通常会通过 adb 保存所有应用数据)。此属性的默认值为 true。
详细请看https://developer.android.com/guide/topics/manifest/application-element
也就是说,App的数据可以通过adb将数据备份出来。
接下来,我就把工程所有AndroidManifest的allowBackup属性全改成false,然后打包就报下面这个错!
看到这个问题,是不是心里好慌,别慌,在项目的根目录执行以下命令
Windows执行
gradlew processDebugManifest --stacktrace
MAC 执行
.gradlew processDebugManifest --stacktrace
执行结果如下图所示
D:\Code\Android\Demo\1\JinYuDemoApp>gradlew processDebugManifest --stacktrace
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
> Configure project :app
WARNING: API 'variantOutput.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variantOutput.getPackageApplication(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
> Task :app:processDebugManifest FAILED
D:\Code\Android\Demo\1\JinYuDemoApp\app\src\main\AndroidManifest.xml:12:5-95 Warning:
Element uses-permission#android.permission.ACCESS_NETWORK_STATE at AndroidManifest.xml:12:5-95 duplicated with element declared at AndroidManifest.xml:6:5-79
D:\Code\Android\Demo\1\JinYuDemoApp\app\src\main\AndroidManifest.xml:18:5-83 Warning:
Element uses-permission#android.permission.INTERNET at AndroidManifest.xml:18:5-83 duplicated with element declared at AndroidManifest.xml:5:5-67
D:\Code\Android\Demo\1\JinYuDemoApp\app\src\main\AndroidManifest.xml:29:5-80 Warning:
Element uses-permission#android.permission.WRITE_EXTERNAL_STORAGE at AndroidManifest.xml:29:5-80 duplicated with element declared at AndroidManifest.xml:22:5-97
D:\Code\Android\Demo\1\JinYuDemoApp\app\src\main\AndroidManifest.xml:32:9-36 Error:
Attribute application@allowBackup value=(false) from AndroidManifest.xml:32:9-36
is also present at [com.github.lzyzsd:jsbridge:1.0.4] AndroidManifest.xml:12:9-35 value=(true).
Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:31:5-78:19 to override.
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
FAILURE: Build failed with an exception.
到这里,我们问题基本就解决了,原因是因为在com.github.lzyzsd:jsbridge这个库里面,有设置allowBackup为true,解决问题的方法也已经给出了
Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:31:5-78:19 to override.
加上下面这行代码就可以打包了!
image.png
网友评论