Back arrow missing from ActionBar on release build but not debug build

Viewed 385

When I move from the debug build of my Android app to the release build, the back navigation arrow in the ActionBar gets replaced by the hamburger (for want of a better name), which is not what I want.

Here is the debug build, with the back arrow as it should be.

enter image description here

And here is the release build, with the hamburger.

enter image description here

It's the default back arrow that appears when the user navigates to a fragment using Jetpack Navigation Component, in an AppBarLayout that looks like this:

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/AppTheme.PopupOverlay">

            </androidx.appcompat.widget.Toolbar>

        </com.google.android.material.appbar.AppBarLayout> 

When I turn minification off in the release version, the back arrow reappears. So it's something to do with minification.

But what do I tell ProGuard to keep? I tried all this but none of it helped:

-keep class androidx.appcompat.widget.Toolbar{}
-keep class androidx.navigation.NavController{}
-keep class androidx.navigation.Navigation{}
-keep class androidx.navigation.ui.AppBarConfiguration{}
-keep class androidx.navigation.ui.navigateUp.** {*;}
-keep class * extends android.support.v4.app.Fragment{}
-keep class com.google.android.material.appbar.AppBarLayout{}

Thanks in advance!

2 Answers

I had the same problem and found it in Google Issue Tracker. Someone had a solution there :

-keep class androidx.appcompat.graphics.drawable.DrawerArrowDrawable { *; }

Apparently, the back arrow drawable (DrawerArrowDrawable) is obfuscated by Proguard by default. This solved the problem for me and I don't have any of your other Proguard rules.

And you should also replace android.support.v4.app.Fragment with androidx.fragment.app.Fragment (although it's not related to your question)

When you're using:

  • androidx navigation library 2.2.0
  • disabled androidx jetifier

you'll encounter this problem because the proguard rule still referenced the Support library version.

It is fixed in Navigation 2.2.1 and later(see https://issuetracker.google.com/issues/147610424)

Related