您当前的位置: 首页 >  android

韩曙亮

暂无认证

  • 4浏览

    0关注

    1068博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【错误记录】Android 应用 release 打包报错处理 ( 关闭语法检查 | 日志处理 | release 配置 )

韩曙亮 发布时间:2021-04-27 17:38:32 ,浏览量:4

文章目录
  • 一、关闭语法检查
  • 二、日志处理
  • 三、release 编译优化配置

一、关闭语法检查

Android 应用打包时会进行一系列语法检查 , 如某个布局文件中位置摆放问题 , 比较繁琐 ;

在 Module 下的 build.gradle 中进行如下配置 , 即可关于语法检查 , 忽略一些小的语法错误 ;

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
    }
}
二、日志处理

根据当前编译配置中的编译类型 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";
}

如果当前是 release 版本 , 则 BuildConfig.DEBUG 值为 false ;

开发日志工具类 Log 示例 :

public class L {

    public static void i(String TAG, String msg) {
        if (BuildConfig.DEBUG)
            Log.i(TAG, msg);
    }
}
三、release 编译优化配置

一般情况下 , release 发布版本 , 都需要如下配置 ;

android {
    buildTypes {
        debug {
        }

        release {
            zipAlignEnabled true     //Zipalign优化
            shrinkResources true     // 移除无用的resource文件
            minifyEnabled true       //混淆
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
关注
打赏
1663594092
查看更多评论
立即登录/注册

微信扫码登录

0.0876s