6

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.

1
  • Did you read the answer carefully? It's using Is Library Project module for Facebook SDK, this module is then added as a dependency to the main application module. There is even a sample project attached.
    – CrazyCoder
    Feb 6, 2013 at 13:08

4 Answers 4

26

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!!
5
  • 5
    The package cannot be named arbitrarily. It has to be com.facebook.android otherwise the application will complain about not being able to import com.facebook.android.R. I believe that the specified package name is used to construct the project structure inside the gen/ folder where the R.java file is created during compilation. Dec 3, 2013 at 18:11
  • Not sure if this is working anymore? Anyone having trouble with this method as of sdk 3.15.0?
    – Coova
    Jun 15, 2014 at 3:17
  • 3
    Doesn't work for me with facebook sdk 3.17.2 and IntelliJ 13 :( Why can't the facebook sdk simply be a .jar? Aug 25, 2014 at 7:23
  • Doesn't work me too, I am using facebook sdk 3.17.2, any solution?
    – Ehsan
    Aug 28, 2014 at 4:04
  • 1
    facebook's AndroidManifest file changes when you import it to intellij, make sure what you have there is the same as what is here github.com/facebook/facebook-android-sdk/blob/master/facebook/… Sep 7, 2014 at 15:46
0

i had same problem but i'm using eclipse so my steps to solve this problem using eclipse :

1-in eclipse after you import facebook sdk to your workspace right click on FacebookSDk library then chose properties or press Alt + enter 2 - chose "java build path" from leth then go to Libraries Tab

enter image description here


3- click "add external jars" then go to facebook sdk path or location chose libs folder add android-support-v4 file and bolts file
now you done you are happy


i hope this halps

0

Cloud's solution didn't work for me so I'll post mine below. Specifically, mine didn't work because I was already using the appcompat support library, so this will be especially useful in this case.

ONLY DO THE HIGHLIGHTED STEPS IF YOU ARE ALREADY USING THE APPCOMPAT SUPPORT LIBRARY.

  1. Click File -> Project Structure -> Modules. Click the green + -> Import module. Select the facebook folder from the facebook SDK and click OK.
  2. Select Create module from existing sources -> Next -> Next.
  1. Click split (the pink/blue button at the top). Type FacebookDependencies in Name -> select bolts.. -> OK. Uncheck the other one (libs?).
  1. Click Next -> Next -> Finish.
  1. Click the green + on the right -> 2. Library -> (the library that contains your android-support-v4.jar - you can check in the Libraries page on the left) -> Add Selected.

  2. Click the green + on the right -> 3. Module Dependency -> appcompat -> OK.

  1. Click your module.

  2. Click the green + on the right -> 2. Library -> FacebookDependencies (or whatever name it had previously in step 3) -> Add Selected.

  3. Click the green + on the right -> 3. Module Dependency -> facebook -> OK.

-1

A much simpler approach is to import the Facebook SDK as an AAR library in your Android app's Gradle build. For doing so, I suggest not to reinvent the wheel and use the facebook-api-android-aar project (see https://github.com/mente/facebook-api-android-aar) instead. As explained on this project's documentation (in the README.md file) the simple way is to use a pre-built Maven artifact of the Facebook SDK, by adding the following code in your application's build.gradle file:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:+'
    }
}

repositories {
    mavenCentral()
    mavenLocal()
    maven {
        url "http://mente.github.io/facebook-api-android-aar"
    }
}

apply plugin: 'android'
dependencies {
    compile ('com.facebook:facebook-android-sdk:+@aar') {
        transitive = true
    }

    // other dependecies definition here
}

android {
   //android build setup
} 

That's it. Note that this tool support version 3.0.2, 3.5.0, 3.5.2, 3.6.0, 3.7.0, 3.8.0, 3.14.1, 3.15.0, 3.16 of the Facebook SDK.

Ciao

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.