NativeScript / nativescript-facebook

NativeScript plugin, wrapper of native Facebook SDK for Android and iOS
Apache License 2.0
79 stars 50 forks source link

The SDK has not been initialized #214

Closed AgustinV08 closed 4 years ago

AgustinV08 commented 4 years ago

Application crashes on android device after initialization.

sinkersan commented 4 years ago

Same for me. Just got this error for no reason. For me it craches only on android build. iOS looks working. On Android it says: Error: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.

sinkersan commented 4 years ago

I got a solution to my problem. I leave it here in case if someone it will help too.

In your App_Resources/Android/src/main/AndroidManifest.xml under application section need to add:

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

Then in the App_Resources/Android/src/main/res/values/strings.xml under the resources section need to add:

<string name="facebook_app_id">YOUR_APP_ID</string>

More info here: https://developers.facebook.com/docs/android/getting-started/#app_id

AgustinV08 commented 4 years ago

Solution worked, thanks very much, closing the issue

StefanAleksik commented 4 years ago

I got a solution to my problem. I leave it here in case if someone it will help too.

In your App_Resources/Android/src/main/AndroidManifest.xml under application section need to add:

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

Then in the App_Resources/Android/src/main/res/values/strings.xml under the resources section need to add:

<string name="facebook_app_id">YOUR_APP_ID</string>

More info here: https://developers.facebook.com/docs/android/getting-started/#app_id

Solution worked, thanks very much, closing the issue

Hey I am having the same issue, but for me the solution didn't work. Can you share the code in order to see if I am missing something.

Tnx in advance.

sionzee commented 4 years ago

@StefanAleksik I had the same issue. My main file was:

import Vue from 'nativescript-vue'
import * as application from 'tns-core-modules/application';
import VueDevtools from 'nativescript-vue-devtools'
import store from './store'
import SplashScreen from './components/pages/SplashScreen.vue'
import * as Facebook from 'nativescript-facebook';
import FacebookPlugin from "nativescript-facebook/vue";

Vue.use(FacebookPlugin)

if(TNS_ENV !== 'production') {
  Vue.use(VueDevtools)
}

// Prints Vue logs when --env.production is *NOT* set while building
Vue.config.silent = (TNS_ENV === 'production')

application.on(application.launchEvent, function() {
  Facebook.init("hidden-id")
})

new Vue({
  store,
  render: h => h('frame', [h(SplashScreen)])
}).$start()

BUT I accidentally put the meta-data

<application>
  <activity>
     HERE...
  </activity>
</application>

Because there was another meta-data present for SET_THEME_ON_LAUNCH. As documentation says, it should be outside of ACTIVITY but inside APPLICATION.

Everything is working now.

StefanAleksik commented 4 years ago

Hey tnx for the replay. In my case I have the meta-data outside of the activity and inside the application tag. Nevertheless I managed to make it work by changing the order of Facebook sdk initialization inside the facebook-login.andriod.js file in the node module. I saw also that the creators did the same. The weird part is that when I update to the new version I still get .js files instead of the .ts and some old code (so its not the code as in master on this repo).