Cannot resolve symbol AppCompatActivity - Support v7 libraries aren't recognized?

后端 未结 25 1486
情深已故
情深已故 2020-12-07 18:39

I\'m trying to figure out why the heck my Android studio isn\'t recognizing the AppCompat v7 library correctly. The import statement below shows up as gray and says there\'s

相关标签:
25条回答
  • 2020-12-07 18:54

    AppCompatActivity was only added in version 22.1.0 of the support library. Before that it was called ActionBarActivity.

    You should use the same version for all of your support libraries. At the time of writing the latest version is 23.1.1 (you can find out the latest here https://developer.android.com/tools/support-library/index.html#revisions) so the dependencies section of your gradle file should look like this.

    implementation "com.android.support:support-v4:23.1.1"
    implementation "com.android.support:appcompat-v7:23.1.1"
    implementation "com.android.support:support-annotations:23.1.1"
    
    0 讨论(0)
  • 2020-12-07 18:54

    Replace the

    import android.support.v7.app.AppCompatActivity;
    

    with import androidx.appcompat.app.AppCompatActivity

    0 讨论(0)
  • 2020-12-07 18:55

    I went through the same situation and the fix was quiet easy. Just try removing the following import statement.

    import android.support.v7.app.AppCompatActivity;
    

    A message will be prompted with the below code, also asking you to press alt+enter.

    import androidx.appcompat.app.AppCompatActivity;
    

    Just press alt+enter and remove the previous import statement completely.

    Basically this problem arises in new version of Android Studio.

    0 讨论(0)
  • 2020-12-07 18:57

    File->Invalidate Caches/Restart works for me.

    0 讨论(0)
  • 2020-12-07 19:00

    I had these settings in 'gradle.properties'

    android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true

    It is better to use androidx library. So I changed all imports to androidx library and project compiled. visit http://developer.android.com/jetpack/androidx for information.

    0 讨论(0)
  • 2020-12-07 19:00

    After invalidating Cache, changing from

    import android.support.v7.app.AppCompatActivity;
    

    to

    import androidx.appcompat.app.AppCompatActivity;
    

    worked for me.

    0 讨论(0)
提交回复
热议问题