I'm trying to create a new Android application that uses the Facebook SDK, I'm using latests versions for everything, so I'm using Android Studio 0.4.0 with the new Gradle compilation system and the latests version of the SDK downloaded from Facebook.
I have tried to follow the instructions in the Facebook Developers page: https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android-using-android-studio/3.0/ with no luck, because the instructions are not for a Gradle based Android Studio.
I have also tried to follow the instructions from Scott Barta in using facebook sdk in android studio but no luck, the step 7 when "Sync Project with Gradle Files" is not working, I'm getting this error:
Failed to refresh Gradle project. You are using an old, unsupported version of Gradle. Please use version 1.9 or greater. Please point to a supported Gradle version in the project's Gradle settings or in the project's Gradle wrapper (if applicable.)
I have tried to modify the build.gradle file and change the classpath line from:
classpath 'com.android.tools.build:gradle:0.6.+'
to:
classpath 'com.android.tools.build:gradle:0.7.+'
And also change the compileSdkVersion, buildToolsVersion, minSdkVersion and targetSdkVersion to the values I have in my project, but is not working.
Can anyone help me? Thanks!
EDIT: I have updated today to Android 0.4.2 but no luck with the new version.
My gradle-wrapper.properties file is using Gradle 1.9:
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-all.zip
This is the build.gradle file I use to compile the Facebook library:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
And this is the complete build.gradle I use for my application:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile project(':libraries:facebook')
}
Now, when I click on Sync Project with Gradle Files I get the following error:
Gradle 'Testing' project refresh failed:
Project with path ':libraries:facebook' could not be found in project ':app'.
I have tried to change the path using: "libraries:facebook", "app:libraries:facebook", ":app:libraries:facebook"... but I'm always having the same error.
EDIT WITH SOLUTION:
With Android 0.4.2 and latest version of the Facebook SDK is really easy, Facebook SDK is including a build.gradle file that works, just only follow these steps:
Create a folder called "libs" (important, don't use other name!!! If you use "lib" may not work), at the top of your project (important too, don't create in a subfolder!!!).
Copy the facebook folder from the downloaded SDK into the libs folder you just created.
Include this line at the top of your settings.gradle:
include ':libs:facebook'
Include this line at the bottom of your build.gradle file, in the dependencies group:
compile project(':libs:facebook')
Just click on "Sync Project with Gradle files", rebuild project and it should work!
EDIT FOR ANDROID STUDIO > 0.5.2:
Well, from Android Studio version 0.5.2, when a new project is created, a "libs" folder is created inside your project, so I think is a better idea to use that folder, so these are the steps:
Copy the facebook folder from the downloaded SDK into the libs folder: YourProjectName/yourProjectName/libs
Include this line at the top of your settings.gradle:
include ':libs:facebook'
Include this line at the bottom of your build.gradle file, in the dependencies group:
compile project(':yourProjectName:libs:facebook')
Just click on "Sync Project with Gradle files", rebuild project and it should work!