簡體   English   中英

遷移到androidx時無法訪問類android.support.v4.app.FragmentActivity

[英]cannot access class android.support.v4.app.FragmentActivity when i migrate to androidx

我在中出現錯誤“無法訪問類android.support.v4.app.FragmentActivity”

GoogleApiClient.Builder(this).enableAutoManage(this,this).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。 路徑不匹配。 如何解決這個問題?

第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,請轉到“文件”->“使緩存無效/重新啟動”

您還需要更新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'

我我的解決方案將是可行的。

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

對於某些使用FragmentActivity的庫,開發人員應更新其項目

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM