Android libmoudle生成jar包并混淆

工具 Android studio4.0.1 和一个library的moudle
在lib的biuld文件里写上

 def SDK_BASENAME = "myjar";
    def SDK_VERSION = "_v1.0.0";
    def sdkDestinationPath = "build/outputs/jar/";
    task deleteBuild(type: Delete) {
        delete sdkDestinationPath + SDK_BASENAME + SDK_VERSION + ".jar"
    }
    task makeJar(type: Jar) {
        from('build/intermediates/javac/debug/classes/')
        baseName SDK_BASENAME + SDK_VERSION
        destinationDir file(sdkDestinationPath)
    }
    makeJar.dependsOn(deleteBuild, build)


    task ProguardJar(type: ProGuardTask, dependsOn: "build") {
// 未混淆的jar路径
        injars sdkDestinationPath + SDK_BASENAME + SDK_VERSION + ".jar"
        // 混淆后的jar输出路径
        outjars sdkDestinationPath + SDK_BASENAME + SDK_VERSION + "P.jar"
        // 混淆协议
        configuration 'proguard-rules.pro'
    }

跟buildTypes同级
然后点击右边gradle找到 makeJar双击运行
再找到ProguardJar双击运行
去自己写好的路径里找生成出来的jar包

附上混淆文件

-dontoptimize
-dontusemixedcaseclassnames
-keepattributes *Annotation*,Signature,InnerClasses,EnclosingMethod
-dontpreverify
-verbose
-dontnote com.android.vending.licensing.ILicensingService,com.google.vending.licensing.ILicensingService,com.google.android.vending.licensing.ILicensingService,android.support.**
-dontwarn android.support.**
-ignorewarnings

-dontshrink#混淆jar的时候一定要配置,不然会把没有用到的代码全部remove   我本来封装一个jar就是给别人调用的,全部删掉就没有东西了

-verbose
-keep class com.mmm.security.MainActivity


-keep class com.mmm.security.SecurityUtil{
    public ;
    public ;
}

你可能感兴趣的:(Android libmoudle生成jar包并混淆)