Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
758 views
in Technique[技术] by (71.8m points)

gradle - Android Studio project can't resolve ActionBarSherlock imports

I have an Android Studio project which has a dependency on ActionBarSherlock set in build.gradle:

dependencies {
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile project(':Core')
    compile fileTree(dir: 'libs', include: '*.jar')
}

The project builds successfully on the command line with gradle assemble assembleDebug and also builds and runs just fine from the IDE when I press ctrl+D. When I view some of the Sherlock-related source files in the IDE, though, the file is full of red error notifications, starting with this line:

import com.actionbarsherlock.app.SherlockPreferenceActivity;

The tooltip that pops up says

Cannot resolve symbol 'SherlockPreferenceActivity'

and none of the context-sensitive stuff such as auto-completion is available.

I had tried the File > Invalidate Caches/Restart > Invalidate and Restart menu option, which doesn't seem to have cured the problem. How can I get Android Studio to correctly resolve this import?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First sync your project with gradle and check if it gives some error, if it worked fine go back and try importing something from actionbarsherlock library in any of your class.

If above step doesn't help. Check once Your_Project/your_module/build/exploded-bundles/ComActionbarsherlock.../classes.jar exists or not.

Then go for this :

Clean your project from Build > Clean Project, sync your project with gradle than check this for reference.

Import Google Play Services library in Android Studio

Or Follow the steps :

  • Exit Android Studio
  • Delete all the .iml files and files inside .idea folder from your project
  • Relaunch Android Studio and wait till the project synced completely with gradle

This is bug in Android Studio 0.4.2 and fixed for Android Studio 0.4.3 release.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...