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;
}
}