打包混淆初体验

来源:互联网 发布:网络测试好学吗 编辑:程序博客网 时间:2024/06/06 11:48

由于本人不是互联网公司,主要是定制客户的功能,所以写的App都不需要发布、混淆等功能,下面是我测试的混淆,打包版本

打包

添加了签名

apply plugin: 'com.android.application'android {    signingConfigs {        release {            //storeFile file("../yourapp.keystore")            //storePassword "your password"            //keyAlias "your alias"            //keyPassword "your password"            //edit local.properties            //second, add property STORE_FILE, STORE_PASSWORD, KEY_ALIAS, KEY_PASSWORD        }    }    compileSdkVersion 23    buildToolsVersion "23.0.2"    defaultConfig {        applicationId "com.xuie.androiddemo"        minSdkVersion 21        targetSdkVersion 23        versionCode 1        versionName "1.0"    }    buildTypes {        release {            signingConfig signingConfigs.release            minifyEnabled true            zipAlignEnabled true            shrinkResources true            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }        debug {            debuggable true            minifyEnabled false            zipAlignEnabled true            shrinkResources true        }    }    productFlavors {        dev {            manifestPlaceholders = [channel: "dev"]        }    }    // rename the apk with the version name    applicationVariants.all { variant ->        variant.outputs.each { output ->            output.outputFile = new File(                    output.outputFile.parent.toString(),                    """android-test-demo-${variant.buildType.name}-v${variant.versionName}-${                        buildTime()                    }-${variant.productFlavors[0].name}.apk""".toLowerCase())        }    }}// 不想让别人知道别名,密码,Jenkins等信息,// 可以放在[local.properties],重要的事情说三遍,没有''符号,exp:a=123456// KEY_ALIAS=[别名]// KEY_PASSWORD=[pw]// STORE_FILE=[jks path]// STORE_PASSWORD=[pw]def Properties props = new Properties()def propFile = file('../local.properties')if (propFile.canRead()){    props.load(new FileInputStream(propFile))    if (props!=null && props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') &&            props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) {        println 'RELEASE BUILD SIGNING'        android.signingConfigs.release.storeFile = file(props['STORE_FILE'])        android.signingConfigs.release.storePassword = props['STORE_PASSWORD']        android.signingConfigs.release.keyAlias = props['KEY_ALIAS']        android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']    } else {        println 'RELEASE BUILD NOT FOUND SIGNING PROPERTIES'        android.buildTypes.release.signingConfig = null    }}else {    println 'RELEASE BUILD NOT FOUND SIGNING FILE'    android.buildTypes.release.signingConfig = null}// 编译日期def buildTime() {    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))}dependencies {    // 。。。}

混淆

-dontwarn butterknife.**-keep class butterknife.** { *; }

想知道有哪些包,我是用jadx来看有哪些包,不想隐藏的用上面的示例添加进去,然后再核对试试,程序别挂了。。。挂了好多次 - -!!!!

## 位于module下的proguard-rules.pro############################################## 主程序不能混淆的代码 ###############################################-dontwarn com.xuie.androiddemo.ui.**-keep class com.xuie.androiddemo.ui.** { *; }-keep class com.xuie.androiddemo.fragment.** { *; }-keep class com.xuie.androiddemo.adapter.** { *; }-keep class com.xuie.androiddemo.view.EnergyColumn-dontwarn butterknife.**-keep class butterknife.** { *; }-dontwarn com.dd.**-keep class com.dd.** { *; }-dontwarn android.**-keep class android.** { *; }-dontwarn com.android.**-keep class com.android.** { *; }-dontwarn com.squareup.**-keep class com.squareup.** { *; }-dontwarn jp.wasabeef.**-keep class jp.wasabeef.** { *; }-dontwarn rx.**-keep class rx.** { *; }################################################ 不优化泛型和反射 ###############################################-keepattributes Signature

参考

http://frank-zhu.github.io/android/2015/10/28/android-build-config/
http://www.jayfeng.com/2015/11/07/Android%E6%89%93%E5%8C%85%E7%9A%84%E9%82%A3%E4%BA%9B%E4%BA%8B/

0 0