【问题标题】:react-native-fb sdk com.android.support dependency errorreact-native-fb sdk com.android.support 依赖错误
【发布时间】:2017-12-06 13:36:14
【问题描述】:
 > A problem occurred configuring project ':react-native-fbsdk'.
  > Could not resolve all dependencies for configuration ':react-native-fbsdk:_debugPublishCopy'.
     > Could not find com.android.support:appcompat-v7:27.0.1.
       Searched in the following locations:
           file:/<location_to_sdk>/sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.pom
           file:/<location_to_sdk>/sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
           file:/<location_to_app>/android/sdk-manager/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
       Required by:
           newPtMobile:react-native-fbsdk:unspecified

这个问题从今天早上开始出现,当时运行 react-native run-android 没有对代码进行任何更改或添加新包,它一直运行良好!

"react-native":"0.50.3", "react-native-fbsdk":"0.6.3"

我可以看到我的sdk/extras/android/m2repository/com/android/support 子文件夹中缺少android support libraries,所有子文件夹都将26.0.0-alpha1 文件夹作为最后一个文件夹。 我已经尝试删除支持存储库并通过 android studio 重新安装并手动下载最新的android_m2repository,但文件夹仍然丢失。

我无法理解的是为什么 google's maven repository (https://dl.google.com/dl/android/maven2/index.html) 声明在 例如 m2repository/com/android/support/appcompat-v7 我应该有一个名为 27.0.2 的文件夹(以及一些以前的版本也不见了),但即使在他们提供的最新的 android_m2repository 中也不见了!

https://dl.google.com/android/repository/android_m2repository_r48.zip

【问题讨论】:

    标签: android react-native react-native-fbsdk


    【解决方案1】:

    我也有同样的问题。我能够通过更新我的
    ROOT : android/build.gradle 文件成功构建。

    步骤:
    1. 您所要做的就是在allprojects 部分为maven.google.com 添加一个新的maven
    2.添加resolutionStrategy将限制你的android fbsdk版本为4.28.0

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

    【讨论】:

    • 谢谢,当我添加 maven.google.com 时,它会下载丢失的项目。但就我而言,我还必须将我的 android/app/build.gradle 和 android/build.gradle 更改为 26 , 27.0.2
    • 是的,您将获得更新 项目:android/app/build.gradle 以及您在项目中链接的所有库。 FBSDK : android/build.gradle to 26 , 27.0.2 @chii
    【解决方案2】:

    我看到另一个线程在同样的问题上打开了:getting error when run react-native run-android

    这里推荐的解决方案是接近 Sutani 的一种,即编辑node_modules/react-native-fbsdk/android/build.gradle 并添加

    compile('com.facebook.android:facebook-android-sdk:4.28.0')

    这似乎不是 react-native-fbsdk 引入的回归,而是 Google Android 库引入的,但我不是 100% 清楚。

    【讨论】:

      【解决方案3】:

      我有同样的问题,我解决了:

      1. 编辑package.json,我将react-native-fbsdkreact-native-fbsdk": "0.6.3"编辑到react-native-fbsdk": "0.6.0"

      2. 转到您的node_modules/react-native-fbsdk/android/build.gradle。打开build.gradle file.

      3. compile('com.facebook.android:facebook-android-sdk:4++')更改为compile('com.facebook.android:facebook-android-sdk:4.22.1')

      但我不知道这是否是解决此问题的最佳方法, 谢谢

      【讨论】:

        【解决方案4】:
        CUR_SPACE=.
        culpritLocation=$CUR_SPACE/node_modules/react-native-fbsdk/android/build.gradle
        
        sed -i -e 's/com.facebook.android:facebook-android-sdk:4.+/com.facebook.android:facebook-android-sdk:4.26.0/' $culpritLocation
        
        printf "Fixed Could not resolve all dependencies for configuration ':react-native-fbsdk:_debugPublishCopy'.\n> Could not find com.android.support:appcompat-v7:27.0.1."
        printf "fix_rn_fbsdk_google_libraries.sh should be removed at a later time\n"
        

        将上述脚本放在你的 react-native 项目的根目录下,为其添加执行权限,然后在 postinstall 属性中的 package.json 中添加 ./your-script-name .sh;。例如:

        {
          "name": "AppName",
          "version": "1.28.14",
          "scripts": {
            "start": "node node_modules/react-native/local-cli/cli.js start",
            "postinstall": "./fix_rn_fbsdk_google_libraries.sh; ./infuse_version.sh;"
          },
          [..]
        }
        

        如果您不熟悉安装后脚本,它们会在运行 npm install / yarn 命令后立即运行。

        建议的解决方案适用于云构建工具:),它只是暂时的。未来的 rn-fbsdk 版本应该会解决这个问题。

        【讨论】:

        • 您能否详细描述您的答案以便清楚理解。
        • 如原始评论中所述,您必须在项目的根文件夹中创建一个文件 your-script-name.sh,然后添加(如果尚未添加)使用 package.json 文件中的 postinstall 属性。如果脚本具有执行权限并且内容是原始答案中的内容,它将解决问题。
        【解决方案5】:

        关键在于您的案例中显示的错误消息:

        在以下位置搜索: file:/&lt;location_to_sdk&gt;/sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/

        我也遇到过。然后我去了地点:

        file:&lt;location_to_sdk&gt;/sdk/extras/android/m2repository/com/android/support/appcompat-v7/

        发现没有名为27.0.1的目录,因为在我的情况下,没有下载最新的buildTool。就我而言,我有27.0.0-alpha1

        所以在我的应用程序build.gradle

        node_modules/react-native-fbsdk/android/build.gradle

        我将27.0.1 替换为27.0.0-alpha1,构建成功。

        【讨论】:

          【解决方案6】:

          build.gradle --- 应用程序

          dependencies {
              compile 'com.facebook.react:react-native:+' // support react-native-v0.22-rc+
              compile('com.facebook.android:facebook-android-sdk:4.+')
          }
          
              allprojects {
                  repositories {
                      configurations.all {
                          resolutionStrategy {
                              force 'com.facebook.android:facebook-android-sdk:4.28.0'
                          }
                      }
                  }
              }
          
          
          Solution:
          
          How to fix the file permissions, after loading end react-native start
          
          First, Go to android folder
          
          cd android
          
          Now clean the project...
          
          gradlew clean //for Mac users, change gradlew to ./gradlew
          
          Now run the build process again in the root folder 
          cd ..
          react-native run-android
          
          Solved Issue Happy Coding!
          

          【讨论】:

            猜你喜欢
            • 2017-12-23
            • 1970-01-01
            • 1970-01-01
            • 2021-12-08
            • 2021-06-15
            • 2018-07-05
            • 2017-10-28
            • 2021-01-07
            • 2020-04-22
            相关资源
            最近更新 更多