0

I've got a LibGDX game and I've just noticed that at some point the soft keys stopped being hidden. I'm not sure exactly when this occurred or what changed.

Looking into the issue I discovered that it was working fine in debug mode. I then tried a release build with minification turned off and it also worked fine.

I've tried tweaking various settings but can't get the soft keys to hide with minification turned on.

I've got this happening on two different Android 6 devices.

I don't really know where to start looking with this one. Has anyone else experienced this?

My UI related code is here:

private void setUpAndroidUi() {
    // Do the stuff that initialize() would do for you
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        setKitKatVisibility();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setJellyBeanVisibility();
    } else {
        setStandardVisibility();
    }

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

private void setStandardVisibility() {
    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private void setJellyBeanVisibility() {
    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN);
}

@TargetApi(Build.VERSION_CODES.KITKAT)
private void setKitKatVisibility() {
    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE);
}

Proguard file is

# ********** DEAFULT ANDROID SETUP *************

# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html

# Optimizations: If you don't want to optimize, use the
# proguard-android.txt configuration file instead of this one, which
# turns off the optimization flags.  Adding optimization introduces
# certain risks, since for example not all optimizations performed by
# ProGuard works on all versions of Dalvik.  The following flags turn
# off various optimizations known to have issues, but the list may not
# be complete or up to date. (The "arithmetic" optimization can be
# used if you are only targeting Android 2.0 or later.)  Make sure you
# test thoroughly if you go this route.
-optimizations !code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 5
-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

-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

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

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

# 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*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

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

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

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

# ********** END OF DEAFULT ANDROID SETUP *************

# ********** AMAZON RELATED STUFF *************

-dontwarn com.amazon.**
-keep class com.amazon.** {*;}
-keepattributes *Annotation*

-optimizations !code/allocation/variable

# ********** END AMAZON RELATED STUFF *************

# ********** WE WANT TO KEEP SERIALIZABLE STUFF FOR REFLECTION *********
-keep class * implements java.io.Serializable
-keepnames class * implements java.io.Serializable
-keepclassmembers class * implements java.io.Serializable{
    public <init>();
    public <init>(android.content.Context);
}

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    !static !transient <fields>;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

# ********** END WE WANT TO KEEP SERIALIZABLE STUFF FOR REFLECTION *********

# ********** OGURY *********

-keepattributes Signature
-keep class sun.misc.Unsafe { *; }

-keep class shared_presage.** { *; }
-keep class io.presage.** { *; }
-keepclassmembers class io.presage.** {
 *;
}

-keepattributes *Annotation*
-keepattributes JavascriptInterface
-keepclassmembers class * {
    @android.webkit.JavascriptInterface <methods>;
}

-dontwarn org.apache.commons.collections.BeanMap
-dontwarn java.beans.**

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

# ********** OGURY BESPOKE

-keep class android.media.**
-dontwarn android.media.**
-dontnote android.media.**

# ********** END OGURY *********

# ********** LIBGDX **************

-verbose

-dontwarn android.support.**
-dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication
-dontwarn com.badlogic.gdx.utils.GdxBuild
-dontwarn com.badlogic.gdx.physics.box2d.utils.Box2DBuild
-dontwarn com.badlogic.gdx.jnigen.BuildTarget*

-keepclassmembers class com.badlogic.gdx.backends.android.AndroidInput* {
   <init>(com.badlogic.gdx.Application, android.content.Context, java.lang.Object, com.badlogic.gdx.backends.android.AndroidApplicationConfiguration);
}

-keepclassmembers class com.badlogic.gdx.physics.box2d.World {
   boolean contactFilter(long, long);
   void    beginContact(long);
   void    endContact(long);
   void    preSolve(long, long);
   void    postSolve(long, long);
   boolean reportFixture(long);
   float   reportRayFixture(long, float, float, float, float, float);
}

# ********** LIBGDX BESPOKE
-dontwarn java.awt.**
-dontwarn com.google.gwt.**
-keep,includedescriptorclasses class * implements com.badlogic.gdx.utils.Json*

# ********** END LIBGDX **************

# ********** GUAVA **********

-dontwarn javax.annotation.**
-dontwarn javax.inject.**
-dontwarn javax.xml.bind.**
-dontwarn sun.misc.Unsafe

# ********** END GUAVA **********

# ********** ADMOB **********

-keep,includedescriptorclasses public class com.google.android.gms.ads.** {
   public *;
}

-keep,includedescriptorclasses public class com.google.ads.** {
   public *;
}

# ********** END ADMOB **********

# ********** VUNGLE **********

-keep,includedescriptorclasses class com.vungle.** { public *; }
-keep,includedescriptorclasses class javax.inject.*
-keepattributes *Annotation*
-keepattributes Signature
-keep,includedescriptorclasses class dagger.*

# ********** END VUNGLE **********


# ********** BESPOKE **************

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class android.webkit.WebSettings
-dontwarn android.webkit.WebSettings
-keep,includedescriptorclasses class json.** {*; }
-keepnames class json.** {*; }
-keep class com.scribble.socketshared.messaging.IScrambledMessageReceiver
-dontwarn com.scribble.socketshared.messaging.IScrambledMessageReceiver
-dontwarn org.codehaus.**

-keep class com.facebook.ads.** { *; }
-dontwarn com.flurry.ads.**
-keep class com.flurry.android.** { *; }
-dontwarn com.flurry.android.**
-keep class com.inmobi.ads.** { *; }
-dontwarn com.inmobi.ads.**
-keep class com.inmobi.sdk.** { *; }
-dontwarn com.inmobi.sdk.**

-keep public @com.google.android.gms.common.util.DynamiteApi class * { *; }

# ********** END BESPOKE **************
Will Calderwood
  • 3,878
  • 2
  • 31
  • 55
  • please post your proguard file ? and why you're not using useImmersiveMode flag of AndroidApplicationConfiguration that enable 'Immersive mode'. – Abhishek Aryan Apr 05 '17 at 10:30
  • @AbhishekAryan Proguard added. I'm also using the immersive flag. I decided to test setting it explicitly too for clarity. Neither work. – Will Calderwood Apr 05 '17 at 10:56

2 Answers2

0

Moving the layout code into onWindowFocusChanged resolved the problem. I can't tell you why, but it works.

There is some example code here.

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
}
Community
  • 1
  • 1
Will Calderwood
  • 3,878
  • 2
  • 31
  • 55
0

must be because the '@TargetApi' and '@RequiresApi' annotation ads something through reflection. If you do not add a "keep" in proguard and it cannot see any path to that code it will remove the method.

So if you add the following to proguard:

-keep <the package where this code is in>

it should work.

p.streef
  • 2,952
  • 2
  • 21
  • 46