jeduan / cordova-plugin-facebook4

Use the latest Facebook SDK in your Cordova and Ionic projects
Other
767 stars 511 forks source link

App fail to run after installing plugin #843

Closed tanjunior closed 4 years ago

tanjunior commented 4 years ago

Please do not submit support requests or "How to" questions here. Instead, please use channels like StackOverflow or the Ionic forum

For issues or feature requests related to the code in this repository file a Github issue and provide as much details as possible

Bug or feature request

[X] I'm reporting a reproducible issue with the code [ ] I'm reporting a feature request

Describe the Bug of feature request

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.subtlesystem.homehelper, PID: 6675
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.subtlesystem.homehelper/com.subtlesystem.homehelper.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CordovaPlugin.privateInitialize(java.lang.String, org.apache.cordova.CordovaInterface, org.apache.cordova.CordovaWebView, org.apache.cordova.CordovaPreferences)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3012)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1716)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:232)
        at android.app.ActivityThread.main(ActivityThread.java:6802)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1103)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CordovaPlugin.privateInitialize(java.lang.String, org.apache.cordova.CordovaInterface, org.apache.cordova.CordovaWebView, org.apache.cordova.CordovaPreferences)' on a null object reference
        at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:171)
        at org.apache.cordova.PluginManager.startupPlugins(PluginManager.java:97)
        at org.apache.cordova.PluginManager.init(PluginManager.java:86)
        at com.getcapacitor.cordova.MockCordovaWebViewImpl.init(MockCordovaWebViewImpl.java:62)
        at com.getcapacitor.BridgeActivity.load(BridgeActivity.java:73)
        at com.getcapacitor.BridgeActivity.init(BridgeActivity.java:56)
        at com.subtlesystem.homehelper.MainActivity.onCreate(MainActivity.java:16)
        at android.app.Activity.performCreate(Activity.java:6974)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2900)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3012) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1716) 
        at android.os.Handler.dispatchMessage(Handler.java:110) 
        at android.os.Looper.loop(Looper.java:232) 
        at android.app.ActivityThread.main(ActivityThread.java:6802) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1103) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) 

Expected Behavior

App to launch successfully

Plugin version, OS, devices, etc Windows 10 Home ionic 4.7.1 angular 8.1.2 "@ionic-native/facebook": "^5.18.0", "cordova-plugin-facebook4": "^6.2.0" Android Studio 3.5.3 JRE: 1.8.0_202-release-1483-b03 amd64 AVD API26 OPPO R9S Plus

Sample repo Steps to reproduce

ionic start myApp tabs --capacitor
cd myApp
npx cap init [appName] [appId]
npm install --save @ionic-native/facebook
npm install cordova-plugin-facebook4 --save
cordova plugin add cordova-plugin-facebook4 --save --variable APP_ID="appId" --variable APP_NAME="appName"
ionic build
npx cap add android
npx cap copy
npx cap open android

Additional Context

Seems like I am not the only one facing this issue stackoverflow.com/questions/56738410/app-crashes-on-startup-after-adding-ionic-cordova-plugin-facebook4

peterpeterparker commented 4 years ago

I couldn't reproduce the error and therefore don't think it's an issue but more a support inquiry.

When I look your "step to reproduce" I notice that you are using the same "appId" keywords for both setting up your project and the plugin but these are different.

From the documentation:

Make sure you've registered your Facebook app with Facebook and have an APP_ID https://developers.facebook.com/apps.

Also as you are using Capacitor, you may want to have a look to the tutorial of Josh Morony: https://www.joshmorony.com/using-cordova-plugins-that-require-install-variables-with-capacitor/

In my case I had to modify strings.xml like the following:

<?xml version='1.0' encoding='utf-8'?>
<resources>
    <string name="app_name">myApp345</string>
    <string name="title_activity_main">myApp345</string>
    <string name="package_name">com.example.yolo</string>
    <string name="custom_url_scheme">com.example.yolo</string>
    <string name="fb_app_id">123456789</string>
    <string name="fb_app_name">myApp345</string>
</resources>

and add this to AndroidManifest.xml:

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/fb_app_id" />

And then everything went fine. I hope this help, good luck.

Capture d’écran 2019-12-11 à 07 42 04