React native buld 失败并显示以下消息 Failed to list versions for com.facebook.react:react-native

Posted

技术标签:

【中文标题】React native buld 失败并显示以下消息 Failed to list versions for com.facebook.react:react-native【英文标题】:React native buld failed with the following message Failed to list versions for com.facebook.react:react-native 【发布时间】:2022-01-23 21:05:23 【问题描述】:

我正在使用 ReactNative 版本 0.62.2,当我尝试使用命令运行应用程序时

react-native run-android 构建失败并显示以下错误消息

Could not determine the dependencies of task ':app:mergeDebugAssets'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve com.facebook.react:react-native:+.
     Required by:
         project :app
         project :app > project :react-native-fs
         project :app > project :react-native-community_async-storage
         project :app > project :react-native-community_datetimepicker
         project :app > project :react-native-community_slider
         project :app > project :react-native-firebase_analytics
         project :app > project :react-native-firebase_app
         project :app > project :react-native-firebase_storage
         project :app > project :react-native-audio
         project :app > project :react-native-document-picker
         project :app > project :react-native-file-selector
         project :app > project :react-native-get-random-values
         project :app > project :react-native-image-crop-picker
         project :app > project :react-native-navigation
         project :app > project :react-native-scan-barcode
         project :app > project :react-native-track-player
         project :app > project :react-native-vector-icons
         project :app > project :react-native-video
      > Failed to list versions for com.facebook.react:react-native.
         > Unable to load Maven meta-data from http://dl.bintray.com/lukaville/maven/com/facebook/react/react-native/maven-metadata.xml.
            > Could not get resource 'http://dl.bintray.com/lukaville/maven/com/facebook/react/react-native/maven-metadata.xml'.
               > Could not GET 'http://dl.bintray.com/lukaville/maven/com/facebook/react/react-native/maven-metadata.xml'. Received status code 502 from server: Bad Gateway

不知道为什么它现在会失败,因为之前它构建正确

构建.gradle

buildscript 
    ext 
        RNNKotlinVersion = "1.3.61"
        buildToolsVersion = "28.0.3"
        minSdkVersion = 19
        compileSdkVersion = 28
        targetSdkVersion = 28
        RNNKotlinStdlib = "kotlin-stdlib-jdk8"
    
    repositories 
        google()
        jcenter()
        mavenLocal()
        mavenCentral()
    
    dependencies 
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
        classpath("com.android.tools.build:gradle:3.5.2")
        classpath 'com.google.gms:google-services:4.3.3'

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

【问题讨论】:

能否提供您项目的 GitHub repo 链接,以便我们更好地分析问题? 您需要先接受 sdk 工具的许可 【参考方案1】:

Bintray 服务已关闭,解决此问题的唯一方法是迁移到不再使用此 repo 的 React Native 0.65。

【讨论】:

【参考方案2】:

是的,我找到了一个可行的解决方案,但不确定它是否是一个好的解决方案。

我在 android -> build.gradle

中使用了以下内容,而不是 bintray 服务
allprojects 
    repositories 
        mavenLocal()
        maven 
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        
        maven 
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        

        google()
        jcenter()
        maven  url 'https://www.jitpack.io' 
        maven  url 'http://dl.bintray.com/lukaville/maven' 
    

我已将 bintray 替换为 https://repo1.maven.org/maven2,如下所示

allprojects 
    repositories 
        mavenLocal()
        maven 
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        
        maven 
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        

        google()
        jcenter()
        maven  url 'https://www.jitpack.io' 
        maven  url 'https://repo1.maven.org/maven2' 
    

当我构建应用程序时,构建成功。

【讨论】:

【参考方案3】:

只需断开与互联网的连接并构建您的项目,一旦构建完成并启动应用程序,您就可以重新连接。

【讨论】:

我刚刚尝试@devgeek 回答,将 react-native 从 v0.64.* 升级到最新版本,它解决了问题

以上是关于React native buld 失败并显示以下消息 Failed to list versions for com.facebook.react:react-native的主要内容,如果未能解决你的问题,请参考以下文章

react-native-maps 构建失败

React Native:Android 构建失败并出现异常 - 安装在模拟器上

React Native 中获取后的条件渲染

如何修复 Android Studio 中的 React Native 应用程序错误?

未启用远程调试器时,React Native Detox 测试失败

react-native run-android失败,出现“Task:app:compileDebugJavaWithJavac FAILED”安装后的react-native-fbsdk