运行react-native run-android时出错

时间:2017-12-06 09:46:56

标签: android gradle react-native

A problem occurred configuring project ':app'.
   > Could not resolve all dependencies for configuration ':app:_debugApk'.
     > 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:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified
         > Could not find com.android.support:appcompat-v7:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.react:react-native:0.46.4
         > Could not find com.android.support:support-annotations:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-annotations/27.0.1/support-annotations-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-annotations/27.0.1/support-annotations-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/support-annotations/27.0.1/support-annotations-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-core:4.29.0
         > Could not find com.android.support:support-core-utils:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-core-utils/27.0.1/support-core-utils-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-core-utils/27.0.1/support-core-utils-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/support-core-utils/27.0.1/support-core-utils-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-core:4.29.0
         > Could not find com.android.support:appcompat-v7:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-common:4.29.0
         > Could not find com.android.support:cardview-v7:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/cardview-v7/27.0.1/cardview-v7-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/cardview-v7/27.0.1/cardview-v7-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/cardview-v7/27.0.1/cardview-v7-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-common:4.29.0
         > Could not find com.android.support:customtabs:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/customtabs/27.0.1/customtabs-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/customtabs/27.0.1/customtabs-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/customtabs/27.0.1/customtabs-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-common:4.29.0
         > Could not find com.android.support:support-v4:27.0.1.
           Searched in the following locations:
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-v4/27.0.1/support-v4-27.0.1.pom
             file:/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/support-v4/27.0.1/support-v4-27.0.1.jar
             file:/home/ubuntu/git/mstore-pro/android/sdk-manager/com/android/support/support-v4/27.0.1/support-v4-27.0.1.jar
           Required by:
             beostore:react-native-fbsdk:unspecified > com.facebook.android:facebook-android-sdk:4.29.0 > com.facebook.android:facebook-common:4.29.0

compileSdkVersion 25

buildToolsVersion" 25.0.0"

targetSdkVersion 25

5 个答案:

答案 0 :(得分:34)

接受的答案可以解决问题,但更清晰的解决方案是限制反应原生fbsdk库中使用的android fbsdk版本。将以下代码添加到项目(root)build.gradle中,确保所有库项目都使用指定版本的fbsdk。

allprojects {
    repositories {
        ...
        configurations.all {
            resolutionStrategy {
                force 'com.facebook.android:facebook-android-sdk:4.28.0'
            }
        }
    }
}

答案 1 :(得分:12)

我今天遇到了同样的问题。

react-native-fbsdk包看起来有些问题;

我现在找到了解决问题的唯一方法:

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

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

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

这是一个非常糟糕的解决方案。

如果你能找到解决问题的正确方法 - 请分享。

答案 2 :(得分:7)

我今天早上有同样的问题,据我所知,这是react-native-fbsdk库和android支持库的问题。

如果你进入安装sdk的路径上的任何子文件夹(在你的情况下)" home / ubuntu / Android / Sdk / extras / android / m2repository / com / android / support"你可能会看到" 26.0.0-alpha1"作为最后一个文件夹即使google(https://dl.google.com/dl/android/maven2/index.html - collapse com.android.support)明确建议最后一个文件夹应该是" 27.0.2"!

我尝试从获取的链接下载最新的android_m2存储库: https://dl.google.com/android/repository/android_m2repository_r47.zip 但它也缺少以下所有文件夹: 26.0.0-beta1,26.0.0-beta2,26.0.0,26.0.1,26.0.2,26.1.0,27.0.0,27.0.1,27.0.2

我设法通过编辑node_modules / react-native-fbsdk / android / build.gradle来删除错误

编译(' com.facebook.android:Facebook的Android的SDK:4.28.0&#39)

但我仍然无法建立,我相信即使你能够建立,这也不是正确的方法!

答案 3 :(得分:5)

按照以下步骤进行构建

  1. 转到项目build.gradle file添加maven {url"https://maven.google.com"}将下载缺失的项目。

  2. android/build.gradle filerestrict fbsdk Version to 4.28.0

  3. 其他方式

    转到node_modules/react-native-fbsdkbuild.gradle更改为compileSdkVersion 26或27

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

答案 4 :(得分:0)

更新Android工作室为我解决了这个问题......

以下是我遵循的步骤

  • 更新了android-sdk(下载的平台和版本27的构建工具以及其他汽车建议)
  • 更新了Android Studio
  • 同步依赖项目
  • Android Studio自动要求更新gradle
  • 从gradle-4.1-all.zip运行react-native run-android自动下载的依赖项,由于上一步的gradle更新,它自动添加到我的“gradle-wrapper.properties”文件中