Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seem doesn't get Facebook SDK resource when using Facebook Android SDK in IntelliJ IDEA 12

According to the article Add facebook SDK to IntelliJ Android project?, I choose to add the "facebook.jar" file as a Module in the "Dependencies" section in the project structure. The compile process works fine. However, when I trying to using "Session Login" to login in facebook, I got the runtime error message like this:

02-06 20:15:56.648: ERROR/AndroidRuntime(5891): FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: com.facebook.android.R$layout
    at com.facebook.LoginActivity.onCreate(LoginActivity.java:55)
    at android.app.Activity.performCreate(Activity.java:4524)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2115)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2189)
    at android.app.ActivityThread.access$600(ActivityThread.java:139)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:4894)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)

It looks like the facebook.jar doesn't contain the layout resource itself provided in facebook sdk? Don't know if I am right or wrong. I do import the current project and build and run my app via eclipse, and it work like a charm. Everything works flawlessly. However, being a IntelliJ IDEA favorer, I would like to seek if anyone could provide solution for this issue. Many thanks.

like image 286
Cloud Chen Avatar asked Feb 06 '13 12:02

Cloud Chen


1 Answers

OK, finally got the facebook android SDK worked for me. Here are the order of steps I did.

  1. Open up and be in your current android project then select File | New Module
  2. Choose "Library Module" on the left-side panel.
  3. Fill in the required information on the right-side panel. Here I just given the:
    • Module name: "facebook"
    • Content root: Choose where the downloaded facebook android SDK is, and be sure to select the subfolder named "facebook"
      select facebook subfolder

    • Module file location: same as Content root
      New Module Window in IntelliJ IDEA 12
    • Package name: com.facebook.android (Guess could assign arbitrarily?)
  4. Click finish button and wowla~ you got the facebook android sdk module in your project.
  5. Go to File | Project Structure then select the Modules pages at the left panel
    enter image description here
  6. Select your original android project, Click Plus(Add) button to add a new Module Dependency, you will see the facebook module we created above just shown for selection. Select it.
  7. Click the apply, OK button. Then you got the facebook android SDK worked flawlessly in you android application. Congrats!!
like image 117
Cloud Chen Avatar answered Oct 13 '22 15:10

Cloud Chen