在Android中添加Facebook登录依赖项后出现错误

时间:2020-01-04 13:02:32

标签: java android facebook android-gradle-plugin facebook-android-sdk

我想将我的应用程序与Facebook登录信息集成在一起,但是在添加以下依赖项并同步Gradle时:

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

我遇到以下错误:

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

我在应用程序级别的 build.gradle

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'
在项目级别上

build.gradle

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
}

我在google和StackOverflow上进行了大量搜索,并测试了所有方法,但是此问题无法解决。请帮我解决我的问题。

4 个答案:

答案 0 :(得分:3)

首先删除

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

repositories { }
当您在项目级Gradle文件中设置了存储库时,从您的应用程序级Gradle文件中

。这会引起混乱。

使用implementation 'com.facebook.android:facebook-android-sdk:5.13.0'而不是您的依赖项。

您随时可以在Maven Centeral中查看库的最新版本。

使用Gradle, please,只需输入所需的库名称并复制结果即可(不要忘记将编译替换为实现)

答案 1 :(得分:2)

我已经测试了一些Facebook SDK版本,突然在 4.26.0 版本中,我的Gradle已成功构建。 我已经查看了下一个版本( 4.27.0 )上的Facebook SDK的发行说明,并且发现了这一点:

已修改
+重组了Facebook SDK,并将其组织为可以相互依赖的单独的库/模块。
+将GraphRequest.createOpenGraphObject(ShareOpenGraphObject)移到ShareGraphRequest.createOpenGraphObject(ShareOpenGraphObject)
+将FacebookSDK。[set | get] WebDialogTheme(...)移至WebDialog。[set | get] WebDialogTheme(...)
+从styles.xml中删除未使用的调暗
+删除仅由内部测试使用的文件
+更新proguard文件

无论如何,使用以下代码行,我的问题已解决:

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

使用大约3年前的包裹对于我来说不是一个好消息,但是目前我还没有任何想法。

答案 2 :(得分:1)

好像您要指向一个不存在的库。 将您的implementation....替换为:

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

(来源:https://developers.facebook.com/docs/android/componentsdks/

答案 3 :(得分:0)

this post中所述,您需要将这两个属性添加到 gradle.properties 文件中:

android.useAndroidX=true
android.enableJetifier=true