[FIXED] "GooglePlayServices not available due to error 9" when running an app with Firestore integrated

Issue

I just created an app that retrieves data from the Firestore database. When I try to run this app, it always crashes.

Logcat (Error):

GooglePlayServices not available due to error 9

Here is my Java code:

TextView ret;
FirebaseFirestore db = FirebaseFirestore.getInstance();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Objects.requireNonNull(getSupportActionBar()).hide();

    ret = findViewById(R.id.ret);

    DocumentReference documentReference = db.collection("users").document("user");

    documentReference.addSnapshotListener((documentSnapshot, e) -> {
        if (e != null) {
            Toast.makeText(MainActivity.this, "An Error Occurred while connecting to the database", Toast.LENGTH_SHORT).show();
        }
        if (documentSnapshot != null && documentSnapshot.exists()) {
            ret.setText(Objects.requireNonNull(Objects.requireNonNull(documentSnapshot.getData()).get("updatedValue")).toString());
        }
    });

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/ret"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:textSize="50sp"
        android:textAlignment="center"
        android:layout_marginTop="60dp"/>

</LinearLayout>

Manifest:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Solution

The problem is in the emulator. Try it using your phone, and change the Android version of the application to be compatible with your phone.

Answered By – website coding

Answer Checked By – Candace Johnson (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published