com.google.firebase:firebase-config:16.0.0无效

时间:2018-06-04 11:19:05

标签: android firebase

我按照instructions做了一切。但mFirebaseRemoteConfig.fetch(cacheExpiration)尚未开始工作。

但是当我从

的app app build gradle文件中将版本更改为更早版本时
implementation 'com.google.firebase:firebase-config:16.0.0'

implementation 'com.google.firebase:firebase-config:11.0.4'

它开始工作..

你有什么想法,可能是什么原因?

我也检查了以前的项目。我将版本从11.0.4更改为16.0.0并获取stoped working ...

我的应用构建gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.bestworldgames.bestwordgame"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        android.defaultConfig.vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.inkapplications.viewpageindicator:library:2.4.3'
    implementation 'com.startapp:inapp-sdk:3.8.4'
    implementation 'com.google.firebase:firebase-config:16.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') {
        exclude module: 'support-v4'
    }
}
apply plugin: 'com.google.gms.google-services'

我的项目gradle文件

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:4.0.1'

    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

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

添加了:

mFirebaseRemoteConfig.fetch(cacheExpiration)无法正常工作意味着public void onComplete(@NonNull Task<Void> task)尚未被召唤。

mFirebaseRemoteConfig.fetch(cacheExpiration)
        .addOnCompleteListener(this, new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if (task.isSuccessful()) {
                    Toast.makeText(MainActivity.this, "Fetch Succeeded",
                            Toast.LENGTH_SHORT).show();

                    // After config data is successfully fetched, it must be activated before newly fetched
                    // values are returned.
                    mFirebaseRemoteConfig.activateFetched();
                } else {
                    Toast.makeText(MainActivity.this, "Fetch Failed",
                            Toast.LENGTH_SHORT).show();
                }
                displayWelcomeMessage();
            }
        });

logcat的:

06-04 17:39:55.966 10786-10826/com.bestwordgame W/GooglePlayServicesUtil: Google Play services out of date. Requires 12451000 but found 11509470 
06-04 17:39:55.966 10786-10786/com.bestwordgame W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}

promlem在模拟器中,我猜..但现在我无法在模拟器的扩展窗口中找到Google Play设置..如果我是对的,还有其他方法可以更新模拟器上的Google Play服务?

这是我的SDK设置 enter image description here

使用&#39;显示包裹详情&#39;:

enter image description here

3 个答案:

答案 0 :(得分:1)

是的,问题出在模拟器中。但我也发现,通过GoogleApiAvailability.makeGooglePlayServicesAvailable()方法检查设备是否兼容的Google Play服务会更好。 请参阅the link

这是我的验证方法,我打电话给onCreate():

 private void checkGooglePlayServices() {
        GoogleApiAvailability api = GoogleApiAvailability.getInstance();
        int status = api.isGooglePlayServicesAvailable(this);
        Log.i("TAG", "AppController checkGooglePlayServices status " + status);
        if (status != ConnectionResult.SUCCESS) {
            api.makeGooglePlayServicesAvailable(this);
        }
    }

答案 1 :(得分:0)

您需要添加:

 implementation 'com.google.firebase:firebase-core:16.0.0'
  

您的应用程序gradle文件现在必须明确地列出com.google.firebase:firebase-core作为Firebase服务按预期工作的依赖项。

更多信息:

https://firebase.google.com/support/release-notes/android

答案 2 :(得分:0)

遇到同样的问题。我只是将google()换成了行家{ url 'https://maven.google.com' },然后它开始工作。

请参考快速入门应用here