Android Studio says there isnt google play services - android

I'm developing an android project and until today it was fine. It gets user data and creates a connection via websocket to server. I started the project to check something and it worked normally and 2 minutes later I started t again it stopped getting user location and it said there is a problem with google play sevices
W/GoogleApiManager: The service for com.google.android.gms.common.internal.service.zap is not available: ConnectionResult{statusCode=SERVICE_INVALID, resolution=null, message=null}
W/GooglePlayServicesUtil: com.example.airboxproject requires the Google Play Store, but it is missing.
W/GoogleApiManager: The service for com.google.android.gms.common.internal.service.zap is not available: ConnectionResult{statusCode=SERVICE_INVALID, resolution=null, message=null}
I wouldn't get this messages before but now it keeps producing these error and I don't know what to do. I deleted the emulator and uploaded a new one and now there is difference in it GUI. I have to submit this project in less than 48 hours and I'm having problems with it.
Edit: It shows some parts of the GUI as Android 2 even though it is Android 11

Create a new emulator from Android Studio and verify it has Google Play Installed. Tools > Device Manager > Create Device. Select a device which has the Google Play logo under the Play Store column.
And/or verify the correct emulator is selected next to the run button at the top of Android studio.
It is also best practice to check if the device supports Google Play Services.
Uncomment if (googleAPI.isUserResolvableError(result)) conditional for an automatic dialog to the user explaining the error
public static boolean isPlayServicesInstalled(Context context) {
GoogleApiAvailabilityLight googleAPI = GoogleApiAvailabilityLight.getInstance();
int result = googleAPI.isGooglePlayServicesAvailable(context);
//This call shows a dialog not controlled by the app (dialog text controlled by Firebase package)
// so do not show this as if self handled
// if(googleAPI.isUserResolvableError(result)) {
// Log.v(LOG_TAG, "Google Play Services are not installed");
// GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
// Objects.requireNonNull(googleApiAvailability.getErrorDialog(frag, result, 6)).show();
// }
return result == ConnectionResult.SUCCESS;
}
https://developers.google.com/android/reference/com/google/android/gms/common/GoogleApiAvailability

Related

How to fix apiAvailability.isGooglePlayServicesAvailable misbehaving on emulator

I'm developing an application that uses google maps and I encountered a weird problem when trying to launch my app on emulator - it (obviously) doesn't work and shows an error message "MyApp having trouble with Google Play services. Please try again".
To solve this problem, I decided to check the availability of Google Play Services (as recommended in this guide by Google https://developers.google.com/android/guides/setup). And.. it doesn't work as intended.
So, here's the code I use to check the availability of Google Play Services and the result code for the emulator is always SUCCESS, even though it doesn't have the desired version installed.
private fun checkPlayServices(): Boolean {
val apiAvailability = GoogleApiAvailability.getInstance()
val resultCode = apiAvailability.isGooglePlayServicesAvailable(activity)
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this.activity, resultCode, 9000)
.show()
} else {
Timber.tag("tag").e("This device is not supported.")
}
return false
}
return true
}
In logs I can clearly see the message
W/GooglePlayServicesUtil: Google Play services out of date. Requires 13400000 but found 13280022
And I cannot comprehend why Google says that there are google play services installed on a version without google play service
I expected this function to return some kind of error and show the correct dialog, but it just returns success for the emulator.
Though, if I run it on a version WITHOUT google API, it shows the error correctly about not having google play services completely.
So, my question is - is it a problem with emulator or API and will it misbehave like this on normal phones or this is just an emulator bug (feature)?

"No acceptable module found" on Android emulators using com.google.android.gms play-services 9.2.0

