Gradle编译混淆jar包流程说明和解决错误 lint 和 java.io.IOException: Please correct the above warnings first.

35 篇文章 1 订阅

一. Gradle编译混销魂的jar包,流程:

 开发编译环境为Android studio 3.6.2,其他版本可能会有不一样的地方,

1. 增加编译task

在需要编译jar包的build.gradle文件的根中增加task :

//app/build.gradle:

//apply plugin: 'com.android.application'
apply plugin: 'com.android.library'

.........................
//自定义编译任务名称
task makeMyJar(type: proguard.gradle.ProGuardTask, dependsOn: "build") {
    // 未混淆的jar: compile_library_classes为android studio 3.6.2版本编译产出
    // 其他版本可能不一样,可打开build/intermediates/目录查找,低版本的事bundle
    injars 'build/intermediates/compile_library_classes/release/classes.jar'
    // 混淆后的jar路径
    outjars 'build/My-sdk.jar'
    // 混淆规则文件,具体需要keep的类
    configuration 'proguard-rules.pro'
}

2. 执行makeMyJar编译任务: 

(1). 直接在Android studio右上角的task中找到makeMyJar双击即可开始编译;

(2). 项目根目录下打开终端Terminal,输入 ./gradlew makeMyjar 回车即可.

 

二  解决lint错误 Lint found errors in the project; aborting build.

1. 错误信息

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':MyApp:lint'.
> Lint found errors in the project; aborting build.
  
  Fix the issues identified by lint, or add the following to your build script to proceed with errors:
  ...
  android {
      lintOptions {
          abortOnError false
      }
  }
  ...
  
  The first 3 errors (out of 4) were:

原因: 以上错误原因是执行lint检查事出现错误;

2. 解决方案:

按照提示信息,在build.gradle的android{}中增加配置禁用即可:

lintOptions {
          abortOnError false
}

 

三.  解决警告过多错误 java.io.IOException: Please correct the above warnings first.

编译过程中出现很多警告,最后错误

1. 错误信息

Warning: com.hulk.demo.User: can't find referenced class java.lang.Class
Warning: com.hulk.demo.UserManager: can't find referenced class java.lang.Class
很多警告......................................

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':MyApp:makeMyJar'.
> java.io.IOException: Please correct the above warnings first.

................
原因: 警告过多导致错误

2. 解决方案:

在proguard-rules.pro(可以使其他自定义名字的文件)中增加不警告声明:

#不警告编译过程中的警告:Please correct the above warnings first
#-dontwarn com.mobile.emm.**

如proguard-rules.pro:

#不警告编译过程中的警告:Please correct the above warnings first
#-dontwarn com.mobile.emm.**

#keep user
-keep class com.hulk.demo.User** {*;}
.......................

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

总结:

错误一般会有提示信息,仔细分级一般都能找到解决办法

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值