用于 React Native 的 Facebook SDK - Android 在干净的项目上失败

Facebook SDK for React Native - Android fails on clean project

我正在尝试在我的项目中使用 facebook/react-native-fbsdk。在 iOS 上一切顺利,但我无法在 Android 上正确设置。

我的设置如下:

  "dependencies": {
    "react": "16.2.0",
    "react-native": "0.52.0",
    "react-native-fbsdk": "^0.7.0"
  }

我已按照官方文档的说明进行操作https://developers.facebook.com/docs/react-native/configure-android-current

项目构建失败,控制台输出如下

Scanning folders for symlinks in /Users/szucsnorbert/fbsdk-android/node_modules (9ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Incremental java compilation is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
   > Could not find com.android.support:appcompat-v7:27.0.2.
     Searched in the following locations:
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.2/appcompat-v7-27.0.2.pom
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.2/appcompat-v7-27.0.2.jar
         file:/Users/szucsnorbert/fbsdk-android/android/sdk-manager/com/android/support/appcompat-v7/27.0.2/appcompat-v7-27.0.2.jar
     Required by:
         fbsdkandroid:app:unspecified
         fbsdkandroid:app:unspecified > com.facebook.react:react-native:0.52.0
   > Could not find com.android.support:appcompat-v7:27.0.2.
     Searched in the following locations:
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.2/appcompat-v7-27.0.2.pom
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.2/appcompat-v7-27.0.2.jar
         file:/Users/szucsnorbert/fbsdk-android/android/sdk-manager/com/android/support/appcompat-v7/27.0.2/appcompat-v7-27.0.2.jar
     Required by:
         fbsdkandroid:app:unspecified > fbsdkandroid:react-native-fbsdk:unspecified
         fbsdkandroid:app:unspecified > fbsdkandroid:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.31.0 > com.facebook.android:facebook-common:4.31.0
         fbsdkandroid:app:unspecified > fbsdkandroid:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.31.0 > com.facebook.android:facebook-login:4.31.0
   > Could not find com.android.support:support-annotations:27.0.2.
     Searched in the following locations:
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/support-annotations/27.0.2/support-annotations-27.0.2.pom
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/support-annotations/27.0.2/support-annotations-27.0.2.jar
         file:/Users/szucsnorbert/fbsdk-android/android/sdk-manager/com/android/support/support-annotations/27.0.2/support-annotations-27.0.2.jar
     Required by:
         fbsdkandroid:app:unspecified > fbsdkandroid:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.31.0 > com.facebook.android:facebook-core:4.31.0
   > Could not find com.android.support:support-core-utils:27.0.2.
     Searched in the following locations:
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/support-core-utils/27.0.2/support-core-utils-27.0.2.pom
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/support-core-utils/27.0.2/support-core-utils-27.0.2.jar
         file:/Users/szucsnorbert/fbsdk-android/android/sdk-manager/com/android/support/support-core-utils/27.0.2/support-core-utils-27.0.2.jar
     Required by:
         fbsdkandroid:app:unspecified > fbsdkandroid:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.31.0 > com.facebook.android:facebook-core:4.31.0
   > Could not find com.android.support:support-v4:27.0.2.
     Searched in the following locations:
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/support-v4/27.0.2/support-v4-27.0.2.pom
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/support-v4/27.0.2/support-v4-27.0.2.jar
         file:/Users/szucsnorbert/fbsdk-android/android/sdk-manager/com/android/support/support-v4/27.0.2/support-v4-27.0.2.jar
     Required by:
         fbsdkandroid:app:unspecified > fbsdkandroid:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.31.0 > com.facebook.android:facebook-common:4.31.0
   > Could not find com.android.support:cardview-v7:27.0.2.
     Searched in the following locations:
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/cardview-v7/27.0.2/cardview-v7-27.0.2.pom
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/cardview-v7/27.0.2/cardview-v7-27.0.2.jar
         file:/Users/szucsnorbert/fbsdk-android/android/sdk-manager/com/android/support/cardview-v7/27.0.2/cardview-v7-27.0.2.jar
     Required by:
         fbsdkandroid:app:unspecified > fbsdkandroid:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.31.0 > com.facebook.android:facebook-common:4.31.0
   > Could not find com.android.support:customtabs:27.0.2.
     Searched in the following locations:
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/customtabs/27.0.2/customtabs-27.0.2.pom
         file:/Users/szucsnorbert/Library/Android/sdk/extras/android/m2repository/com/android/support/customtabs/27.0.2/customtabs-27.0.2.jar
         file:/Users/szucsnorbert/fbsdk-android/android/sdk-manager/com/android/support/customtabs/27.0.2/customtabs-27.0.2.jar
     Required by:
         fbsdkandroid:app:unspecified > fbsdkandroid:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.31.0 > com.facebook.android:facebook-common:4.31.0

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 10.48 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

我认为这是一个版本兼容性问题。有没有人让它与不同的版本一起工作?我在这里遗漏了什么吗?

我添加了以下内容:

  1. 将 Maven 存储库添加到 google

添加到 android/build.gradle

maven {
    url "https://maven.google.com"
}
  1. 强制使用更早的 SDK 版本

添加到 android/build.gradle

configurations.all {
    resolutionStrategy {
        force 'com.facebook.android:facebook-android-sdk:4.22.1'
    }
}

文件 android/build.gradle 应如下所示:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
        configurations.all {
            resolutionStrategy {
                force 'com.facebook.android:facebook-android-sdk:4.22.1'
            }
        }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}