SupportMapFragment does not support AndroidX Fragment

后端 未结 10 1583
傲寒
傲寒 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:21

    Add the latest google map play services and that'll solve the problem.

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

    Google play services latest versions.

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

    Finally, here is the perfect answer:

    1. Add

      android.enableJetifier=true
      android.useAndroidX=true
      

      to your gradle.properties file.

    2. With Android Studio 3.2 or higher, migrate your project to AndroidX by selecting Refactor > Migrate to AndroidX from the menu.

    3. (Most important) Some of your project imports (used in classes) will need to be replaced by equivalent AndroidX libraries. Here you can find libraries and their equivalents. Replace any imports that refer to pre-AndroidX libraries one-by-one.

    Now you're good to go :-)

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

    This issue has already been reported to Google in the public issue tracker:

    https://issuetracker.google.com/issues/110573930

    I would suggest starring the feature request in the public issue tracker to add your vote and subscribe to further notifications from Google. Hopefully, Google will implement it in next versions of Android Maps SDK.

    Update

    Google has provided the following answer in the public issue tracker

    Hi all,

    As noted the Google Maps API is currently based off the support libraries and not AndroidX. Future versions of Google Maps API will certainly support AndroidX, but in the meantime, the following workaround will resolve the issue for you:

    • Use Android Studio 3.2 (currently preview) or higher

    • Ensure your build.gradle contains 'compileSdkVersion 28' (default for new AS 3.2 projects)

    • Include the following in your gradle.properties file (default for new AS 3.2 projects)

      android.useAndroidX=true

      android.enableJetifier=true

    Finally, for existing code referencing the support libraries, you can use the "Refactor -> Refactor to AndroidX" tool in Android Studio 3.2+ to automatically convert your code to use the new AndroidX packages.

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

    I had this issue too. It is really not nice, and for sure temporary, but that was the only way I could make it work. So at least it unblocked me until it gets fixed.

        final Object mf = getChildFragmentManager().findFragmentById(R.id.map);
        if (mf instanceof SupportMapFragment) {
            final SupportMapFragment smf = (SupportMapFragment) mf;
            // ...
        } else {
            //handle
        }
    

    It works both compiler time and runtime.

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

    I had your same problem, fixed by updating all imports to the last version available in the build.gradle file and adding

    android.enableJetifier=true
    android.useAndroidX=true
    

    To the gradle.properties

    this is the version of the maps package I imported

    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    

    You just have to fix some imports and then you're done

    I hope

    EDIT: even after editing what i just said, you will still have the error shown in the java but it compiles and runs without errors

    EDIT2: yesterday they suggested a workaround on the issuetracker https://issuetracker.google.com/issues/110573930#comment13

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

    I solved this by implementing the latest version of play-services-maps in my app's build.gradle file:

    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    
    0 讨论(0)
提交回复
热议问题