android Studio 混淆打包jar,已经添加其他文件到jar

      最近在做相关第三方的SDK,使用的开发工具是android studio 。开发的时候没什么问题,直接使用了新建了library Module,重点来了,产品结束的时候,混淆打包,强调一下,现在项目查看的模式是project模式下,不然找不到文件就发愁了。

  • 最普遍的方法,就是直接修改library中的build.gradle和proguard-rules.pro文件,这两个修改已经是很普通化了。build.gradle中
buildTypes {
    release {
        minifyEnabled true//只需要把这里改成true就可以
        shrinkResources false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

上边的意思很简单的。就是修改build时候的配置文件。minifyEnabled是混淆的意思,true就是build程序的时候打开混淆。最后一句话就是,混淆的方式,把你要求的混淆东西都写到proguard-rules.pro文件中,比如接口类不能混淆,就要在这个文件中写到,接下来看proguard-rules.pro。

# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.

-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keepclassmembers public class com.test.application.test{
#      下面几项是为了测试暴露出来的方法
        public void getPublicKey(***);

}
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keepclassmembers class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

# Understand the @Keep support annotation.
-keep class android.support.annotation.Keep

-keep @android.support.annotation.Keep class * {*;}

-keepclasseswithmembers class * {
    @android.support.annotation.Keep <methods>;
}

-keepclasseswithmembers class * {
    @android.support.annotation.Keep <fields>;
}

-keepclasseswithmembers class * {
    @android.support.annotation.Keep <init>(...);
}


#忽略警告
-ignorewarnings
#保证是独立的jar,没有任何项目引用,如果不写就会认为我们所有的代码是无用的,从而把所有的代码压缩掉,导出一个空的jar
#-dontshrink
#保护泛型
-keepattributes Signature

-keepattributes EnclosingMethod


#下面是项目中不要混淆的代码
-keep class base64.**{*;}

说实话上边的也都是我从别的地方copy过来的。重点看有汉语注释的地方。

-keep class base64.**{*;}  就是把下边包内的所有类都不混淆,这里的-keep就是保留的意思,-keepclassmembers这个保留类里面的方法的意思,剩下的就自己研究吧,反正我是没怎么用到。

这样,跑起来还是没问题的,最后的jar文件在library中build/....文件下可以找到,下边就说说往jar包里添一些东西比如assets内的东西。

  • 第一步和上边的一样,生出jar,第二步就厉害了,要用到task makejar。修改文件 还是build.gradle,首先开头加一个
    apply plugin: 'com.android.library'

之后就要写task makejar

task makeJar(type: Jar) {
    from zipTree('build/intermediates/bundles/release/classes.jar')
    from fileTree(dir: 'src/main', includes: ['assets/**'])
    baseName = "Test"
    destinationDir = file("build")
}

上边的意思,大致能看懂吧,两个from 就是要把混淆好的jar包和assets下的文件合并 出来的名字是baseName 位置放在build路径下,不过这里可能有些问题,我出来直接在该项目下。

写完上边的的就开始点吧,android studio最右边,一般缩小着的gradle,点开,一般都是项目目录,接着点开你的library项目,应该只有Tasks目录。接着点开,层次应该是 android build help install other verification

咱们用到的 是other,点开 找到makejar,双击,等待,等待,下边不报错就好了。

转载于:https://my.oschina.net/u/3102230/blog/828009

Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值