alexpalchikovskiy / nativescript-facebook-vue-example

Nativescript-facebook plugin with nativescript-vue example
6 stars 0 forks source link

The plugin could not find the android library #1

Open arzke opened 6 years ago

arzke commented 6 years ago

Hello,

I've been trying to setup facebook login like in the example for android, but I get the following errors:

JS: 'nativescript-facebook: The plugin could not find the android library, try to clean the android platform' JS: [Vue warn]: Error in created hook: "Error: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.

So I had to dive in the code of nativescript-facebook to see where the error happens and it is here: https://github.com/NativeScript/nativescript-facebook/blob/2437e17b9aa71396a679335408c03011ef687bfa/src/login-manager.android.ts#L27

When logging in the console the "e" variable containing the error, I get:

TypeError: Cannot read property 'getApplicationContext' of undefined

alexpalchikovskiy commented 6 years ago

@brundozer can you try this?

setTimeout(() => Facebook.init('APP_ID'), 0)

arzke commented 6 years ago

It works. I guess that we trigger the init before android context is ready and setting a timeout of 0 will delay the call to the init function so the context is there. It looks a bit hacky though. Is it normal that the context is not set when created is triggered? Even after it is mounted?

arzke commented 6 years ago

So when outputting the value of require("tns-core-modules/application").android, I see that I don't have the context set:

{ 
    _observers: { 
        activityStarted: [ [Object], [length]: 1 ],
        activityStopped: [ [Object], [length]: 1 ] 
    },
    _registeredReceivers: {},
    _pendingReceiverRegistrations: [ [length]: 0 ] 
}

I have to figure out why we're expecting the context to be set at this step and it isn't.