简体   繁体   中英

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

I have error "cannot access class android.support.v4.app.FragmentActivity " in

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

I migarete to androidx and use library implementation('com.google.api-client:google-api-client-android:1.24.1')

I think GoogleApiClient require android.support.v4.app.FragmentActivity, but i have only androidx.appcompat.app.AppCompatActivity. Paths not match. How to resolve this problem?

Step 1:
Check if your dependencies migrated correctly to androidX, which you can do here - https://developer.android.com/jetpack/androidx/migrate . In your particular case - if you're using gradle go to your gradle.build file make sure com.android.support:support-v4 is now androidx.legacy:legacy-support-v4:1.0.0 or higher.

Step 2:
Clean IDE cache - if you're using Android Studio go to File -> Invalidate Caches / Restart

You need also update your dependencies of firebase library.
Because enableAutoManage() could useandroidx.fragment.app.FragmentActivity as parameter

Step 0: I assume that you've migareted your project to androidx
(If you haven't migareted your project to androidx, I strongly suggest you backup before you migarete it to anroidx. Because it is a large process)

Step 1: backup your project (you probably will need to change some codes)

Step 2: go to your build.gradle(Module:app) file

Step 3: update the version of your firebase dependencies
(but be careful, some methods are deprecated in new version. So, maybe you will need change a lot of code)

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'

I my solution this will be work.

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

For some of library, what use FragmentActivity, developers should updated their projects

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM