SupportMapFragment不支持AndroidX Fragment [英] SupportMapFragment does not support AndroidX Fragment

查看:419
本文介绍了SupportMapFragment不支持AndroidX Fragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import com.google.android.gms.maps.SupportMapFragment;
import androidx.fragment.Fragment;
...
private SupportMapFragment mMapFragment;
...
mMapFragment = (SupportMapFragment) form.getSupportFragmentManager().findFragmentByTag(MAP_FRAGMENT_TAG);

此处,IDE显示错误, androidx.fragment.Fragment 无法转换为 SupportMapFragment (扩展了android.support.v4.app.Fragment)

Here, the IDE shows an error that androidx.fragment.Fragment cannot cast to SupportMapFragment (which extends android.support.v4.app.Fragment)

我正在使用play-services-maps的15.0.1版本和AndroidX库的1.0.0-beta01版本.

I'm using the version 15.0.1 of the play-services-maps and version 1.0.0-beta01 of the AndroidX libraries.

我在发行说明中未找到AndroidX之后对SupportMapFragment的任何更新: https ://developers.google.com/maps/documentation/android-sdk/releases

I have not found any updates to SupportMapFragment after AndroidX in the release notes: https://developers.google.com/maps/documentation/android-sdk/releases

在任何人问之前,formForm类的实例,该类扩展了AppCompatActivity(来自AndroidX)

Before anyone asks, form is an instance of Form class which extends AppCompatActivity (from AndroidX)

推荐答案

此问题已通过公共问题跟踪器报告给Google:

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

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

我建议在公共问题跟踪器中为功能请求加注星标,以添加您的投票并订阅来自Google的进一步通知.希望Google可以在下一版的Android Maps SDK中实现它.

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.

Google在公共问题跟踪器中提供了以下答案

Google has provided the following answer in the public issue tracker

大家好,

如前所述,Google Maps API当前基于支持库而不是AndroidX.将来的Google Maps API版本肯定会支持AndroidX,但与此同时,以下解决方法将为您解决问题:

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:

  • 使用Android Studio 3.2(当前为预览版)或更高版本

  • Use Android Studio 3.2 (currently preview) or higher

确保您的build.gradle包含"compileSdkVersion 28"(新的AS 3.2项目的默认设置)

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

在gradle.properties文件中添加以下内容(新AS 3.2项目的默认设置)

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

android.useAndroidX = true

android.useAndroidX=true

android.enableJetifier = true

android.enableJetifier=true

最后,对于引用支持库的现有代码,您可以使用重构->".重构为AndroidX"; Android Studio 3.2及更高版本中的工具,可自动将您的代码转换为使用新的AndroidX软件包.

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.

这篇关于SupportMapFragment不支持AndroidX Fragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