1

I try to encrypt classes in my android library project. But I cannot do that. Variables and strings are changed by dexguard, but there is no impact from -encryptclasses. I receive logs in build output:

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.

My dexguard-project.txt is:

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

And my gradle for module:

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
}
kamilf
  • 157
  • 1
  • 3
  • 15

1 Answers1

2

You are using the default library configuration: dexguard-library-release.pro which will by default keep all public / protected classes.

You can not encrypt classes that are kept.

To solve that issue, use the aggressive configuration: dexguard-library-release-aggressive.pro and specify the public API of your library which should not be obfuscated.

Dont forgot to also use -repackageclasses com.mypackage.internal

to move all obfuscated classes into this package.

T. Neidhart
  • 6,060
  • 2
  • 15
  • 38
  • It works. But I have another problem. I have also SomeClass3 with static Builder inside. I excluded SomeClass3 to not encrypt and it is visible, but Builder disappears. I try with -keep, -keepattributes, -keepclassmembers but nothing works. – kamilf Nov 07 '18 at 13:36
  • 1
    To keep inner classes as well you have to use for example -keep class com.myclass$** { *; }, inner classes have as name their outerclass $ innerclass name. – T. Neidhart Nov 07 '18 at 14:40