1

I'm fairly new to android development and I know decided to give ProGuard a go.

After struggling with thousands of warnings, I managed to get a stable version of my app which does exactly what it's supposed to do.

So the only problem left is that Proguard completely destroys the layout of my androidplot.

I don't really know how to fix it and i didn't really find a similar problem online.

Any kind of tips are appreciated, as i don't even know where I should start to search for the Problem.

Here are two Screenshots (before and after ProGuard):

enter image description here enter image description here

----- UPDATE: -----

For everyone who might come across the same Issue:

I still don't know what exactly caused the problem but updating from Androidplot v1.1.0 to v1.4.1 did the trick for me.

m-mb
  • 44
  • 7

2 Answers2

3

For some situations, the default ProGuard configuration file (proguard-android.txt) is sufficient and ProGuard removes all—and only—the unused code. However, many situations are difficult for ProGuard to analyze correctly and it might remove code your app actually needs. Some examples of when it might incorrectly remove code include

When using proguard be sure to check documentation for all the libraries used in your project and add the givens proguard rules in the proguard-rules.pro at the root level of your Android project.

example for the v4

-dontwarn android.support.v4.** -keep class android.support.v4.app.** { *; } -keep interface android.support.v4.app.** { *; } -keep class android.support.v4.** { *; }

For android plot try this:

-keep class com.androidplot.** { *; }

But your problem is not obligatory on this lib

Cedric Franck
  • 526
  • 4
  • 9
  • i tried both of your suggestions, but unfortenately none of those help much :/ surprisingly, the '-keep class com.androidplot.** {*;}' does not affect my application even if it's missing. – m-mb Feb 17 '17 at 15:19
1

Cedric's answer is the right one, but given your comment on his solution it sounds like maybe your custom proguard rules arent getting picked up at all.

Depending on your project structure etc. (I'd assume you're using gradle with a recent SDK version) there might be different things going on. A couple things to check:

  • Make sure your proguard config (usually proguard-rules.pro) is in the correct location. (usually the project root)
  • Check your build.gradle to ensure that it's including your proguard config.

Usually something like this:

android {
  buildTypes {
    release {
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
    }
  }
  ...
}

NOTE: If you've enabling obfuscation for dev builds, you'll need to add the same thing for your dev build profile as well.

Nick
  • 8,181
  • 4
  • 38
  • 63
  • I checked it again and they do get picked up, as i got a lot of warnings about javamail but i managed to fix it with -libraryjars command in proguard-rules.pro so they do not seem to be ignored. The plot itself works fine too, its just the styling that gets messed up, I enabled proguard for release and debug and added the config to the debug build to but that didn't do the trick aswell :/ The issue that the line of code doesnt affect the functionality does still exist. I do a lot of the styling at runtime and still use v1.1.0 and a panzoomhelper class, can this be the problem? – m-mb Feb 22 '17 at 12:26
  • Depends if you use the old configurator way of configuring things. If that's what the problem is, then adding this proguard rule should work: `-keepclassmembers com.halfhp.fig.** { *; }` – Nick Feb 22 '17 at 13:45
  • unfortunately the rule gives me an unexpected keyword warning and doesnt let me compile the project, so i don't use the old configurator, i guess. Out of curiosity i updated to v1.4.1 and commented the whole panzoomhelper class out and now it works. I tested 1.1.0 without the panzomhelper class too, but this doesn't work either. So v1.1.0 seems to be causing the issue. So the only problem left is, that the functions "getCalculatedMinX" etc. are no longer available and don't have a replacement, which stops me from updating, because i hardly modified the helperclass and need them. – m-mb Feb 22 '17 at 15:14
  • regarding `getCalculatedMinX` etc. actually they do - check out the 1.2.2 section of the [release notes](https://github.com/halfhp/androidplot/blob/master/docs/release_notes.md) :-) – Nick Feb 22 '17 at 15:22
  • oh good lord, i must've been blind, i completely overlooked that ... Well i tested it now and everything works fine, thank you so much! :-) So i don't know exactly what caused it, but now it works nontheless. – m-mb Feb 22 '17 at 15:32