Unable to resolve imports from external dependencies in Android Studio 2.0 Preview 5 + Preview 6

After upgrading from the last Android Studio 2.0 preview to Preview 5 I’m having trouble with the imports from the android.support.wearable package.

Both the main app and Wear app builds and run just fine, but the editor in Android Studio complains that it can’t resolve the these imports

  • android weightSum not working properly
  • How MPAndroidChart display all xaxis values
  • List view snap to item
  • ListView in AlertDialog
  • Are there any recommendations for request codes values in Android?
  • Add local javadoc to local aar in Android-Studio
  • import android.support.wearable.activity.WearableActivity;
    import android.support.wearable.view.CircledImageView;
    import android.support.wearable.view.WearableListView;
    

    In the Wear module’s build.gradle I have the following dependencies:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile project(':common')
        compile 'com.android.support:appcompat-v7:23.1.1'
        compile 'com.android.support:support-v13:23.1.1'
    
        compile 'com.google.android.support:wearable:1.3.0'
        provided 'com.google.android.wearable:wearable:1.0.0'
        compile 'com.google.android.gms:play-services-wearable:8.4.0'
    }
    

    As I understand from http://developer.android.com/training/wearables/apps/always-on.html#EnableAmbient this should work when using the provided statement. And it has worked well until the Android Studio upgrade. Am I missing something?

    Update:

    This isn’t just a problem with the Wear library, it’s general for what seems to be any external dependency. (Topic originally was Unable to resolve package android.support.wearable in Android Studio 2.0 Preview 5.)

    It seems like the problem can occur at any time, but in practice it happens mostly whenever I do lotsa changes in a class (maybe changes to the imports?). Just now it suddenly was unable to resolve the imports of Play Services and Facebook ads (while still working for other dependencies).

    I accidentally found a workaround of the problem: If I open and build the project in Android Studio 1.5 which I also have installed, all the imports are fixed. Going back to Android Studio 2.0 I can continue programming without the imports becoming unresolvable for a long while.

    For anyone googling the problem, the error message in Android Studio is the usual Cannot resolve symbol ‘[package]’.

  • Unable to play some Youtube videos using YouTube Android Player API
  • Why is this not working sometimes?
  • How should I choose a video format to be played on Web, Android & iOS?
  • Mask ImageView with round corner background
  • Android app google maps showing grey tiles and not map!
  • Android Studio debugger highlights the wrong lines
  • One Solution collect form web for “Unable to resolve imports from external dependencies in Android Studio 2.0 Preview 5 + Preview 6”

    I had this problem even before with AS 1.5, the easiest way for me to fix it was to use the Terminal inside Android Studio and execute:

    ./gradlew assembleDebug
    

    This will work if you’re not using flavors if not just use the name of the flavor, for e.g:

    ./gradlew assembleFlavorNameDebug
    

    that should work too as a workaround without leaving your current instance of AS, and then the compiler recognizes your imports if everything is setup properly.

    For more references please look: http://tools.android.com/build/gradleplugin
    https://stackoverflow.com/a/21307568/799162

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.