Import Facebook SDK on Android Studio 0.5.1
Solution 1
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)
Solution 2
On Mac with Android Studio 0.5.8, this is what worked for me:
Click on the top level project and select project structure:
Click the + to add another module
Click on "Import Existing Project" and "Next"
Select the facebook directory from your SDK folder and click next
The facebook module should now be shown in addition to your existing module
Click on your project, select the Dependencies tab and click '+' to add a dependency.
Select "Module Dependency" as dependency type.
Select the Facebook module that we just added
Note that it shows up under dependencies (of your app)
And you're all set!
Solution 3
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
Furedal
Updated on July 26, 2022Comments
-
Furedal almost 2 years
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?
-
Furedal about 10 yearsThanks 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?
-
Scott Barta about 10 yearsYes, and your
include
in the settings.gradle needs to look like that too. -
Furedal about 10 yearsThat 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.
-
TheModularMind about 10 yearsclick on "import existing project", and the project will be imported as a module
-
Oleksii K. almost 10 yearsit's possible to include Facebook SDK as Gradle-dependency, check this answer: stackoverflow.com/a/23746667/1891118
-
Thermometer almost 10 yearsThis 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?
-
NRR almost 10 yearsGreat answer! Solved our problem. Thanks!
-
HukeLau_DABA almost 10 yearsIf 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?
-
Scott Barta almost 10 yearsMy text was correct, but my ASCII-art directory structure was wrong. I fixed it.
-
Nagaraj Alagusundaram almost 10 yearsAlso dont forget to add bolts.jas as your library!
-
Markel Mairs over 8 yearsThis is the best solution