I have recently updated to com.google.android.gms:play-services 9.2.0 and am attempting to use the new Chromecast library and Firebase Analytics but am receiving the error "com.google.android.gms.internal.zzsj$zza: No acceptable module found. Local version is 0 and remote version is 0." in the Activity onCreate method at com.google.android.gms.cast.framework.CastContext.(Unknown Source). Any ideas if this is due to the Cast functionality not working with the emulators or if it's a version issue? The emulators I am testing with are running 5.0 and 5.1.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
setupCastListener();
mCastContext = CastContext.getSharedInstance(this);
mCastSession = mCastContext.getSessionManager().getCurrentCastSession();
mCastContext.getSessionManager().addSessionManagerListener(mSessionManagerListener, CastSession.class);
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
}
Thanks
The version of Play Services on your emulator does not support 9.2.0. At this time, I don't think any of the emulator images support 9.2.0. Your options are to downgrade to 9.0.2, or run on a real device until an updated emulator image is released.
If you look carefully at your logcat output you should see a message like this:
W/GooglePlayServicesUtil: Google Play services out of date. Requires 9256000 but found 9080030
You can see the GPS version number the emulator is using by going to Settings/Apps, finding Google Play Services, and tapping on it to get the App Info.
You can get the GPS version number from code by calling GoogleApiAvalability.GOOGLE_PLAY_SERVICES_VERSION_CODE.
This answer contains some related information about emulator versions.
Update for Adrian Cretu's questions regarding real devices
My experiments indicate that it is possible for a Cast app running on a real device to detect an older version of Play Services and initiate resolution processing. I experimented with the CastVideos sample app. My solution may not be the best, but demonstrates the concept. I created a new activity that runs on launch and checks the availability of Play Services. I changed the manifest to make this activity the launcher activity instead of VideoBrowserActivity:
public class InitActivity extends AppCompatActivity {
private static final String TAG = "InitActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GoogleApiAvailability googAvail = GoogleApiAvailability.getInstance();
int status = googAvail.isGooglePlayServicesAvailable(this);
Log.i(TAG, "onCreate: Status= " + googAvail.getErrorString(status));
googAvail.makeGooglePlayServicesAvailable(this)
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
Log.i(TAG, "onComplete: Done");
if (task.isSuccessful()) {
Log.i(TAG, "onComplete: Starting VideoBrowser");
startActivity(new Intent(InitActivity.this, VideoBrowserActivity.class));
finish();
} else {
Log.e(TAG, "onComplete: RESOLUTION FAILED");
}
}
});
}
}
If Play Services is present, up to date, and enabled, the task that checks for availability completes immediately and starts VideoBrowserActivity, the original launch activity. Otherwise, a dialog is presented telling the user that Play Services must be upgraded, and after the user accepts, the Play Store is opened and the user can initiate a download of the latest version.
I was unable to find a way to cleanly transition back to the VideoBrowserActivity. I had to restart the app. With more work, I think a clean recovery from out-of-date Play Services is possible. At least something better than an app crash.
This crash also happens on real devices with non-updated GPS. I am using Google Cast SDK v3 and GPS 9.2.0
I didn't see anywhere mentioned that the device actually requires GPS 9.2.0 in order for the Cast v3 to work. What is the workaround or at least a solution for the app not to crash on startup?
When I updated the google play developer services app, I was able to solve it.

How do I determine the actual build number for Google Play Services on Android?

NOTE: I am not trying to update google play services in the emulator. I do not care that it is out of date. I mentioned it only to show that somehow logcat is reporting the actual build number, which I wish to access in the app.
Similar, but not the same as, How can I determine the version of Google Play services?
An app I'm developing using Android Studio 1.2.2 is experiencing a problem if the latest Google Play Services is not installed on the device, yet GoogleApiAvailability is not reporting a problem and so the code instructing the user to update is never called. If I manually tell the users to update play services in the play store with a manual link to https://play.google.com/store/apps/details?id=com.google.android.gms&hl=en, there is an update available, and the app functions correctly after they install it.
However I am unable to find a way to determine that the user needs to update via application code or the gradle build file.
In the gradle file I've specified: compile 'com.google.android.gms:play-services:7.5.0' and this is the latest version as far as I know. Android Studio does not indicate that I should update this line to a newer version.
The SDK manager reports the play services I have installed is "rev 25", and no update is available.
When I test in an emulator, the code works correctly, and in logcat I see the message: "W/GooglePlayServicesUtil: Google Play services out of date. Requires 7571000 but found 6774470". This is normal for the emulator since they haven't released new images yet, but it provides an interesting clue.
Is there a way to get this build number reported in item 3 above, programatically? If so, I could compare against that rather than using the isgooglePlayServicesAvailable method of GoogleApiAvailability -- which I'm already using, but is reporting success on devices that need an update.
I've managed to do a little digging and answer my own question. The following code will do what I (and perhaps others) want.
PackageInfo pi = getPackageManager().getPackageInfo("com.google.android.gms", 0);
if (pi.versionCode < VERSION_YOU_WANT)
{
// instruct user to update
}
What I've done is wrap this in the required exception handler and run it if the API check reports SUCCESS. If the version is too low I call the getErrorDialog just like when the API check fails, with ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED instead of the returned SUCCESS value.
Doing this may require you to update your minimum SDK target. For example both my phone(5.0.1) and tablet(4.2.2) report success from the API check, and going to the play store does not show an update for either one; However, the installed build on the table is 7895032 while on the phone it's 7895438.
This function will tell the user to update the GooglePlaServices if an update is available. You can start the registration process, if this function returns true
private boolean checkPlayServices()
{
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS)
{
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode))
GooglePlayServicesUtil.getErrorDialog(resultCode, this, 9000).show();
else
{
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}

