6

I am trying to debug the behaviour of Android Studio regarding syntax highlighting and definition following for files in the java SDK folder. The project builds fine, but Android Studio itself will not behave consistent with this in the editor.

I have read the responses in the following link in detail and it does not fix the problem: Android Studio says "cannot resolve symbol" but project compiles

I have tried all those solutions, including "Invalidate and Restart", Clean, Rebuild, checking the sdk directory is correct, checking the all the dependencies are present, resyncing the gradle, changing the compileSdkVersion to the minSdkVersion and it still refuses to follow expected behaviour.

Android studio is highlighting some methods and symbols in red, and will not follow them when I hit CTRL+B on them (go to definition). However when I simply open the file, the methods and symbols are in there fine.

For example, for sdk\sources\android-14\..., in a RingtonePreference class, in ...android\preference\RingtonePreference.java, there is a line:

PreferenceFragment owningFragment = getPreferenceManager().getFragment();

The method getFragment() is highlighted red for "cannot resolve method".

I then hit CTRL+B on getPreferenceManager(), which jumps to:

public PreferenceManager getPreferenceManager() {
    return mPreferenceManager;
}

I then hit CTRL+B on PreferenceManager, which jumps to the file ...android\preference\PreferenceManager.java. In that file there is the following:

PreferenceFragment getFragment() {
    return mFragment;
}

It is beyond me what on earth else Android Studio needs to function as would be expected. What am I doing wrong here?

For reference, this is how my project is using the RingtoneManager, but there is no "cannot resolve" Android Studio red highlighting in this:

import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.preference.RingtonePreference;
import android.util.AttributeSet;

public class ExtRingtonePreference extends RingtonePreference {
private String mInitialRingtone;

public ExtRingtonePreference(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

public ExtRingtonePreference(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public ExtRingtonePreference(Context context) {
    super(context);
}

@Override
protected Uri onRestoreRingtone() {
    if(mInitialRingtone == null) {
        return null;
    } else {
        return Uri.parse(mInitialRingtone);
    }
}

public void setInitialRingtone(String initialRingtone) {
    this.mInitialRingtone = initialRingtone;
}

}
InsaneCat
  • 2,115
  • 5
  • 21
  • 40
  • show your code. – Manoj Perumarath Mar 30 '17 at 06:57
  • whats the error there – Ranjit Mar 30 '17 at 06:57
  • As mentioned, it compiles, there is no build error. This is an Android Studio red highlight editor error. OK I've add how my code is using the RingtonePreference. –  Mar 30 '17 at 07:03
  • Crazy huh. There's just nothing I can do. Doesn't matter how many fixes I make, instructions I follow, logic or reason I use, there's always one more block to stop it working. The gauntlet never ends. –  Mar 30 '17 at 15:05
  • What version of Android Studio are you using? – stefan222 Jun 15 '17 at 17:50
  • Related post - [Android Studio suddenly cannot resolve symbols](https://stackoverflow.com/q/21100688/465053) – RBT Aug 06 '18 at 00:02
  • It's 2022 and the issue still exists with Android source code, even for the files that are present in the android.jar – Pratzz Jul 09 '22 at 14:43

1 Answers1

3

Even i had the same problem after changing the git branch, the way i fixed it is by changing in app/build.gradle (e.g. add blank line) and IDE ask to Sync** the project and after syncing it got fixed.

Nishant Pardamwar
  • 1,450
  • 12
  • 16