2

Apparently after upgrading Android Support Library to version 22.2.0 now I cannot add these:

import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentPagerAdapter; 
import android.support.v4.view.ViewPager;

I tried these and none are working:

  1. File->Invalidate Caches and Restart
  2. Sync Gradle Files
  3. Change Build Tools Version

Could this be a bug? I put back to version 18.0.0 for time being to avoid this error. And everything works fine again.

I am using

  1. Android Studio 1.2.1.1
  2. Android SDK Tools 24.3
  3. Android SDK Platform-tools 22
  4. Android SDK Build-tools 22.0.1
  5. Android Support Repository 15
  6. Android Support Library 22.2
stuckedunderflow
  • 3,551
  • 8
  • 46
  • 63
  • See if [this](http://stackoverflow.com/questions/20386331/android-studio-and-android-support-v4-app-fragment-cannot-resolve-symbol) question might help you. – Prudhvi Jun 03 '15 at 16:50
  • Is your gradle build succeeding? My guess is that you haven't updated the support library in your SDK Manager. – Bryan Herbst Jun 03 '15 at 16:54
  • @Tanis.7x Everything is up to date. I have edited my question and put more specific version I used. – stuckedunderflow Jun 03 '15 at 17:31
  • And is your gradle build succeeding? If not, what messages are you getting from it? – Bryan Herbst Jun 03 '15 at 18:08
  • 1
    EDIT: I had the *exact* same problem. Latest everything, reset cache, could NOT resolve v4. Funny thing.. run a build (Ctrl+F9), and suddenly the 'sea of red' goes away. Expected that it wouldn't have built, but then it did.. sigh~ – Matthew Housser Jun 04 '15 at 01:47
  • @Tanis.7xYes I did not see any errors coming on Event Log and Gradle Console. The red mark error only show on the Java class. – stuckedunderflow Jun 04 '15 at 01:48
  • @MatthewHousser Good news. Your solution works. I never knew we need to "Make Project/Module" manually. Everything works automatically since Android Studio. Such as save file, etc. But in this case we must manually "Make Project/Module". In my case Ctrl+Shift+F9. Please give your answer below. I'll accept it. – stuckedunderflow Jun 04 '15 at 01:55
  • Posted my answer below (same thing) :) – Matthew Housser Jun 04 '15 at 04:35
  • I have the same problem, except for the difference that now the sea of red marks (cannot resolve symbol) are only for the classes from Google Play Services (e.g. GoogleMap, LatLng) and v4 Support Library (e.g. LocalBroadcastManager, FragmentActivity). For all other classes, the red marks disappeared after trying out the workarounds mentioned. Build always succeeds and I can run the App and all features work fine 100%. I use all latest tools and libraries. Really looking forward to get rid of these annoying sea of red marks. – Jim C Jun 24 '15 at 07:11

2 Answers2

4

I had the exact same problem. Latest everything, reset cache, could NOT resolve v4. Funny thing.. run a build (Ctrl+F9), and suddenly the 'sea of red' goes away. Expected that it wouldn't have built, but then it did.. sigh!

Matthew Housser
  • 1,012
  • 9
  • 21
0

Since the support library is an AAR, it has to be used in a successful build so it gets "exploded". Android Studio cannot use the AAR as a pure dependency. So in short, the solution is to build the project with Gradle at least once.

David Burström
  • 1,592
  • 14
  • 14