isGooglePlayServicesAvailable always returns 2

I'm trying to implement Google Play Services Library to my Android app. But there is an issue about isGooglePlayServicesAvailable function.
Although my play services is up to date, it returns 2 which means SERVICE_VERSION_UPDATE_REQUIRED according to documentation.
My code is below:
#Override
protected void onResume() {
super.onResume();
int statusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(LoginSigninActivity.this);
if( statusCode != ConnectionResult.SUCCESS)
{
Log.e("statuscode",statusCode+"");
if(GooglePlayServicesUtil.isUserRecoverableError(statusCode))
{
Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(
statusCode,
LoginSigninActivity.this,
REQUEST_CODE_RECOVER_PLAY_SERVICES);
// If Google Play services can provide an error dialog
if (errorDialog != null) {
errorDialog.show();
}
}
else
{
Toast.makeText(this, getString(R.string.toast_google_play_services_not_found),Toast.LENGTH_LONG).show();
}
}
}
Thanks in advance.
P.S. Error dialog is always shown.
No it should not.
Device with android 4.4.4 has play service version 5.0.89 where as devices with android L preview has play service version 5.2.08. This is reason why android studio ask you to update your play service version to 5.2.08. So, for now use
compile 'com.google.android.gms:play-services:5.0.89'
If you are using android L emulator, i think you should use 5.2.08.
And if you want to update your play service to 5.2 see this.
I also faced same problem. I used latest play services version: 5.+ to develop may app. But my device which has Kitkat uses play services version: 4.4.52. It always said SERVICE_VERSION_UPDATE_REQUIRED because i build an app which uses upper version of play service but device has lower version.
My suggestion is use lower play services version to develop your app or use device which uses upper version of play service.

"this app won\'t work unless you update google play services" error

I am trying to implement the google play services sign-in to my app.
I added libraries (Google-play-services lib, basegameutils lib).I have added the sign in button. The app is not crashing. Everything that I have done seems to be ok.
I signed the app with the keytool and export it, then install it to my phone. I added the SHA1 code to my test app on developers console. And added My app Id to my app.
But when I tap on the sign in button it say with a pop-up "this app won\'t work unless you update google play services". When tap on the "update" it seems the service is up to date.
Is this a problem with my device? Or else What can I try to solve that?
My device is Samsung Galaxy S3.
Update
I added this code :
private boolean checkIfMapsIsOk() {
int checkGooglePlayServices = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (checkGooglePlayServices != ConnectionResult.SUCCESS) {
GooglePlayServicesUtil.getErrorDialog(checkGooglePlayServices, this, 1122).show();
Toast.makeText(getApplicationContext(), "err"+checkGooglePlayServices, Toast.LENGTH_SHORT).show();
return false;
} else {
Toast.makeText(getApplicationContext(), "ok", Toast.LENGTH_SHORT).show();
return true;
}
}
and the toast result is "err2". And I looked up for the error numbers from http://developer.android.com/reference/com/google/android/gms/common/ConnectionResult.html
It says on that site "public static final int SERVICE_VERSION_UPDATE_REQUIRED"
"The installed version of Google Play services is out of date. The calling activity should pass this error code to getErrorDialog(int, Activity, int) to get a localized error dialog that will resolve the error when shown.
Constant Value: 2 (0x00000002)"
So from this I think the reason for error is my device. But my device sees no updates. It is up to date. This is so strange.

Categories

Resources