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
Facebook has indeed added the SDK to the Maven Central repositories. To configure your project using the maven repo's instance, you'll need to do 2 things:
In your projects top-level build.gradle file, add the Maven Central repositories. Mine looks like this:
In the app-level build.grade file, add the Facebook sdk dependency:
You can also adjust the specific Facebook SDK version as well. For a list of available versions in the maven repository click this link.
*Gradle Repository for the Facebook SDK.
Search for the latest version facebook sdk
I have used facebook sdk 4.10.0 to integrate login in my android app. Tutorial I followed is :
facebook login android studio
You will be able to get first name, last name, email, gender , facebook id and birth date from facebbok.
Above tutorial also explains how to create app in facebook developer console through video.
add below in
build.gradle(Module:app)
file:and
now add below in AndroidManifest.xml file :
add following in activity_main.xml file :
And in last add below in MainActivity.java file :
I fixed the
error on the
build.gradle
file, by adding ingradle.properties
the values:Source: https://stackoverflow.com/a/21490651/2161698
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 aHelloWorldProject/libraries
folder.Now copy the entire
facebook
directory from the SDK installation into thelibraries
folder you just created.Delete the
libs
folder in thefacebook
directory. If you like, delete theproject.properties
,build.xml
,.classpath
, and.project
. files as well. You don't need them.Create a
build.gradle
file in thefacebook
directory with the following contents: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: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.I deployed Facebook Android SDK to Sonatype repository.
You can include this library as Gradle dependency:
Original post here.