André Luiz
André Luiz

Reputation: 7302

Android + Firebase: how to make sure to have the minimum Google Play Services

I have this problem: I'm running an app with firebase in a Samsung tablet with Android 4.3 with Google Play Services at version 7.8.99 (should be minimum 9). So when I try to login with FireBase it gives me a "Can't connect to Google Play Services".

My question is: is there a way to make sure that the App will run on all devices with the minimum version of the SDK, in my case the minimum compatibility is 4.3.

I installed Firebase in the app using the assistant, and then checked if everything was there following the manual install guide. I also tried what is described in this post and is this post. So far nothing solved my issue.

My root level build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And my App Level build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "xx.xx.xxxxxxxx"
        minSdkVersion 18
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.roughike:bottom-bar:2.3.1'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.2'
    compile 'com.github.clans:fab:1.6.4'
    testCompile 'junit:junit:4.12'
    compile 'com.google.firebase:firebase-core:10.2.6'
    compile 'com.google.firebase:firebase-auth:10.2.6'
    compile 'com.google.firebase:firebase-database:10.2.6'
    compile 'com.google.firebase:firebase-crash:10.2.6'
    compile 'com.estimote:sdk:1.0.3:release@aar'

}

apply plugin: 'com.google.gms.google-services'

Is there anything I can do to make sure that I can work with firebase in every device?

Upvotes: 0

Views: 621

Answers (1)

tyczj
tyczj

Reputation: 73753

You need to check to see if google play services is available and the connection result of that check tells you what you need to do

switch (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this)){
        case ConnectionResult.SERVICE_MISSING:
            GoogleApiAvailability.getInstance().getErrorDialog(this,ConnectionResult.SERVICE_MISSING,0).show();
            break;
        case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
            GoogleApiAvailability.getInstance().getErrorDialog(this,ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED,0).show();
            break;
        case ConnectionResult.SERVICE_DISABLED:
            GoogleApiAvailability.getInstance().getErrorDialog(this,ConnectionResult.SERVICE_DISABLED,0).show();
            break;
    }

The latest Google Play Services is compatible with all devices 4.1 and up.

There isn't a way to tie GPS to specific android versions, you have to just make sure the version you are using is compatible with your min Android API version you need to target.

Upvotes: 3

Related Questions