Android Studio and android.support.v4.app.Fragment: cannot resolve symbol

后端 未结 22 2710
眼角桃花
眼角桃花 2020-12-01 06:03

I am tryng out Android Studio instead of Eclipse. I install it and then start a completely new project and follow the wizard. I add no code of my own.

Then, I right-

相关标签:
22条回答
  • 2020-12-01 06:27

    DID NOT WORK:

    I have already had the following dependency in my build.gradle

    implementation 'com.android.support:support-v13:26.0.2'
    

    I have tried all of the following,

    • Invalidate Caches/Restart
    • Sync project with gradle files
    • Clean project
    • Rebuild project
    • gradlew clean

    But, none of them worked for me.

    SOLUTION:

    Finally, I solved it by deleting "/.idea/libraries", and then synced with gradle and built again.

    0 讨论(0)
  • 2020-12-01 06:29

    Try this may will help you.Go to "File" -> "Invalidate Caches...", and select "Invalidate and Restart" option to fix this.

    0 讨论(0)
  • 2020-12-01 06:29

    Android studio has option to manage dependencies. Follow path.

    1. Click on File, then select Project Structure
    2. Choose Modules "app"
    3. Click "Dependencies" tab
    4. Click on the + sign, choose Library Dependencies
    5. Select support-v4 or other libraries as needed and click OK

    FYI check link stackoverflow.com/a/33414287/1280397

    0 讨论(0)
  • 2020-12-01 06:29

    Hrrm... I dont know how many times this has happend so far: I test, try, google, test again and mess around for hours, and when I finally give up, I go to my trusted Stackoverflow and write a detailed and clear question.

    When I post the question, switch over to the IDE and boom - error gone.

    I can't say why its gone, because I change absolutely nothing in the code except for that I already tried as stated above. But all of a sudden, the compile error is gone!

    In the build.gradle, it now says:

    dependencies {
        compile "com.android.support:appcompat-v7:18.0.+"
    }
    

    which initially did not work, the compile errors did not go away. it took like 30 min before the IDE got it, it seems... hmm...

    === EDIT === When I view the build.gradle again, it has now changed and looks like this:

    dependencies {
        compile 'com.android.support:support-v4:18.0.0'
        compile "com.android.support:appcompat-v7:18.0.+"
    }
    

    Im not really sure what the appcompat is right now.

    0 讨论(0)
  • 2020-12-01 06:29

    I was facing the same issue. As it turns out in my build.gradle file there was this :

    configurations {
        all*.exclude group: 'com.android.support'
    }
    

    Removing that fixed my issue. So guys, if doing all that and still your issue is not fixed, look for any exclude keywords in your gradle file.

    0 讨论(0)
  • 2020-12-01 06:30

    replace this line of code

    import android.support.v4.app.FragmentActivity;
    

    with

    import androidx.fragment.app.FragmentActivity;
    

    and you are done.

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