Gradle 匯出jar,混淆注意點

weixin_33850890發表於2016-07-26

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$* {
    *;
}

相關文章