Gradle 导出jar,混淆注意点

1、build.gradle

apply plugin: 'com.android.library'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.1'
    }
}

android {
    compileSdkVersion 19
    buildToolsVersion '20.0.0'
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets{
        main {
            java.srcDirs = ['src']
        }
    }
}



// This is the actual solution, as in http://stackoverflow.com/a/19037807/1002054
task clearJar(type: Delete) {
    delete 'build/libs/test11.jar'
}

task makeJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('build/intermediates/libs/')
    include('classes.jar')
    rename ('classes.jar', 'test11.jar')
}

makeJar.dependsOn(clearJar, assembleRelease)

2、因为加了混淆,这里如果有内部类的话,混淆的时候就要注意了

-printmapping proguardMapping.txt
-dontwarn org.apache.lang.**
##保留内部类
-keepattributes Exceptions, InnerClasses

-keep public class * {
   public *;
}
##保留内部类
-keep class com.XXX.A$* {
    *;
}
    原文作者:紫苓
    原文地址: https://www.jianshu.com/p/1bf38fa86dbb
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