38

I tried via import module but I'm always getting

Error:(13, 0) Could not find property 'ANDROID_BUILD_MIN_SDK_VERSION' on project ':facebook'.

I didn't find a tutorial how to use the Facebook SDK with the latest Android Studio...

swalkner
  • 16,679
  • 31
  • 123
  • 210
  • TL;DR; Go to Tom Redman's answer and enjoy. And please upvote his answer as this is definitely the correct one as of today. – grandouassou Jan 24 '15 at 23:12
  • possible duplicate of [using facebook sdk in android studio](http://stackoverflow.com/questions/19961828/using-facebook-sdk-in-android-studio) – SBerg413 Apr 08 '15 at 20:09
  • This answer helped me to resolve the problem: http://stackoverflow.com/questions/29581771/can-not-import-facebook-sdk-4-0-1# – Shajeel Afzal Sep 03 '15 at 10:17

12 Answers12

138

Using Facebook SDK 3.23 in Android Studio 1.1 preview 2

Two choices :

*Maven Repository for the Facebook SDK.

dependencies {
    compile 'com.facebook.android:facebook-android-sdk:4.7.0'
}

check for the latest version facebook sdk

OR

*Follow the steps below:

1.Download facebook sdk https://developers.facebook.com/docs/android/

2.Unzip the archive facebook-android-sdk-3.23.0

3.File menu->Import Module

4.Chose “facebook” folder inside the unzipped archive.

5.Go to directory facebook/build.gradle change this part

This:

 compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
    buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

    defaultConfig {
        minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
        targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
    }

To proper sdk version

example:

 compileSdkVersion 21
        buildToolsVersion '21.1.1'

        defaultConfig {
            minSdkVersion 14
            targetSdkVersion 21
        }

6.Click your project and press F4 ,go to 'dependencies' tab, click '+', 'module dependency' and select your imported facebook module.

7.Resync and rebuild

Cristiana Chavez
  • 11,349
  • 5
  • 55
  • 54
  • 1
    This worked for me, thanks! However, I got build error after this and then resolved by replacing 'libs/bolts.jar' with 'libs/bolts-android-1.1.2.jar', which is the exact file name of bolts lib. – Eric Fan Sep 01 '14 at 12:29
  • 1
    @EricFan thats right because facebook sdk updated to version 3.17.2 and they renamed the bolts.jar into bolts-android-1.1.2.jar – Cristiana Chavez Sep 02 '14 at 03:38
  • 2
    Worked for me on AS 0.8.9 updating some fields just for warnings – MiguelHincapieC Oct 10 '14 at 23:09
  • I haven't done point 5 and directly move to 6, build worked perfectly ! I suppose replacing facebook/build.gradle is not always necessary. – tufekoi Oct 21 '14 at 22:05
  • The build.gradle file in the facebook module was pretty extensive, and I was afraid to get rid of all of it, so from the above I just added the buildscript section and changed the android section to have integers instead of constants (e.g., 21 instead of `project.ANDROID_BUILD_SDK_VERSION`) – hBrent Oct 27 '14 at 22:09
  • On the current version 3.19.1, I had to modify only the sdk constants and add these lines: repositories { mavenCentral() } – schystz Oct 28 '14 at 11:23
  • I have error after following above steps.. can not find `com.parse.bolts:bolts-android:1.1.2` – Dharmik Nov 18 '14 at 12:09
  • 2
    For anybody still wondering, there is finally an official Maven repo for the Facebook SDK: dependencies { compile 'com.facebook.android:facebook-android-sdk:3.20.0' } – Tom Redman Nov 24 '14 at 19:51
  • 1
    This solution worked for me (I only had to fine tune target SDK version and minimum SDK version) and it should be the accepted answer. – Luke47 Dec 18 '14 at 09:57
  • @Cristiana214 i got this error when i used your first solution the Maven one – Sagar Devanga Feb 03 '15 at 10:00
  • @SagarDevanga 2nd one is the perfect solution. – Cristiana Chavez Feb 05 '15 at 11:39
  • I am getting: Error:(24, 13) Failed to resolve: com.facebook.android:facebook-android-sdk:3.23.+ I'm not sure as to why though. I have the repository added in my top-level build.gradle and added the appropriate compile to dependencies in the app level build.gradle. – Hanny Mar 17 '15 at 16:30
  • 1
    @Hanny inside the app the same level of build,src,and libs there is build.gradle add compile 'com.facebook.android:facebook-android-sdk:3.23.+' to dependencies – Cristiana Chavez Mar 18 '15 at 03:30
  • @Cristiana214: Are you sure that just adding the maven repository does the trick? Because It still does for me – Ashwin Mar 28 '15 at 11:24
  • @Cristiana214 : getting this error for your second solution. Please help – Sagar Devanga Jul 06 '15 at 09:36
28

For anybody still wondering, there is finally an official Maven repo for the Facebook SDK:

dependencies {
    compile 'com.facebook.android:facebook-android-sdk:3.20.0'
}
Tom Redman
  • 5,592
  • 4
  • 34
  • 42
17

Write all those variables values in "gradle.properties" file.

Like

ANDROID_BUILD_TARGET_SDK_VERSION=19
ANDROID_BUILD_TOOLS_VERSION=19.1.0
ANDROID_BUILD_SDK_VERSION=19
ANDROID_BUILD_MIN_SDK_VERSION=14

You can follow this post https://stackoverflow.com/a/20221453/1232520

Community
  • 1
  • 1
Bhupinder
  • 1,329
  • 1
  • 14
  • 29
7

add these line in your gradle.properties it work for me!

ANDROID_BUILD_TARGET_SDK_VERSION=19
ANDROID_BUILD_TOOLS_VERSION=19.1.0
ANDROID_BUILD_SDK_VERSION=19
ANDROID_BUILD_MIN_SDK_VERSION=14

After do this plese follow step describe in this post https://stackoverflow.com/a/24457464/3296641

Community
  • 1
  • 1
Aneh Thakur
  • 1,072
  • 12
  • 20
5

Now you can use version 3.21.1 from maven

https://developers.facebook.com/docs/android/

dependencies {
       compile 'com.facebook.android:facebook-android-sdk:3.21.1'
}
Mahmud Ahsan
  • 1,755
  • 19
  • 18
3

You can now get Facebook SDK with gradle:

compile 'com.facebook.android:facebook-android-sdk:3.20.0'
Defuera
  • 5,356
  • 3
  • 32
  • 38
2

You can get rid of the

"Error:(13, 0) Could not find property 'ANDROID_BUILD_MIN_SDK_VERSION'"

by replacing all the values like below see your build.gradle . you can find all the properties and the versions your application is using. replace the values of 'buld.gradle file' from facebook sdk with the same versions.

 android {
    compileSdkVersion 19 
    buildToolsVersion "20.0.0"

    defaultConfig {
         minSdkVersion 8
        targetSdkVersion 19
     }

and for BOLT.JAR Error, there is a dependacy in facebook sdk build.gradle file like compile "files('../libs/bolts.jar')" this is actually for the whole sdk folder which we download, but as we use only facebook folder so we have one less directory path to follow. Hence, you can get rean of one period before /libs so just remove it and keep it as compile files ('./libs/bolts.jar')

you are good to go !!

Cristiana Chavez
  • 11,349
  • 5
  • 55
  • 54
punkb
  • 53
  • 12
2

Simply just go to project structure and select dependency enter image description here

then click + on the right top corner and select library dependency (the first option ) and just type facebook or if you need any other lib and click a search icon (MAKE SURE YOU HAVE INTERNET CONNECTION) and select com.facebook.android:facebook-android-sdk:.... and you are good to go enter image description here

Nasz Njoka Sr.
  • 1,138
  • 16
  • 27
2

EXPLINATION:

The following constants can be defined in your project gradle.properties:

ANDROID_BUILD_MIN_SDK_VERSION=15
ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION=21.1.2
ANDROID_BUILD_SDK_VERSION=21

Those are used in the Facebook sdk as build gradle settings. To specify your use of the sdk. (it's encouraged that those values match your project values!).

"Code Reusability and Dependancy!" you can use those same values as gradle build settings in all build.gradle files for your project and all other modules inside your project. use them they same way they are used in the Facebook build.gradle file.

Example Benefit: Changing the minimum sdk version on gradle.properties will automatically change it for all your modules build.gradle.

hasan
  • 23,815
  • 10
  • 63
  • 101
  • give professional answer. But why this declaration not affected to - compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)? – Ranjithkumar Jun 17 '15 at 11:17
  • I didn't work on Android since that time. I forgot. but what I can remember that I asked myself the same question and I am not sure if I found an explanation or not. – hasan Jun 17 '15 at 12:55
  • I think it is affected. but you can't use this in all files. Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION) can't get compiled in some files. – hasan Jun 17 '15 at 12:56
1

Add the compile dependency with the latest version of the Facebook SDK in the build.gradle file:

 dependencies { 
      compile 'com.facebook.android:facebook-android-sdk:4.14.0'
    }

For more info https://developers.facebook.com/docs/android/getting-started

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

For those who do not know where to put gradle.properties, it should go to the root of the project. This is how it looks in one of my projects.

sandalone
  • 41,141
  • 63
  • 222
  • 338
0

I recently came across an error that was not resolved here yet. I tried to use the latest Facebook SDK from maven (by declaring compile 'com.facebook.android:facebook-android-sdk:4.6.0'). After gradle build I got no error and Android studio's static code analysis was also OK when declaring and writing FacebookSdk related code. However when I tried to run the code in the emulator, I got an error that facebook sdk is not included in the project. Then I tried some other hacks and then I finally removed the facebook entry from the gradle build file and tried to import it as a module, but that also did't work.

After a while when I was reading Facebook gradle file I realized that they are compiling the code with "sourceCompatibility JavaVersion.VERSION_1_7" flag. I used VERSION_1_8 flag because I wanted to use lambda's using retrolambda library. After I switched to 1.7 (and also adjusted the settings in File -> Project structure -> Source Compatibility) it started to work and there were no problems.

I quite don't understand why (and if) is this related together, but it probably is so be aware of that.

vanomart
  • 1,739
  • 1
  • 18
  • 39