【问题标题】:cannot access class android.support.v4.app.FragmentActivity when i migrate to androidx当我迁移到 androidx 时无法访问类 android.support.v4.app.FragmentActivity
【发布时间】:2019-02-04 16:44:33
【问题描述】:

我在

中出现错误“无法访问 android.support.v4.app.FragmentActivity 类”

GoogleApiClient.Builder(这个) .enableAutoManage(这个,这个) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build()

我迁移到 androidx 并使用库 实现('com.google.api-client:google-api-client-android:1.24.1')

我认为 GoogleApiClient 需要 android.support.v4.app.FragmentActivity,但我只有 androidx.appcompat.app.AppCompatActivity。路径不匹配。如何解决这个问题?

【问题讨论】:

  • 您好,我遇到了同样的问题,并且该响应没有为问题本身提供任何具体答案。你能修复或做任何工作吗?

标签: android kotlin android-jetpack


【解决方案1】:

您还需要更新 firebase 库的依赖项。
因为 enableAutoManage() 可以使用androidx.fragment.app.FragmentActivity 作为参数

第 0 步:我假设您已将项目迁移到 androidx
(如果你的项目还没有迁移到androidx,我强烈建议你在迁移到anroidx之前先备份,因为这是一个很大的过程)

第 1 步:备份您的项目(您可能需要更改一些代码)

第 2 步:转到您的 build.gradle(Module:app) 文件

第 3 步:更新 Firebase 依赖项的版本
(但要小心,有些方法在新版本中已弃用。所以,也许你需要更改很多代码)

implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.google.firebase:firebase-database:18.0.0'
implementation 'com.google.firebase:firebase-storage:18.0.0'
implementation 'com.google.firebase:firebase-core:17.0.0'
implementation 'com.google.firebase:firebase-messaging:19.0.1'
implementation 'com.google.firebase:firebase-crash:16.2.1'
implementation 'com.google.android.gms:play-services-auth:17.0.0'

【讨论】:

    【解决方案2】:

    第 1 步:
    检查您的依赖项是否正确迁移到 androidX,您可以在此处执行此操作 - https://developer.android.com/jetpack/androidx/migrate。在您的特定情况下 - 如果您使用 gradle 转到您的 gradle.build 文件,请确保 com.android.support:support-v4 现在是 androidx.legacy:legacy-support-v4:1.0.0 或更高版本。

    第 2 步:
    清理 IDE 缓存 - 如果您使用的是 Android Studio,请转到 File -> Invalidate Caches / Restart

    【讨论】:

      【解决方案3】:

      我的解决方案是可行的。

      https://stackoverflow.com/a/30627422/6709795

      对于一些使用 FragmentActivity 的库,开发者应该更新他们的项目

      【讨论】:

        猜你喜欢
        • 2018-11-10
        • 2020-01-27
        • 2019-06-27
        • 1970-01-01
        • 1970-01-01
        • 2019-07-08
        • 2019-11-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多