1

I am building a sample Android Wear App using Android Studio, so I started by creating new Wear project with API 20: Android 4.4 (KitKat Wear). When I build the project it gives me the following error

Error:(8, 34) error: cannot find symbol class WatchActivity
Error:(12, 5) error: method does not override or implement a method from a supertype
Error:(14, 9) error: cannot find symbol variable super
Error:(15, 9) error: cannot find symbol method setContentView(int)
Error:(16, 52) error: cannot find symbol method findViewById(int)

Following are my source

package com.example.rahul.myapplication;   
import android.os.Bundle;
import android.support.wearable.activity.WatchActivity;
import android.support.wearable.view.WatchViewStub;
import android.util.Log;
import android.widget.TextView;

public class MyActivity  extends WatchActivity {

    private TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
        stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
            @Override
            public void onLayoutInflated(WatchViewStub stub) {
                mTextView = (TextView) stub.findViewById(R.id.text);
                Log.d(TAG, "TextView: " + mTextView.getText() + " view=" + mTextView);
            }
        });
    }
}

Also I am getting the message from the Intellisense "unused import statement" when I place cursor at the following line

  import android.support.wearable.activity.WatchActivity;

I also tried cleaning the project and again rebuild it, but its not working. Thanks in advance.

Content of AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.rahul.myapplication" >

    <uses-feature android:name="android.hardware.type.watch" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.DeviceDefault" >
        <activity
            android:name=".MyActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Rahul Vishwakarma
  • 996
  • 5
  • 17
  • 35

1 Answers1

0

Your app module's build.gradle file should look like this:

    apply plugin: 'com.android.application'

    android {
      compileSdkVersion 21
      buildToolsVersion "21.1.2"

      defaultConfig {
          applicationId "com.example.rahul.myapplication"
          minSdkVersion 21
          targetSdkVersion 21
          versionCode 1
          versionName "1.0"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }

  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.google.android.support:wearable:1.1.0'
      compile 'com.google.android.gms:play-services-wearable:6.5.87'
  }
IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147