0

CrashLytics test project in Android Studio with proguard enabled do not obfuscate Class and method names. As you see in provided rules file, I don't use any rules "proguard-rules.pro".

  1. Where I am doing wrong?
  2. Is there a reference document or tutorial for explaining Proguard rules?

build.gradle

buildscript { repositories { maven { url 'https://maven.fabric.io/public' } } dependencies { // These docs use an open ended version so that our plugin // can be updated quickly in response to Android tooling updates // We recommend changing it to the latest version from our changelog: // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin classpath 'io.fabric.tools:gradle:1.22.1' } } apply plugin: 'com.android.application' apply plugin: 'io.fabric' repositories { maven { url 'https://maven.fabric.io/public' } } android { signingConfigs { config { keyAlias 'key0' keyPassword 'A123456789' storeFile file('D:/Android/KeyStorePath/key1.jks') storePassword 'A123456' } } compileSdkVersion 26 buildToolsVersion "26.0.0" defaultConfig { applicationId "com.example.ba.autocompletetextcustomadapter" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" signingConfig signingConfigs.config } buildTypes { release { debuggable true minifyEnabled true shrinkResources false proguardFiles 'proguard-rules.pro' } debug { minifyEnabled true proguardFiles 'proguard-rules.pro' } } productFlavors { } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso- core:3.0.1' compile('com.crashlytics.sdk.android:crashlytics:2.7.0@aar') { transitive = true } } 

proguard-rules.pro

 # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in D:\sdk/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} # Uncomment this to preserve the line number information for # debugging stack traces. #-keepattributes SourceFile,LineNumberTable # If you keep the line number information, uncomment this to # hide the original source file name. 

apk analyser shows that Class and method names are completely clear

apk analyser shows that Class and method names are completely clear

below screenshot shows that proguard is working

below screenshot shows that proguard is working Updated

Ok, I cannot obfuscate Activity names because it should be referable via Manifest file, but how about method names onCreate and forceCrash, why they are still readble?

import io.fabric.sdk.android.Fabric; import com.crashlytics.android.Crashlytics; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Fabric.with(this, new Crashlytics()); setContentView(R.layout.activity_main); } public void forceCrash(View view) { throw new RuntimeException("This is a crash"); } } 
8
  • 1
    are you analyizing the relase apk or the debug apk? Alao I suggest you hide your keystore password and other sensitive informations Commented Oct 30, 2017 at 8:00
  • both, they are same, if you look at build.gradle file proguard is enabled for both. Commented Oct 30, 2017 at 8:02
  • why is your release build debuggable lol so weird Commented Oct 30, 2017 at 8:03
  • @Patzu you shouldn't have proguard enabled on debug builds because it obfuscates the APK and through that the output Commented Oct 30, 2017 at 8:04
  • Yes I know, proguard should not enabled in debug mode, It cause more time to build. I did this just for testing. Also sensitive information are temporary. Commented Oct 30, 2017 at 8:06

3 Answers 3

1

replace

proguardFiles 'proguard-rules.pro'

line with

getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

Sign up to request clarification or add additional context in comments.

1 Comment

I also did this before sending the question no result anymore.
1
  1. You are doing nothing wrong. Most of your code is appparently obfuscated - the b, a and c classes in your screenshot are. There are default ProGuard rules being generated in your build - you can find them in build\intermediates\proguard-files\ folder of your project. Activity names are not obfuscated for reason explained in this answer ProGuard Still Displays Full Activity Name

    Activity names are never obfuscated because these are referenced in manifest.xml. and android access these activities via reflection so their names cannot be changed)

  2. Using ProGuard rules is explained in the Android docs - https://developer.android.com/studio/build/shrink-code.html, in ProGuard manual - https://www.guardsquare.com/en/proguard/manual/usage and recently there has been a nice article on troubleshooting ProGuard - https://medium.com/google-developers/troubleshooting-proguard-issues-on-android-bce9de4f8a74

1 Comment

Thanks a lot for the info, specially for links, please see my updates in question.
0

Apparentely, actually no one thing obfuscates activities names. But, you can change it manually. Just modify its name to some name you want.

For methods and classes obfuscating, just use the:

-obfuscationdictionary file.txt -classobfuscationdictionary file.txt 

4 Comments

what could be there in that file.txt?
Strings for new classes names. Like: this.that that.this OrThis
Can you share a sample file with text here or any reference?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.