android - Facebook SDK 与 android 支持 26.+ 库冲突

标签 android facebook android-support-library

我正在尝试使用 Facebook 实现登录,我遵循了此处的指南 https://developers.facebook.com/docs/facebook-login/android 但每次我收到以下错误

Error:Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(26.0.0-alpha1) from [com.android.support:appcompat-v7:26.0.0-alpha1] AndroidManifest.xml:27:9-38 is also present at [com.android.support:cardview-v7:25.3.1] AndroidManifest.xml:24:9-31 value=(25.3.1). Suggestion: add 'tools:replace="android:value"' to element at AndroidManifest.xml:25:5-27:41 to override.

这是我的 Build.gradle 依赖项

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.jakewharton:butterknife:8.7.0'
    compile 'com.android.support:design:26.+'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.android.support:support-v4:26.+'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'

    compile 'com.facebook.android:facebook-android-sdk:4.+'
}

我试过 ass 建议添加 tools:value

   <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:replace="android:25.3.1">

如果不将我的编译 SDK 降级到 25,我该怎么做才能解决这个冲突?

最佳答案

你可能不再需要它,但有人可能需要它。

这解决了我的问题:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "your.package"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'

    // FB compatibility. Consider removing them when upgrading FB SDK
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.android.support:customtabs:26.1.0'
    implementation 'com.android.support:support-annotations:26.1.0'
    implementation 'com.android.support:support-core-utils:26.1.0'
    implementation('com.facebook.android:facebook-android-sdk:4.28.0') {
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'appcompat-v7'
        exclude group: 'com.android.support', module: 'cardview-v7'
        exclude group: 'com.android.support', module: 'customtabs'
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.android.support', module: 'support-core-utils'
    }

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

关于android - Facebook SDK 与 android 支持 26.+ 库冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45918583/

相关文章:

Android通过intent发送Twitter私信

android - Android 2.2 API 级别 8 中的 INSTALL_FAILED_MISSING_SHARED_LIBRARY 错误

Javascript - 使用循环在 Chrome 中查看旧的 Facebook 消息,不知道如何让它停止

fragment 和其他模板的 Android Studio 向导

android - 支持库版本

java - 使用 AppCompat 在 Android 中为按钮着色

android - CollapsingToolbarLayout 中的多行 TextView 而不是标题

android - 改造协程 livedata 仅第一次调用

facebook - 获取 Facebook Graph api 页面评论

ios - 使用 Phonegap 搜索和添加 Facebook 好友