我在我的应用中实施了Firebase Google和手机身份验证。 使用Google登录正常工作。但电话认证给予
错误:NoSuchMethodError:android.support.v4.app.FragmentManager.isStateSaved
我在Android中使用Firebase和Firebase-UI
这是APP Level Build Gradle File
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.dev_man_team.fiverr.predictnwin"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
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:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.google.firebase:firebase-database:11.6.0'
compile 'com.google.firebase:firebase-storage:11.6.0'
compile 'com.google.firebase:firebase-auth:11.6.0'
compile 'com.google.android.gms:play-services:11.6.0'
compile 'com.firebaseui:firebase-ui-database:3.1.0'
compile 'com.firebaseui:firebase-ui-auth:3.1.0'
compile 'com.firebaseui:firebase-ui-storage:3.1.0'
}
apply plugin: 'com.google.gms.google-services'
这就是代码
private FirebaseAuth auth;
private static final int RC_SIGN_IN = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup_login);
auth = FirebaseAuth.getInstance();
if(auth.getCurrentUser() != null){
Toast.makeText(getApplicationContext(), "User is Already Signed in", Toast.LENGTH_LONG).show();
}
else{
signUp();
}
}
private void signUp() {
List<AuthUI.IdpConfig> providers = new ArrayList<>();
providers.add(new AuthUI.IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER).build());
providers.add(new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build());
startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().setAvailableProviders(providers).build(), RC_SIGN_IN);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RC_SIGN_IN){
IdpResponse response = IdpResponse.fromResultIntent(data);
if(resultCode == RESULT_OK){
startActivity(new Intent(this, MainActivity.class));
finish();
Toast.makeText(getApplicationContext(), "User Signed in", Toast.LENGTH_LONG).show();
}
}
}
这就是我收到的错误
11-15 20:48:12.509 9712-9712 / com.dev_man_team.fiverr.predictnwin E / UncaughtException:java.lang.NoSuchMethodError:android.support.v4.app.FragmentManager.isStateSaved 在com.firebase.ui.auth.ui.phone.CompletableProgressDialog.showAllowingStateLoss(CompletableProgressDialog.java:51) 在com.firebase.ui.auth.ui.phone.CompletableProgressDialog.show(CompletableProgressDialog.java:41) 在com.firebase.ui.auth.ui.phone.PhoneVerificationActivity.showLoadingDialog(PhoneVerificationActivity.java:390) 在com.firebase.ui.auth.ui.phone.PhoneVerificationActivity.verifyPhoneNumber(PhoneVerificationActivity.java:157) 在com.firebase.ui.auth.ui.phone.VerifyPhoneNumberFragment.onNext(VerifyPhoneNumberFragment.java:200) 在com.firebase.ui.auth.ui.phone.VerifyPhoneNumberFragment.onActivityResult(VerifyPhoneNumberFragment.java:184) 在android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:164) 在android.app.Activity.dispatchActivityResult(Activity.java:5387) 在android.app.ActivityThread.deliverResults(ActivityThread.java:3205) 在android.app.ActivityThread.handleSendResult(ActivityThread.java:3252) 在android.app.ActivityThread.access $ 1200(ActivityThread.java:143) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1289) 在android.os.Handler.dispatchMessage(Handler.java:99) 在android.os.Looper.loop(Looper.java:137) 在android.app.ActivityThread.main(ActivityThread.java:4960) at java.lang.reflect.Method.invokeNative(Native Method) 在java.lang.reflect.Method.invoke(Method.java:511) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1038) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) at dalvik.system.NativeStart.main(Native Method) 11-15 20:48:12.769 9712-9712 / com.dev_man_team.fiverr.predictnwin E / AndroidRuntime:FATAL EXCEPTION:main java.lang.NoSuchMethodError:android.support.v4.app.FragmentManager.isStateSaved 在com.firebase.ui.auth.ui.phone.CompletableProgressDialog.showAllowingStateLoss(CompletableProgressDialog.java:51) 在com.firebase.ui.auth.ui.phone.CompletableProgressDialog.show(CompletableProgressDialog.java:41) 在com.firebase.ui.auth.ui.phone.PhoneVerificationActivity.showLoadingDialog(PhoneVerificationActivity.java:390) 在com.firebase.ui.auth.ui.phone.PhoneVerificationActivity.verifyPhoneNumber(PhoneVerificationActivity.java:157) 在com.firebase.ui.auth.ui.phone.VerifyPhoneNumberFragment.onNext(VerifyPhoneNumberFragment.java:200) 在com.firebase.ui.auth.ui.phone.VerifyPhoneNumberFragment.onActivityResult(VerifyPhoneNumberFragment.java:184) 在android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:164) 在android.app.Activity.dispatchActivityResult(Activity.java:5387) 在android.app.ActivityThread.deliverResults(ActivityThread.java:3205) 在android.app.ActivityThread.handleSendResult(ActivityThread.java:3252) 在android.app.ActivityThread.access $ 1200(ActivityThread.java:143) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1289) 在android.os.Handler.dispatchMessage(Handler.java:99) 在android.os.Looper.loop(Looper.java:137) 在android.app.ActivityThread.main(ActivityThread.java:4960) at java.lang.reflect.Method.invokeNative(Native Method) 在java.lang.reflect.Method.invoke(Method.java:511) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1038) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 在dalvik.system.NativeStart.main(本地方法)
提前感谢您纠正我的错误。 我将非常感谢你的帮助。
答案 0 :(得分:0)
三点建议:
(1)您正在使用FirebaseUI 3.1.0版和更新版本的Firebase和Google Play库11.6.0。 FirebaseUI documentation解释说这需要升级传递依赖关系。按照文档中的说明,您应该添加这些依赖项:
compile 'com.android.support:customtabs:26.1.0'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:palette-v7:26.1.0'
(2)您包含所有Google Play服务:
compile 'com.google.android.gms:play-services:11.6.0'
这会不必要地增加您的APK大小和构建时间,并且会导致您的应用超过旧设备上的65K方法参考限制。最好只包含您需要的特定API,例如play-services-auth
。 (APIs here)
(3)您的build.gradle没有指定buildToolsVersion
。我不知道使用什么默认值。更安全地指定一个,例如:
compileSdkVersion 26
buildToolsVersion "26.0.2"
答案 1 :(得分:0)
经过大量搜索后,终于找到了我自己的问题的答案
根据@Bob的三个建议,我在App Level Build Gradle中添加了一件事
compile ('com.google.firebase:firebase-core:11.4.2'){
exclude group: 'com.google.firebase:firebase-analytics:9.0.0'
}
compile ('com.google.firebase:firebase-auth:11.4.2'){
exclude group: 'com.google.firebase:firebase-analytics:9.0.0'
}
避免冲突。 现在一切正常。