I setup the Facebook sdk in Eclipse and I am using Facebook sdk 4.18.
I already added Facebook.jar to build path, but also crashes.
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(this); //Crash this line
}
public void initFB(){
Log.e("Facebook", "init facebook");
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile"));
Log.e("Facebook", "init facebook2");
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d("FB", "access token got.");
fbLoginCallBack(loginResult.getAccessToken().getToken());
// accessToken = loginResult.getAccessToken();
}
@Override
public void onCancel() {
// App code
Log.d("FB", "CANCEL");
}
@Override
public void onError(FacebookException exception) {
// App code
Log.d("FB", exception.toString());
}
});
}
Error Message
12-22 16:57:29.620: E/AndroidRuntime(19402): java.lang.NoClassDefFoundError: com.facebook.R$style 12-22 16:57:29.620: E/AndroidRuntime(19402): at com.facebook.FacebookSdk.(FacebookSdk.java:83) 12-22 16:57:29.620: E/AndroidRuntime(19402): at com.sidequest.taxi.taxi.onCreate(taxi.java:187) 12-22 16:57:29.620: E/AndroidRuntime(19402): at android.app.Activity.performCreate(Activity.java:5231) 12-22 16:57:29.620: E/AndroidRuntime(19402): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 12-22 16:57:29.620: E/AndroidRuntime(19402): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2212) 12-22 16:57:29.620: E/AndroidRuntime(19402): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2298) 12-22 16:57:29.620: E/AndroidRuntime(19402): at android.app.ActivityThread.access$800(ActivityThread.java:144) 12-22 16:57:29.620: E/AndroidRuntime(19402): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246) 12-22 16:57 :29.620: E/AndroidRuntime(19402): at android.os.Handler.dispatchMessage(Handler.java:102) 12-22 16:57:29.620: E/AndroidRuntime(19402): at android.os.Looper.loop(Looper.java:212) 12-22 16:57:29.620: E/AndroidRuntime(19402): at android.app.ActivityThread.main(ActivityThread.java:5151) 12-22 16:57:29.620: E/AndroidRuntime(19402): at java.lang.reflect.Method.invokeNative(Native Method) 12-22 16:57:29.620: E/AndroidRuntime(19402): at java.lang.reflect.Method.invoke(Method.java:515) 12-22 16:57:29.620: E/AndroidRuntime(19402): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 12-22 16:57:29.620: E/AndroidRuntime(19402): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684) 12-22 16:57:29.620: E/AndroidRuntime(19402): at dalvik.system.NativeStart.main(Native Method)
@Manlok Wong I am also facing this problem, So the solution is like
FacebookSdk. sdkInitialize (this); It is not properly taking the class
So, try this FacebookSdk. sdkInitialize (Your Activity. this);
FacebookSdk. sdkInitialize (Your Activity. this);
And in Application class, in **onCreate () ** Method
FacebookSdk. sdkInitialize (getApplicationContext ());
Try
FacebookSdk.sdkInitialize(getApplicationContext());
//or
FacebookAPI.getInstance().init(getApplicationContext());
Right Click on your project -> Build Path -> Configure Build Path -> Order and Export Tab.
Make sure that "Facebook.jar" is checked for Export.
In my case, our Android app was completly crashing (in Android 8 only) whenever a call to logInWithReadPermissions()
was made:
/* This caused an immediate crash of the application - wrapping with
try/catch failed to "catch" any unhandled expection that may have been
causing the crash */
LoginManager.getInstance().logInWithReadPermissions(this, PERMISSIONS);
It turns out that the inclusion of the android:screenOrientation
attribute in our manifest's com.facebook.FacebookActivity
activity was the cause of the crash:
<!-- Causes crash -->
<activity
android:name="com.facebook.FacebookActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:screenOrientation="portrait" />
Updating the <acitivty/>
as follows fixed the bug:
<!-- Resolved the crash -->
<activity
android:name="com.facebook.FacebookActivity"
android:label="@string/app_name" />
As part of my investigation into the cause of this bug, I also updated the project's FacebookSDK dependancy from com.facebook.android:facebook-android-sdk:4.20.0
to the more recent com.facebook.android:facebook-android-sdk:5.0.0
.
Hope this helps someone!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.