【问题标题】:dexguard library cannot encrypt classesdexguard 库无法加密类
【发布时间】:2018-11-07 11:28:41
【问题描述】:

我尝试在我的 android 库项目中加密类。但我不能那样做。变量和字符串由 dexguard 更改,但 -encryptclasses 没有影响。我在构建输出中收到日志:

Warning: not encrypting kept class com.justexample.SomeClass1
Warning: not encrypting kept class com.justexample.SomeClass2
Warning: the configuration specifies to encrypt 2 classes that it keeps at the same time.
      Not encrypting those classes to avoid problems at runtime.
Note: inner class com.justexample.SomeClass1 is unencrypted, while its outer class is encrypted.
Note: inner class com.justexample.SomeClass2 is unencrypted, while its outer class is encrypted.
Note: one or more encrypted classes have unencrypted inner classes.

我的 dexguard-project.txt 是:

-verbose
-encryptstrings com.justexample.SomeClass1
-encryptclasses com.justexample.SomeClass1, com.justexample.SomeClass2

还有我的模块:

apply plugin: 'com.android.library'
apply plugin: 'dexguard'

android {
compileSdkVersion 25
defaultConfig {
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName gitVersionName()
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFile getDefaultDexGuardFile('dexguard-library-release.pro')
        proguardFile 'dexguard-project.txt'

    }
}
sourceSets { main {
    assets.srcDirs = ['src/main/assets', 'src/androidTest/assets/']
} }
}

dependencies {
//my dependecies
}

【问题讨论】:

    标签: android dexguard


    【解决方案1】:

    您正在使用默认库配置:dexguard-library-release.pro,默认情况下会保留所有公共/受保护类。

    您不能对保留的类进行加密。

    要解决该问题,请使用激进配置:dexguard-library-release-aggressive.pro 并指定不应混淆的库的公共 API。

    别忘了也使用 -repackageclasses com.mypackage.internal

    将所有混淆的类移动到这个包中。

    【讨论】:

    • 它有效。但我还有另一个问题。我也有 SomeClass3 里面有静态生成器。我排除 SomeClass3 不加密并且它是可见的,但是 Builder 消失了。我尝试使用 -keep、-keepattributes、-keepclassmembers 但没有任何效果。
    • 要保留内部类,您必须使用例如 -keep class com.myclass$** { *; },内部类的名称为它们的外部类 $ 内部类名称。
    猜你喜欢
    • 2012-10-26
    • 2014-02-07
    • 1970-01-01
    • 1970-01-01
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 2015-07-25
    • 1970-01-01
    相关资源
    最近更新 更多