Menu

#680 proguard 6 beta2 getDeclaredField not found

v6.0
closed-fixed
None
5
2018-02-05
2018-01-18
No

Android Project

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.WindowDecorActionBar;

import java.lang.reflect.Field;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
            Field showHideAnimationEnabledField = WindowDecorActionBar.class.getDeclaredField("mShowHideAnimationEnabled");
            showHideAnimationEnabledField.setAccessible(true);
            showHideAnimationEnabledField.setBoolean(getSupportActionBar(), false);
        } catch (NoSuchFieldException e) {
            // should not happen.
            throw new AssertionError(e);
        } catch (IllegalAccessException e) {
           e.printStackTrace();
        }
    }
}

proguard config

-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 1
-allowaccessmodification
-dontpreverify

# The remainder of this file is identical to the non-optimized version
# of the Proguard configuration file (except that the other file has
# flags to turn off optimization).

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}


-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}


-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keepclassmembers class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

-dontwarn android.support.**


-keep class android.support.annotation.Keep

-keep @android.support.annotation.Keep class * {*;}

-keepclasseswithmembers class * {
    @android.support.annotation.Keep <methods>;
}

-keepclasseswithmembers class * {
    @android.support.annotation.Keep <fields>;
}

-keepclasseswithmembers class * {
    @android.support.annotation.Keep <init>(...);
}

-keep class android.support.v4.app.Fragment{
    *;
}
-keep class android.support.v4.app.FragmentActivity{
    *;
}

-keep class android.support.v7.view.ContextThemeWrapper { *; }
-keep class android.support.v7.widget.TintContextWrapper { *; }
-keep class com.meituan.android.hydra.SignatureChecker { *; }

here is build dump

import android.os.Bundle;
import android.support.v7.app.c;
import android.support.v7.app.r;
import java.lang.reflect.Field;

public class MainActivity extends c {
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.activity_main);
        try {
            Field declaredField = r.class.getDeclaredField("mShowHideAnimationEnabled");
            declaredField.setAccessible(true);
            declaredField.setBoolean(b(), false);
        } catch (NoSuchFieldException e) {
            throw new AssertionError(e);
        } catch (IllegalAccessException e2) {
            e2.printStackTrace();
        }
    }
}

r class not exist mShowHideAnimationEnabled

Discussion

  • Eric Lafortune

    Eric Lafortune - 2018-01-18

    Thanks for your detailed report. This is a regression indeed. It has now been fixed for the upcoming DexGuard 6.0 beta3.

     
  • Eric Lafortune

    Eric Lafortune - 2018-01-18
    • status: open --> open-fixed
     
  • Eric Lafortune

    Eric Lafortune - 2018-02-05
    • Status: open-fixed --> closed-fixed
     

Log in to post a comment.