我正在按照https://firebase.google.com/docs/auth/android/firebaseui
中的说明实施用于Firebase身份验证的预构建UI。基本上,我的应用程序上发生的事情是成功登录后,我的应用程序被移至后台,这导致无法调用onActivityResult方法。但是,我不知道发生这种情况的原因是什么。
我正在使用最新版本的FirebaseUI,Google Play Auth和Firebase依赖项,如我应用程序的build.gradle文件中所示。
我遇到了很多问题,这些问题现在都不是一个问题。就像有不正确的SHA-1(在点击登录按钮后导致错误)或缺少依赖项一样。
我尝试生成一个发行版APK,以防调试APK发生某些事情,但结果是相同的。
对此有任何帮助吗?
经过大量测试,我发现唯一看起来不太好的是出现在logcat中的错误:
[DeviceKeyStore]无法加载密钥:找不到设备密钥文件。
这是我用来调用FirebaseUI库的代码:
override fun onResume() {
super.onResume()
val mAuth = FirebaseAuth.getInstance()
val currentUser = mAuth?.currentUser
if (currentUser == null) {
requireFirebaseLogin()
}
}
private fun requireFirebaseLogin() {
val providers = arrayListOf(
AuthUI.IdpConfig.AnonymousBuilder().build(),
AuthUI.IdpConfig.EmailBuilder().build(),
AuthUI.IdpConfig.FacebookBuilder().build(),
AuthUI.IdpConfig.GoogleBuilder().build())
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.setLogo(R.mipmap.logo)
.build(),
RequestCodes.FIREBASE_SIGN_IN)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RequestCodes.FIREBASE_SIGN_IN) {
val response = IdpResponse.fromResultIntent(data)
if (resultCode == Activity.RESULT_OK) {
mapApplication.firebaseAuth = mAuth
initSetup()
} else {
// Sign in failed. If response is null the firebaseAuth canceled the
// sign-in flow using the back button. Otherwise check
// response.getError().getErrorCode() and handle the error.
}
}
}
这是我的应用程序的build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'maven'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath "io.fabric.tools:gradle:$fabric_version"
}
}
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.mypackage.debug"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
lintOptions {
checkReleaseBuilds false
}
buildTypes {
debug {
minifyEnabled false
applicationIdSuffix ".debug"
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
/**
* The 'initWith' property allows you to copy configurations from other build types,
* so you don't have to configure one from the beginning. You can then configure
* just the settings you want to change. The following line initializes
* 'jnidebug' using the debug build type, and changes only the
* applicationIdSuffix and versionNameSuffix settings.
*/
jnidebug {
// This copies the debuggable attribute and debug signing configurations.
initWith debug
applicationIdSuffix ".jnidebug"
jniDebuggable true
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
def room_version = "2.0.0"
implementation "com.android.support:design:$android_dependencies_version"
implementation 'androidx.arch.core:core-runtime:2.1.0-beta01'
implementation "androidx.appcompat:appcompat:1.1.0-alpha05"
implementation 'androidx.annotation:annotation:1.1.0-rc01'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha5'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha05'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.github.filosganga:geogson-core:1.2.21'
implementation 'com.github.filosganga:geogson-jts:1.2.21'
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'com.facebook.android:facebook-android-sdk:5.0.0'
implementation 'com.firebaseui:firebase-ui-auth:4.3.2'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.9@aar') {
transitive = true
}
implementation 'io.swagger:swagger-annotations:1.5.21'
implementation 'org.apache.httpcomponents:httpcore:4.4.11'
implementation 'org.apache.httpcomponents:httpmime:4.5.8'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.27.0-eap13'
implementation 'com.carto:carto-mobile-sdk:4.1.6@aar'
implementation 'com.mapzen.android:lost:3.0.4'
implementation 'com.graphhopper:directions-api-client-hc:0.10.3'
implementation 'com.andkulikov:transitionseverywhere:2.0.0-beta01'
implementation 'com.flickr4java:flickr4java:3.0.1'
implementation 'com.github.PhilJay:MPAndroidChart:3.1.0-alpha'
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.13-beta-2'
testImplementation 'org.robolectric:robolectric:4.3-alpha-2'
testImplementation 'net.jodah:concurrentunit:0.4.4'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.lifecycle:lifecycle-extensions:$room_version"
testImplementation "androidx.room:room-testing:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation 'com.github.humazed:RoomAsset:1.0.3'
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.8'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.8'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
implementation 'com.jmedeisis:draglinearlayout:1.1.0'
implementation 'io.github.kobakei:ratethisapp:1.2.0'
implementation 'org.jetbrains.anko:anko-common:0.9'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.yarolegovich:discrete-scrollview:1.4.9'
implementation 'com.google.android.gms:play-services-vision:17.0.2'
implementation "com.google.android.gms:play-services-auth:16.0.1"
}
configurations.all {
// Check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "com.android.support") {
if (!requested.name.startsWith("multidex")) {
details.useVersion "26.+"
}
}
}
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
task instrumentTest(dependsOn: connectedCheck)
apply plugin: 'com.google.gms.google-services'