skip to Main Content

After implementing Facebook Account Kit and run project it shows Firebase API initialization failure as

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.access$1700(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)

And also getting Null Pointer Exception from 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.access$1700(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) 

Using Account kit gradle as

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

And Firebase Gradle as

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

Note : Removing Account Kit from project its working fine i.e. there is no Firebase API initialization failure. issue. Therefore it’s sure that there is conflict in firebase and Account kit SDK (:

2

Answers


  1. Chosen as BEST ANSWER

    For NullPointerException exception it seems that, Application is not initialized first, Content Providers are initialized before it. And in Facebook account kit SDK's code it was trying to get my application context.

    Now the problem was, I did implement method getApplicationContext() in application class that is getting application shared variable but that variable was setting globally and Facebook Account Kit sdk code getting Null application context.

    Solution : setting shared variable in onCreate method instead of setting globally it resolved the problem of Unable to get provider.

    And For Mixing issue, Account Kit SDK use 11.0.1 version for play services gradle and in my project I am having 11.0.4 that is actually not the issue because on compile time gradle takes latest gradle but In my project I am not referring below gradle which Facebook Account Kit SDK is using.

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

    Solution : I have added above gradle with version 11.0.4 and the mixing gradle issue has been resolved.

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

    And as suggested by @astryk if I exclude play-services-auth-api-phone module then gradle mixing error is not showing but it is not including that module becasue in AccountKitActivity on next button click my application crashes as

    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$1.onReceive(AccountKitActivity.java:176)
    at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:297)
    at android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:46)
    at android.support.v4.content.LocalBroadcastManager$1.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`
    

  2. This is caused by Facebook’s SDK being packaged with a different version of the GMS library than what is packaged with Firebase’s. You can do something like this to get back up and running:

    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'
    

    What this does is essentially hot-swaps out the older library for the newer one packaged with Firebase. It tells Facebook to compile without the old libs and then we make sure they are added back in with newer version right after.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search