6

I want to integrate my app with facebook login, but when adding below dependency and syncing Gradle:

implementation 'com.facebook.android:facebook-android-sdk:[5,6)'

I got the following errors:

ERROR: Failed to resolve: legacy-support-v4
Affected Modules: app


ERROR: Failed to resolve: browser
Affected Modules: app


ERROR: Failed to resolve: legacy-support-core-utils
Affected Modules: app


ERROR: Failed to resolve: media
Affected Modules: app

My build.gradle in app-level:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/'}
    }
}

repositories { }

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.***************"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.firebase:firebase-analytics:17.2.1'
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
    implementation 'com.github.GrenderG:Toasty:1.4.1'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
    implementation 'com.gauravk.bubblenavigation:bubblenavigation:1.0.7'
    implementation 'com.tuyenmonkey:mkloader:1.4.0'
    implementation 'me.riddhimanadib.form-master:form-master:1.1.0'
    implementation 'com.facebook.android:facebook-android-sdk:[5,6)'

}

apply plugin: 'com.google.gms.google-services'

and build.gradle on project-level:

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'io.fabric.tools:gradle:1.31.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://www.jitpack.io" }
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I've searched a lot on google and StackOverflow and tested all the methods, but this problem doesn't fix. Please help me where is my problem.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

4 Answers4

7

First of all remove

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/'}
    }
}

repositories { }

from your app-level Gradle file when you have repositories set in your project-level Gradle file. This causes confusion.

Use implementation 'com.facebook.android:facebook-android-sdk:5.13.0' instead of your dependency.

You can always check Maven Centeral for the latest version of libraries.

or

Use Gradle, please, just enter the library name you need and copy the result (don't forget to replace compile with implementation)

feridok
  • 648
  • 7
  • 26
  • Thank you @feridok , but your solution does not work for me, unfortunately, I encountered this error: `ERROR: Failed to resolve: legacy-support-core-utils Affected Modules: app`. – Mohammadreza Yektamaram Jan 10 '20 at 20:40
2

I've tested some of Facebook SDK versions, suddenly in 4.26.0 version, my Gradle was successfully built. I've checked the release note of Facebook SDK on the next version ( 4.27.0 ) and I find this:

Modified
+ Restructured the Facebook SDK and organized it into separate libraries/modules that can depend on one another.
+ Moves GraphRequest.createOpenGraphObject(ShareOpenGraphObject) to ShareGraphRequest.createOpenGraphObject(ShareOpenGraphObject)
+ Moves FacebookSDK.[set|get]WebDialogTheme(...) to WebDialog.[set|get]WebDialogTheme(...)
+ Removes unused dimens from styles.xml
+ Removes files only used by internal tests
+ updates proguard files

Anyway, with the following line, my problem was solved:

implementation 'com.facebook.android:facebook-android-sdk:4.26.0'

It's not good news for me to use about 3 years ago package, but at this point, I don't have any Idea.

1

Looks like you're pointing to a library that doesn't exist. Replace your implementation.... with:

implementation 'com.facebook.android:facebook-login:[5,6)'

(source: https://developers.facebook.com/docs/android/componentsdks/)

Sean
  • 5,176
  • 2
  • 34
  • 50
0

As Stated in this post, you need to add these two properties to gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true
Aorlinn
  • 718
  • 5
  • 16