Thanks to SABANTO I replaced <fragment>
and <FrameLayout>
with <androidx.fragment.app.FragmentContainerView>
(replaced <FrameLayout>
only in activities). It works right in debug
build, but not in release
where it crashes.
android.view.InflateException: Binary XML file line #16 in com.example:layout/fragment_show_map: Binary XML file line #16 in com.example:layout/fragment_show_map: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #16 in com.example:layout/fragment_show_map: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: androidx.fragment.app.FragmentActivity$HostCallbacks: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
Looking at ClassNotFoundException when using androidx.fragment.app.FragmentContainerView and https://stackoverflow.com/a/61365688/2914140 I found that we should add in proguard-rules.pro
one or two lines, depending on what you have in XML file:
<androidx.fragment.app.FragmentContainerView
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
...
proguard-rules.pro:
#-------------------------------------------------
# JetPack Navigation
# This fixes:
# Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment androidx.navigation.fragment.NavHostFragment: make sure class name exists
# Caused by: androidx.fragment.app.FragmentActivity$HostCallbacks: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists
#-------------------------------------------------
-keepnames class androidx.navigation.fragment.NavHostFragment
-keepnames class com.google.android.gms.maps.SupportMapFragment
Don't forget to test your applications in release
build (and in debug
build, of course).