Facebook 帐户套件 Firebase API 初始化失败

Facebook accout kit Firebase API initialization failure

实施 Facebook Account Kit 和 运行 项目后,它显示 Firebase API 初始化失败

FirebaseApp: Firebase API initialization failure.
 java.lang.reflect.InvocationTargetException
 at java.lang.reflect.Method.invoke(Native Method)
 at com.google.firebase.FirebaseApp.zza(Unknown Source)
 at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
 at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
 at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
 at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
 at android.content.ContentProvider.attachInfo(ContentProvider.java:1758)
 at android.content.ContentProvider.attachInfo(ContentProvider.java:1733)
 at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
 at android.app.ActivityThread.installProvider(ActivityThread.java:5257)
 at android.app.ActivityThread.installContentProviders(ActivityThread.java:4808)
 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4748)
 at android.app.ActivityThread.access00(ActivityThread.java:153)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1436)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:154)
 at android.app.ActivityThread.main(ActivityThread.java:5529)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)

并且还从 AccountKitController 获取 空指针异常 as

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
 at com.facebook.accountkit.internal.Initializer.initialize(Initializer.java:101)
 at com.facebook.accountkit.internal.AccountKitController.initialize(AccountKitController.java:601)
 at com.facebook.accountkit.internal.AccountKitInitProvider.onCreate(AccountKitInitProvider.java:31)
 at android.content.ContentProvider.attachInfo(ContentProvider.java:1758)
 at android.content.ContentProvider.attachInfo(ContentProvider.java:1733)
 at android.app.ActivityThread.installProvider(ActivityThread.java:5257)
 at android.app.ActivityThread.installContentProviders(ActivityThread.java:4808) 
 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4748) 
 at android.app.ActivityThread.access00(ActivityThread.java:153) 
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1436) 
 at android.os.Handler.dispatchMessage(Handler.java:102) 
 at android.os.Looper.loop(Looper.java:154) 
 at android.app.ActivityThread.main(ActivityThread.java:5529) 
 at java.lang.reflect.Method.invoke(Native Method) 

使用帐户工具包 gradle 作为

compile 'com.facebook.android:account-kit-sdk:4.27.0'

和 Firebase Gradle 作为

compile 'com.google.firebase:firebase-messaging:11.0.4'

注意:从项目中删除 Account Kit 工作正常,即没有 Firebase API 初始化失败。 问题。因此可以肯定的是,firebase 和 Account kit SDK 存在冲突 (:

这是由于 Facebook 的 SDK 打包的 GMS 库版本与 Firebase 的不同。你可以做这样的事情来恢复 运行:

compile ('com.facebook.android:account-kit-sdk:4.27.0') {
        exclude group: 'com.google.android.gms', module: 'play-services-auth-api-phone'
        exclude group: 'com.google.android.gms', module: 'play-services-auth'
    }
    compile 'com.google.android.gms:play-services-auth:11.6.0'
    compile 'com.google.firebase:firebase-messaging:11.6.0'

这实际上是将旧库热交换为与 Firebase 打包在一起的新库。它告诉 Facebook 在没有旧库的情况下进行编译,然后我们确保在之后立即将它们添加回新版本。

对于NullPointerException异常似乎是,Application没有先初始化,Content Providers在它之前被初始化。 在 Facebook 帐户工具包 SDK 的代码中,它试图获取我的应用程序上下文。

现在的问题是,我确实在获取应用程序共享变量的应用程序 getApplicationContext() 中实现了方法 getApplicationContext(),但该变量是全局设置的,而 Facebook Account Kit sdk 代码获取的是 Null 应用程序上下文。

解决方案:在 onCreate 方法中设置共享变量而不是全局设置它解决了 Unable to get provider.

的问题

并且对于混合问题,Account Kit SDK 使用 11.0.1 版本播放服务 gradle 并且在我的项目中我有 11.0.4 这实际上不是问题,因为在编译时 gradle 需要最新的 gradle 但在我的项目中我不是指下面 gradle 正在使用哪个 Facebook Account Kit SDK。

compile 'com.google.android.gms:play-services-auth-api-phone:11.0.1'

解决方案 :我在上面添加了 gradle 版本 11.0.4 和混合 gradle 问题已解决

compile 'com.google.android.gms:play-services-auth-api-phone:11.0.4'

并且 如果我排除 play-services-auth-api-phone 模块,则 gradle 混合错误不会显示,但它不包括该模块,因为 AccountKitActivity 在下一个按钮上单击我的应用程序崩溃为

Crash Report Thread:main Exception:java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/auth/api/phone/SmsRetriever;
at com.facebook.accountkit.internal.PhoneLoginController.createSmsToken(PhoneLoginController.java:250)
at com.facebook.accountkit.internal.PhoneLoginController.logIn(PhoneLoginController.java:188)
at com.facebook.accountkit.internal.LoginManager.logInWithPhoneNumber(LoginManager.java:372)
at com.facebook.accountkit.internal.AccountKitController.logInWithPhoneNumber(AccountKitController.java:631)
at com.facebook.accountkit.ui.PhoneLoginFlowManager.logInWithPhoneNumber(PhoneLoginFlowManager.java:57)
at com.facebook.accountkit.ui.ActivityPhoneHandler.onPhoneLoginComplete(ActivityPhoneHandler.java:189)
at com.facebook.accountkit.ui.AccountKitActivity.onReceive(AccountKitActivity.java:176)
at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:297)
at android.support.v4.content.LocalBroadcastManager.access[=12=]0(LocalBroadcastManager.java:46)
at android.support.v4.content.LocalBroadcastManager.handleMessage(LocalBroadcastManager.java:116)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5529)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.auth.api.phone.SmsRetriever" on path: DexPathList[[zip file "/data/app/com.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.myappList item -1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 16 more
Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.auth.api.phone.SmsRetriever
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 17 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available`