打包混淆初体验

由于本人不是互联网公司,主要是定制客户的功能,所以写的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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值