0

I am trying to get GPS coordinates in Android Wear Moto 360. Below is my MainActivity class code for the same. I am getting exception at Line marked 1. Can someone tell me why this error occurs?

public class MainActivity extends Activity implements
        LocationListener,
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener {

    private static String TAG = "MainActivity";

    private TextView mTextView;
    private GoogleApiClient mGoogleApiClient;

    private static final long UPDATE_INTERVAL_MS = 2000;
    private static final long FASTEST_INTERVAL_MS = 1000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        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);
            }
        });

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(LocationServices.API)
                .addApi(Wearable.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();-------------------------------------------1
    }

    @Override
    protected void onResume() {
        super.onResume();
        mGoogleApiClient.connect();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mGoogleApiClient.disconnect();
    }

    private boolean hasGPSSupport() {
        return getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
    }

    @Override
    public void onLocationChanged(Location location) {
        Log.d(TAG,"Latitude=>"+location.getLatitude()+",Longitude=>"+location.getLongitude());
    }

    @Override
    public void onConnected(@Nullable Bundle bundle) {
        if(hasGPSSupport()) {
            LocationRequest locationRequest = LocationRequest.create()
                    .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                    .setInterval(UPDATE_INTERVAL_MS);

            //PackageManager packageManager = context.getPackageManager();

            int hasPermission = getPackageManager().checkPermission(Manifest.permission.ACCESS_FINE_LOCATION,getPackageName());

            if(hasPermission == PackageManager.PERMISSION_GRANTED) {
                LocationServices.FusedLocationApi
                        .requestLocationUpdates(mGoogleApiClient,locationRequest,this)
                        .setResultCallback(new ResultCallback<Status>() {
                            @Override
                            public void onResult(@NonNull Status status) {
                                if(status.isSuccess()) {
                                    Log.d(TAG, "Successfully requested location updates");
                                } else {
                                    Log.e(TAG,
                                            "Failed in requesting location updates, "
                                                    + "status code: "
                                                    + status.getStatusCode()
                                                    + ", message: "
                                                    + status.getStatusMessage());

                                }
                            }
                        });


            }


        }
    }

    @Override
    public void onConnectionSuspended(int i) {
        Log.d(TAG,"Location Suspended");
    }

    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
        Log.d(TAG,"Location Connection Failed");
    }
}

Exception Trace is as follows.

java.lang.NoSuchMethodError: No static method zzaa(Ljava/lang/Object;)Ljava/lang/Object; in class Lcom/google/android/gms/common/internal/zzab; or its super classes (declaration of 'com.google.android.gms.common.internal.zzab' appears in /data/data/com.example.services.sample/files/instant-run/dex/slice-com.google.android.gms-play-services-basement-9.4.0_d850e27da4d3b64df6419dc0ff52b2f0e43e7b6f-classes.dex)
at com.google.android.gms.wearable.internal.zzbp.<init>(Unknown Source)
at com.google.android.gms.wearable.internal.zzbp.<init>(Unknown Source)
at com.google.android.gms.wearable.Wearable$1.zza(Unknown Source)
at com.google.android.gms.wearable.Wearable$1.zza(Unknown Source)
at com.google.android.gms.common.api.GoogleApiClient$Builder.zza(Unknown Source)
at com.google.android.gms.common.api.GoogleApiClient$Builder.zzaoi(Unknown Source)
at com.google.android.gms.common.api.GoogleApiClient$Builder.build(Unknown Source)
at com.example.services.sample.MainActivity.onCreate(MainActivity.java:55)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
praneel
  • 241
  • 2
  • 14
  • which is line 55 of your MainActivity? also please post your Wear app's build.gradle file – Sterling Aug 02 '16 at 23:07
  • I'd venture a guess and say 55 is `new GoogleApiClient.Builder(this).build()`. Anyway, looks like something's incorrectly linked, try rebuilding and double-check your dependencies. Gms might be invoking a method determined at runtime, which is not available perhaps because you linked incompatible versions of gms libs. – Vasiliy Kulakov Aug 10 '16 at 03:15
  • Sorry for the delayed response. The issue is because of http://stackoverflow.com/questions/38735072/connection-failed-connectionresultstatuscode-service-version-update-required/38736169#38736169 – praneel Aug 10 '16 at 23:49

1 Answers1

0

It is a generic problem with com.google.android.gms:play-services-wearable. So one way to solve it is change

compile 'com.google.android.gms:play-services-wearable:9.0.0'

to

compile 'com.google.android.gms:play-services-wearable:+'
Unheilig
  • 16,196
  • 193
  • 68
  • 98
emir
  • 321
  • 3
  • 6