有人看到在Android上使用Firestore保存文档时遇到问题吗?它似乎正在'com.google.firebase:firebase-firestore:17.0.x'
上发生。
尝试像这样进行简单的保存:
val db = FirebaseFirestore.getInstance()
db.collection("users").document("user1").set(user)
.addOnSuccessListener {
Log.d(TAG, "Save OK")
}
.addOnFailureListener {
Log.e(TAG, "Save Failed")
}
但没有调用任何侦听器。我在日志中看到的唯一错误是:
W / Firestore:(0.6.6-dev)[OnlineStateTracker]:无法访问 Firestore后端。
检索文档似乎没问题,降级为com.google.firebase:firebase-firestore:16.0.0
似乎可以解决此问题。
build.gradle失败-
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
def dbflow_version = "4.2.4"
android {
compileSdkVersion 28
buildToolsVersion '28'
defaultConfig {
applicationId "ce.test"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
java.srcDirs = ['src/main/java', 'src/main/java/ce.test/models']
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support:preference-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
implementation 'com.google.firebase:firebase-firestore:17.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.madgag.spongycastle:core:1.56.0.0'
implementation 'com.madgag.spongycastle:prov:1.56.0.0'
implementation 'com.madgag.spongycastle:bcpkix-jdk15on:1.56.0.0'
implementation 'com.android.support:design:28.0.0-alpha3'
implementation 'org.jetbrains.anko:anko-common:0.9'
implementation 'br.com.simplepass:loading-button-android:1.14.0'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
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:28.0.0-alpha3'
}
答案 0 :(得分:0)
如果您的设备无法到达Firestore后端,则不会调用成功侦听器或失败侦听器。仅在数据提交到Firebase服务器或被Firebase服务器拒绝后,才会调用成功/失败侦听器。
这不是强制性的,但我建议您也将最新版本用于Firestore。为此,请更改以下代码行:
implementation 'com.google.firebase:firebase-firestore:17.0.1'
到
implementation 'com.google.firebase:firebase-firestore:17.0.4'
什么是强制性的,应该在文件末尾添加以下代码行:
apply plugin: 'com.google.gms.google-services'
也请不要忘记在build.gradle(项目)文件中包含以下代码行:
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.2'
也请不要忘记在manifiedt文件中添加INTERNET权限。