I'm following Facebook SDK for Android using Android Studio. When I run my application I'm getting the below mentioned warning.
Gradle: module 'facebook' won't be compiled. Unfortunately you can't have non-Gradle Java module and Android-Gradle module in one project.
How should I solve this?
I tried @Scott Barta's answer and get the following error message.
A problem occurred configuring project ':App'.
> Failed to notify project evaluation listener.
> A problem occurred configuring project ':libraries:facebook'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':libraries:facebook:_DebugCompile'.
> Could not find any version that matches com.android.support:support-v4:+.
Required by:
MyApplication2.libraries:facebook:unspecified
NOTE
For Android Studio 0.5.5 and later, and with later versions of the Facebook SDK, this process is much simpler than what is documented below (which was written for earlier versions of both). If you're running the latest, all you need to do is this:
Ctrl + Shift + Alt + S
and then select dependencies tab. Click on +
button and select Module Dependency. In the new window pop up select :facebook.
Instructions for older Android Studio and older Facebook SDK
This applies to Android Studio 0.5.4 and earlier, and makes the most sense for versions of the Facebook SDK before Facebook offered Gradle build files for the distribution. I don't know in which version of the SDK they made that change.
Facebook's instructions under "Import the SDK into an Android Studio Project" on their https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android-using-android-studio/3.0/ page are wrong for Gradle-based projects (i.e. your project was built using Android Studio's New Project wizard and/or has a build.gradle
file for your application module). Follow these instructions instead:
Create a libraries
folder underneath your project's main directory.
For example, if your project is HelloWorldProject, you would create
a HelloWorldProject/libraries
folder.
Now copy the entire facebook
directory from the SDK
installation into the libraries
folder you just created.
Delete the libs
folder in the facebook
directory. If you like,
delete the project.properties
, build.xml
, .classpath
, and .project
. files as well. You don't need them.
Create a build.gradle
file in the facebook
directory with the
following contents:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:+'
}
android {
compileSdkVersion 17
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
Note that depending on when you're following these instructions compared to when this is written, you may need to adjust the classpath 'com.android.tools.build:gradle:0.6.+'
line to reference a newer version of the Gradle plugin. Soon we will require version 0.7 or later. Try it out, and if you get an error that a newer version of the Gradle plugin is required, that's the line you have to edit.
Make sure the Android Support Library in your SDK manager is installed.
Edit your settings.gradle
file in your application’s main directory
and add this line:
include ':libraries:facebook'
If your project is already open in Android Studio, click the "Sync Project with Gradle Files" button in the toolbar. Once it's done, the facebook
module should appear.