ClassNotFoundException when using androidx.fragment.app.FragmentContainerView

前端 未结 2 1787
旧时难觅i
旧时难觅i 2020-12-20 14:46

I\'m trying to transition from using a FrameLayout to using FragmentContainerView and from the tutorials I\'ve seen, it should be pretty easy. Howe

相关标签:
2条回答
  • 2020-12-20 14:59

    That's in androidx.fragment 1.2.0 or higher:

    implementation "androidx.fragment:fragment:1.2.0"
    
    0 讨论(0)
  • 2020-12-20 15:21

    Thanks to @Salam El-Banna and his link, I found that in case an application crashes in release build we should add in proguard-rules.pro (one or two lines, depending on android:name in <FragmentContainerView>:

    #-------------------------------------------------
    # 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.Fragment$InstantiationException: 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
    

    You won't need implementation 'androidx.fragment:fragment:1.2.5' if your applicatin crashes in release build.

    0 讨论(0)
提交回复
热议问题