运行 react-native run-android 时出错
Posted
技术标签:
【中文标题】运行 react-native run-android 时出错【英文标题】:Getting error when run react-native run-android 【发布时间】:2018-05-20 03:39:18 【问题描述】: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
【问题讨论】:
【参考方案1】:接受的答案可以解决问题,但更简洁的解决方案是限制 react native fbsdk 库中使用的 android fbsdk 版本。将以下代码添加到 project(root) build.gradle 确保所有库项目都使用指定版本的 fbsdk。
allprojects
repositories
...
configurations.all
resolutionStrategy
force 'com.facebook.android:facebook-android-sdk:4.28.0'
【讨论】:
啊,这行得通!在我的第一次尝试中,我把它放在了错误的 build.gradle 文件中。但是一旦我将它放在根 build.gradle 中,它就可以工作了。 确保你有最新的 build gradlecom.android.tools.build:gradle:3.0.1
否则它仍然可能无法工作!【参考方案2】:
我今天也遇到了同样的问题。
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')
这是一个非常糟糕的解决方案。
如果您能找到解决问题的正确方法 - 请分享。
【讨论】:
它对我有用,但我已更改为 4.28.0 版。一个好的做法是始终指定库版本而不是使用加号。 多亏了你,我解决了一个与此问题相关的一周结束问题。非常感谢。【参考方案3】:我从今天早上开始遇到同样的问题,据我所知,这是 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_m2repository: 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')
但我仍然无法构建,我相信即使您能够构建,这也不是正确的方法!
【讨论】:
【参考方案4】:按照这些步骤,让您的构建成功
转到项目build.gradle file
添加maven url"https://maven.google.com"
将下载缺少的项目。
android/build.gradle file
和restrict fbsdk Version to 4.28.0
。
其他方式
转到 node_modules/react-native-fbsdk
: build.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"
【讨论】:
【参考方案5】:更新 Android Studio 为我解决了这个问题...
以下是我遵循的步骤
更新了 android-sdk(下载了 27 版和其他自动建议的平台和构建工具) 更新了 Android Studio 已同步依赖项目 Android Studio 自动要求更新 gradle 运行 react-native run-android 自动从 gradle-4.1-all.zip 下载依赖项,由于上述步骤中的 gradle 更新,该依赖项被自动添加到我的“gradle-wrapper.properties”文件中【讨论】:
更新 android studio 不是为我创建/home/ubuntu/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/
文件夹
@Anantkamat 更新了我的确切步骤。希望对您有所帮助...顺便说一句,appcompat-v7/27.0.1 文件夹也没有添加到我的 sdk 中...但是我不再收到错误消息...以上是关于运行 react-native run-android 时出错的主要内容,如果未能解决你的问题,请参考以下文章
为啥我的代码不能在 web 中的 react-native 代码中运行
React-Native 远程调试器无法在 iPhone 上运行