一 錯誤信息
在打包app的時候出現報錯:
Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
...
二 分析
提示中,關閉lint checkReleaseBuilds 的檢查,雖然這樣可以解決問題,但是沒有解決根本問題。也就是說隱患依舊會存在。
lint 是代碼檢查,可以優化代碼,發現一些潛在的bug,所以儘量不要關閉。
關於lint的使用,可以查看 Android 性能優化:使用 Lint 優化代碼、去除多餘資源
三 解決
這個錯誤報告會生成在 [app module]/build/reports/lint-results-yourBuildName-fatal.html
打開這個網頁,可以看到詳細的錯誤信息,修改起來就簡單了。
每個人的報錯信息因代碼而異,像我這個因爲 android.permission.ACCESS_MOCK_LOCATION這個模擬位置的權限一般用於程序創建模擬位置,主要提供用於測試,打包的時候 lint 就會校驗報錯。解決辦法也很簡單:
先引入tools屬性:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
...
找到 ACCESS_MOCK_LOCATION 添加 tools:ignore=”MockLocation”:
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"
tools:ignore="MockLocation"/>
完成!