【错误记录】Android 应用 release 打包报错处理 ( 关闭语法检查 | 日志处理 | release 配置 )
生活随笔
收集整理的這篇文章主要介紹了
【错误记录】Android 应用 release 打包报错处理 ( 关闭语法检查 | 日志处理 | release 配置 )
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
文章目錄
- 一、關(guān)閉語法檢查
- 二、日志處理
- 三、release 編譯優(yōu)化配置
一、關(guān)閉語法檢查
Android 應(yīng)用打包時會進行一系列語法檢查 , 如某個布局文件中位置擺放問題 , 比較繁瑣 ;
在 Module 下的 build.gradle 中進行如下配置 , 即可關(guān)于語法檢查 , 忽略一些小的語法錯誤 ;
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} }二、日志處理
根據(jù)當(dāng)前編譯配置中的編譯類型 BuildConfig.DEBUG , 選擇是否打印日志 ;
public final class BuildConfig {public static final boolean DEBUG = Boolean.parseBoolean("true");public static final String APPLICATION_ID = "cn.zkhw.midi";public static final String BUILD_TYPE = "debug";public static final int VERSION_CODE = 1;public static final String VERSION_NAME = "0.1"; }如果當(dāng)前是 release 版本 , 則 BuildConfig.DEBUG 值為 false ;
開發(fā)日志工具類 Log 示例 :
public class L {public static void i(String TAG, String msg) {if (BuildConfig.DEBUG)Log.i(TAG, msg);} }三、release 編譯優(yōu)化配置
一般情況下 , release 發(fā)布版本 , 都需要如下配置 ;
android {buildTypes {debug {}release {zipAlignEnabled true //Zipalign優(yōu)化shrinkResources true // 移除無用的resource文件minifyEnabled true //混淆proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}} }總結(jié)
以上是生活随笔為你收集整理的【错误记录】Android 应用 release 打包报错处理 ( 关闭语法检查 | 日志处理 | release 配置 )的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Android Protobuf 序列
- 下一篇: 【Android 安全】使用 360 加