Import Facebook SDK on Android Studio 0.5.1
Asked Answered
V

4

8

I've been searching around for a while now and tried every answer I could find with no success. I am starting to believe that the problem is in the android studio version.

However here is what I've done:

1 - I've downloaded the facebook sdk

2 - Copied the sdk into my libs folder so the project looks like following:

 MyProj
 -app
 --libs
 ---facebook
 ----build.gradle (2)
 --build.gradle (1)
 -settings.gradle

3 - I modified settings.gradle:

include ':libs:facebook', ':app'

4 - I modified build.gradle (1) to:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }


    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'me.dm7.barcodescanner:zxing:1.0'
    compile 'com.koushikdutta.ion:ion:1.2.4'
    compile 'com.google.code.gson:gson:2.2.+'
    compile 'com.squareup.picasso:picasso:2.1.1'
    compile project(':libs:facebook');
}

5 - Lastly edited build.gradle (2):

 buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.9.+'
        }
    }

apply plugin: 'android-library'

dependencies {
    compile 'com.android.support:support-v4:+'
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 19
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
}

Now when syncing I get the annoying warning: Gradle 'MyApp' project refresh failed: Configuration with name 'default' not found

And I am not able to use the facebook library.

I guess I'm doing something wrong with the gradle files. Any ideas?

Vocable answered 13/3, 2014 at 15:10 Comment(1)
I think it depends of what version of facebook sdk you are using. The one I downloaded, there was already a gradle file that looked different. The one I used, I found on stackoverflow somewere, can't remember where though. It worked for me.Vocable
H
14

The directory structure of your project doesn't match the dependency specs you're using; it's not clear what's in your settings.gradle. That error you get with "Configuration name 'default' not found" is terribly unintuitive, but it's the message you get when Gradle is looking for a module in a certain directory and it's not finding it. If you have a dependency spec (and settings.gradle include) like :libs:facebook, it will look in MyProj/libs/facebook, not MyProj/app/libs/facebook where you've placed it.

I would recommend this structure:

MyProj
 -app
 --build.gradle (1)
 -libs
 --facebook
 ---build.gradle (2)
 -settings.gradle

i.e. move the libs directory one level up so it's alongside app directory instead of underneath it.

Your settings.gradle file should be:

include ':app', ':libs:facebook'

(which is probably how you already have it set up) and a dependency on facebook should look like:

compile project(':libs:facebook')

(also like how you already have it set up)

Hellenistic answered 13/3, 2014 at 16:16 Comment(5)
Thanks that worked like a charm! Just to clarify, if i would have kept the the structure as it was, should i have added compile project(':app:libs:facebook') instead?Vocable
Yes, and your include in the settings.gradle needs to look like that too.Hellenistic
it's possible to include Facebook SDK as Gradle-dependency, check this answer: https://mcmap.net/q/204451/-using-facebook-sdk-in-android-studioHyperemia
If facebook is supposed to be on the same level as app, why is it :libs:facebook" instead of ":facebook"? I followed these instructions and android studio complains it cant find facebook for another facebook sample "ProfilePictureSample" on the same level as app. Suggestions?Businessman
My text was correct, but my ASCII-art directory structure was wrong. I fixed it.Hellenistic
D
24

On Mac with Android Studio 0.5.8, this is what worked for me:

  1. Click on the top level project and select project structure: Step 1

  2. Click the + to add another module Step 2

  3. Click on "Import Existing Project" and "Next" Step 3

  4. Select the facebook directory from your SDK folder and click next Step 4

  5. The facebook module should now be shown in addition to your existing module Step 5

  6. Click on your project, select the Dependencies tab and click '+' to add a dependency. Step 6

  7. Select "Module Dependency" as dependency type. Step 7

  8. Select the Facebook module that we just added Step 8

  9. Note that it shows up under dependencies (of your app) Step 9

And you're all set!

Demythologize answered 10/5, 2014 at 6:17 Comment(3)
This unfortunately doesn't work for me :( At step 5, when I select the Facebook folder, it doesn't do anything, it still says "Select modules to import". When I select the parent folder (facebook-android-sdk-3.14), it gives me all the modules to import. I then select the "Facebook" module, click finish, but then I only get a gradle sync and the module doesn't show anywhere... Also using 0.5.8 here, do you have any idea what I am doing wrong?Broadwater
Also dont forget to add bolts.jas as your library!Literalism
This is the best solutionBuckeye
H
14

The directory structure of your project doesn't match the dependency specs you're using; it's not clear what's in your settings.gradle. That error you get with "Configuration name 'default' not found" is terribly unintuitive, but it's the message you get when Gradle is looking for a module in a certain directory and it's not finding it. If you have a dependency spec (and settings.gradle include) like :libs:facebook, it will look in MyProj/libs/facebook, not MyProj/app/libs/facebook where you've placed it.

I would recommend this structure:

MyProj
 -app
 --build.gradle (1)
 -libs
 --facebook
 ---build.gradle (2)
 -settings.gradle

i.e. move the libs directory one level up so it's alongside app directory instead of underneath it.

Your settings.gradle file should be:

include ':app', ':libs:facebook'

(which is probably how you already have it set up) and a dependency on facebook should look like:

compile project(':libs:facebook')

(also like how you already have it set up)

Hellenistic answered 13/3, 2014 at 16:16 Comment(5)
Thanks that worked like a charm! Just to clarify, if i would have kept the the structure as it was, should i have added compile project(':app:libs:facebook') instead?Vocable
Yes, and your include in the settings.gradle needs to look like that too.Hellenistic
it's possible to include Facebook SDK as Gradle-dependency, check this answer: https://mcmap.net/q/204451/-using-facebook-sdk-in-android-studioHyperemia
If facebook is supposed to be on the same level as app, why is it :libs:facebook" instead of ":facebook"? I followed these instructions and android studio complains it cant find facebook for another facebook sample "ProfilePictureSample" on the same level as app. Suggestions?Businessman
My text was correct, but my ASCII-art directory structure was wrong. I fixed it.Hellenistic
J
5

Follow this step to add Facebook SDK to your Android project.

1) Open your fresh Android project 
2) Go to File -> Project Structure (or) Alt+Ctrl+Shift+S
3) Go to module click + on second row of window then import module
4) After Facebook SDK imported click + on third row and select Module Dependency select Facebook SDK Apply and press ok 
Joviality answered 13/3, 2014 at 17:10 Comment(2)
That seems not to work on android studio 0.5.1. There are no import module. However, the first answer worked for me! Thank you anyway.Vocable
click on "import existing project", and the project will be imported as a moduleRenaldo
L
0

I made a Facebook Module version from scratch https://github.com/cesarferreira/Facebook-Module

If you want to use this module for your projects you should follow the next steps:

  • You should create a new 'libs' folder in your project root
  • You should copy this project into the 'libs' folder, you must manually copy the project, because if you copy it using the drag and drop action the project doesn't work because android studio throw an error
  • Add the next line into settings.gradle file: include ':libs:facebook'
  • You should rebuild the project

THAT'S IT!

Lycanthropy answered 14/6, 2014 at 19:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.