2

Long story short I have decided to play around with the new Google wearable stuff, so I opened up android studio and clicked the import from sample project. (mind you it does not matter what project I chose to import and have tried many of them)

I open the project and Everything is wrong because Android studio can't find the wearable imports... BUT it CAN build it to the watch just fine. So basically if I type

mApiClient = new GoogleApiClient.Builder(this);

The GoogleApiClient is made red because it "Cannot find the object"

import com.google.android.gms.common.ConnectionResult; <-- cannot find symbol common
import com.google.android.gms.common.api.GoogleApiClient; <-- cannot find symbol common
import com.google.android.gms.common.api.ResultCallback; <-- cannot find symbol common
import com.google.android.gms.wearable.MessageApi; <-- cannot find symbol MessageApi
import com.google.android.gms.wearable.MessageEvent; <-- cannot find MessageEvent
import com.google.android.gms.wearable.Node; <-- Cannot find Node
import com.google.android.gms.wearable.NodeApi; <-- Cannot find NodeApi
import com.google.android.gms.wearable.Wearable; <-- Cannot find Wearable

Now mind you... All of this builds... It just renders the editor useless due to the fact that it gives me no code assistance and is always telling me there are 100s of errors in the project. It is worse then notepad!

Things I have tried:

  • Uninstalling and reinstalling Android Studio (3 times now)

  • Uninstalling and reinstalling ALL of the android SDK's and extra tools

  • Clicking the button to Sync Project with Gradle (1000s of times)

  • Checking all Gradle files for the right packages (again, these are the sample code and it does build... so it has to be getting the right stuff...)

  • Threatening my PC with installing Hackintosh on it and then burning it. (at least 6 times now)

I have tried looking around but so far have not found anything that fixed it. any help would be much appreciated.

Thanks

EDIT:

(Delayed Application wearable sample code!)

gradle files:

Module Application:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}

apply plugin: 'com.android.application'

repositories {
    jcenter()
}

dependencies {
    compile "com.android.support:support-v4:21.0.2"
    compile "com.android.support:support-v13:21.0.2"
    compile "com.android.support:cardview-v7:21.0.2"
    compile 'com.google.android.gms:play-services-wearable:6.5.+'
    compile 'com.android.support:support-v13:21.0.+'
    wearApp project(':Wearable')
}

// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
    'main',     // main sample code; look here for the interesting stuff.
    'common',   // components that are reused by multiple samples
    'template'] // boilerplate code that is generated by the sample template process

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 21
    }

    sourceSets {
        main {
            dirs.each { dir ->
                java.srcDirs "src/${dir}/java"
                res.srcDirs "src/${dir}/res"
            }
        }
        androidTest.setRoot('tests')
        androidTest.java.srcDirs = ['tests/src']

    }

}

Module: Wearable

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}

apply plugin: 'com.android.application'



dependencies {


    compile 'com.google.android.gms:play-services-wearable:6.5.+'
    compile 'com.android.support:support-v13:21.0.+'
    compile 'com.google.android.support:wearable:1.1.+'
}

// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
    'main',     // main sample code; look here for the interesting stuff.
    'common',   // components that are reused by multiple samples
    'template'] // boilerplate code that is generated by the sample template process

android {
    compileSdkVersion 21

    buildToolsVersion "21.1.2"

    defaultConfig {
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt')
        }
    }
    sourceSets {
        main {
            dirs.each { dir ->
                java.srcDirs "src/${dir}/java"
                res.srcDirs "src/${dir}/res"
            }
        }
        androidTest.setRoot('tests')
        androidTest.java.srcDirs = ['tests/src']

    }
}

Hope this helps! hopefully I'm missing something stupid. On my mac I was able to import the sample code and run it (on my windows I can run it... just editing is going to be terrible.)

Marek Counts
  • 126
  • 3
  • 11
  • Post your `build.gradle`. – Jared Burrows Apr 02 '15 at 16:44
  • you can just import any of the wearable google code samples and get them but I can post all of them if you want. – Marek Counts Apr 02 '15 at 16:45
  • That made no sense. You are having trouble using the APIs. You need to post your `build.gradle` so I can see you have everything that you need. – Jared Burrows Apr 02 '15 at 16:54
  • I can use the api's... they just get highlighted red. and I have not writen one line of code... :) I have just been using googles sample code! Again, it runs fine... the editor just says it can't find them to import them. – Marek Counts Apr 02 '15 at 17:01
  • Oh! If the editor can't find them, and it works then you need to sync with Android studio again. – Jared Burrows Apr 02 '15 at 17:03
  • That is what I thought, but even when I hit the "Sync project with Gradle files" button it runs the gradle but does not fix it! I have never had this problem before. I'm currently running on Android studio 1.1. Sorry if I have not been clear! and thanks for the quick responses. – Marek Counts Apr 02 '15 at 17:05
  • You may have to hit File -> Invalidate Caches. Those are the two best ways to "force" it to get new caches. – Jared Burrows Apr 02 '15 at 17:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/74366/discussion-between-klaven-and-jared-burrows). – Marek Counts Apr 02 '15 at 18:15
  • You question has been answered many times on Stackoverflow. I tried to help you through it. I can't message right now. – Jared Burrows Apr 02 '15 at 18:21

1 Answers1

1

Sounds like it could just be a problem with your settings file somehow being corrupted. I would try reseting android studio to a default state.

See this question for steps - How to reset Android Studio

Community
  • 1
  • 1
Eagle11
  • 661
  • 8
  • 25