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

查看:39
本文介绍了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

最后,对于引用支持库的现有代码,您可以使用Refactor ->"重构为 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天全站免登陆