SupportMapFragment does not support AndroidX Fragment

后端 未结 10 1584
傲寒
傲寒 2020-11-30 11:04
import com.google.android.gms.maps.SupportMapFragment;
import androidx.fragment.Fragment;
...
private SupportMapFragment mMapFragment;
...
mMapFragment = (SupportMap         


        
相关标签:
10条回答
  • 2020-11-30 11:33

    Make sure that in the fragment java class you import androidx.fragment.app.Fragment; and in the java class from where you refer to this particular fragment, you also import Fragment the same way i.e. import androidx.fragment.app.Fragment;

    After that to get a reference of the fragment we created, use getSupportFragmentManager().findFrgmentById(R.id.fragment_id).

    To summarise, make sure you have the same import in all concerned Java or Kotlin classes.

    0 讨论(0)
  • 2020-11-30 11:35

    Android Jetifier unfortunately did not work for me. I solved this problem by copying SupportMapFragment to my project and changing the parent. During this procedure I also had to make copy of class called zzak (renamed it to SupportMapCallback).

    Please note that you should take this solution as temporary cause right now it's independent on updates of Play Services library. If you also need to migrate to AndroidX as soon as possible then feel free to grab it from here:

    https://gist.github.com/mroczis/3988e390a8b04fad3c8714181718cd60

    0 讨论(0)
  • 2020-11-30 11:39

    For this to work you must be on the following version or higher:

    com.google.android.gms:play-services-maps:16.0.0

    After migrating to AndroidX, be sure to invalidate caches and restart to get rid of all the red errors on the Google Maps dependencies.

    0 讨论(0)
  • 2020-11-30 11:48

    You need to update the Android studio version to more than 3.2 it's still a beta version. The problem is Google Maps library is using Fragment class from the support library so it's conflicted with androidX, so Android Studio 3.2 version make refactor all dependencies to use androidX classes.

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