【问题标题】:React Native: Android "Received status code 502 from server: Bad Gateway" from JCenter and Bintray being discontinuedReact Native:来自 JCenter 和 Bintray 的 Android“从服务器收到状态代码 502:Bad Gateway”已停止
【发布时间】:2022-01-13 04:46:22
【问题描述】:

请注意,这些是我发现有用的错误的 sn-ps,以及以“出了什么问题”开头的 sn-ps。在运行npx react-native run-android --verbose 之后(它一直有效,而且我的 android 开发环境肯定设置正确,因为这个项目昨天工作了):

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve com.facebook.react:react-native:+.
     Required by:
         project :app
         project :app > project :react-native-firebase_app
         project :app > project :react-native-firebase_auth
         project :app > project :react-native-google-signin_google-signin
         project :app > project :expo
         project :app > project :react-native-fbsdk-next
         project :app > project :react-native-gesture-handler
         project :app > project :react-native-safe-area-context
         project :app > project :react-native-screens
         project :app > project :expo > project :expo-modules-core
         project :app > project :expo > project :expo-splash-screen
         project :app > project :expo > project :expo-updates
      > Failed to list versions for com.facebook.react:react-native.
         > Unable to load Maven meta-data from https://jcenter.bintray.com/com/facebook/react/react-native/maven-metadata.xml.
            > Could not HEAD 'https://jcenter.bintray.com/com/facebook/react/react-native/maven-metadata.xml'. Received status code 502 from server: Bad Gateway

然后,我在我的 android 文件夹的 build.gradle 文件中删除了 jcenter() 的实例。我查看了这个答案https://stackoverflow.com/a/70417675/13368695,它说要这样做,以及删除其他两个 URL(我在任何文件中都没有)。结果是这样,下次我跑npx react-native run-android --verbose

Warning: The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin.
> Task :app:checkDebugAarMetadata FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find com.facebook.flipper:flipper:0.54.0.
     Searched in the following locations:
       - file:/Users/daggerpov/.m2/repository/com/facebook/flipper/flipper/0.54.0/flipper-0.54.0.pom
       - file:/Users/daggerpov/Documents/GitHub/GuestApplication/node_modules/react-native/android/com/facebook/flipper/flipper/0.54.0/flipper-0.54.0.pom
       - file:/Users/daggerpov/Documents/GitHub/GuestApplication/node_modules/jsc-android/dist/com/facebook/flipper/flipper/0.54.0/flipper-0.54.0.pom
       - https://dl.google.com/dl/android/maven2/com/facebook/flipper/flipper/0.54.0/flipper-0.54.0.pom
       - https://repo.maven.apache.org/maven2/com/facebook/flipper/flipper/0.54.0/flipper-0.54.0.pom
       - https://www.jitpack.io/com/facebook/flipper/flipper/0.54.0/flipper-0.54.0.pom
     Required by:
         project :app
   > Could not find com.facebook.flipper:flipper-network-plugin:0.54.0.
     Searched in the following locations:
       - file:/Users/daggerpov/.m2/repository/com/facebook/flipper/flipper-network-plugin/0.54.0/flipper-network-plugin-0.54.0.pom
       - file:/Users/daggerpov/Documents/GitHub/GuestApplication/node_modules/react-native/android/com/facebook/flipper/flipper-network-plugin/0.54.0/flipper-network-plugin-0.54.0.pom
       - file:/Users/daggerpov/Documents/GitHub/GuestApplication/node_modules/jsc-android/dist/com/facebook/flipper/flipper-network-plugin/0.54.0/flipper-network-plugin-0.54.0.pom
       - https://dl.google.com/dl/android/maven2/com/facebook/flipper/flipper-network-plugin/0.54.0/flipper-network-plugin-0.54.0.pom
       - https://repo.maven.apache.org/maven2/com/facebook/flipper/flipper-network-plugin/0.54.0/flipper-network-plugin-0.54.0.pom
       - https://www.jitpack.io/com/facebook/flipper/flipper-network-plugin/0.54.0/flipper-network-plugin-0.54.0.pom
     Required by:
         project :app
   > Could not find com.facebook.flipper:flipper-fresco-plugin:0.54.0.
     Searched in the following locations:
       - file:/Users/daggerpov/.m2/repository/com/facebook/flipper/flipper-fresco-plugin/0.54.0/flipper-fresco-plugin-0.54.0.pom
       - file:/Users/daggerpov/Documents/GitHub/GuestApplication/node_modules/react-native/android/com/facebook/flipper/flipper-fresco-plugin/0.54.0/flipper-fresco-plugin-0.54.0.pom
       - file:/Users/daggerpov/Documents/GitHub/GuestApplication/node_modules/jsc-android/dist/com/facebook/flipper/flipper-fresco-plugin/0.54.0/flipper-fresco-plugin-0.54.0.pom
       - https://dl.google.com/dl/android/maven2/com/facebook/flipper/flipper-fresco-plugin/0.54.0/flipper-fresco-plugin-0.54.0.pom
       - https://repo.maven.apache.org/maven2/com/facebook/flipper/flipper-fresco-plugin/0.54.0/flipper-fresco-plugin-0.54.0.pom
       - https://www.jitpack.io/com/facebook/flipper/flipper-fresco-plugin/0.54.0/flipper-fresco-plugin-0.54.0.pom
     Required by:
         project :app
   > Could not find com.facebook.yoga:proguard-annotations:1.14.1.
     Searched in the following locations:
       - file:/Users/daggerpov/.m2/repository/com/facebook/yoga/proguard-annotations/1.14.1/proguard-annotations-1.14.1.pom
       - file:/Users/daggerpov/Documents/GitHub/GuestApplication/node_modules/react-native/android/com/facebook/yoga/proguard-annotations/1.14.1/proguard-annotations-1.14.1.pom
       - file:/Users/daggerpov/Documents/GitHub/GuestApplication/node_modules/jsc-android/dist/com/facebook/yoga/proguard-annotations/1.14.1/proguard-annotations-1.14.1.pom
       - https://dl.google.com/dl/android/maven2/com/facebook/yoga/proguard-annotations/1.14.1/proguard-annotations-1.14.1.pom
       - https://repo.maven.apache.org/maven2/com/facebook/yoga/proguard-annotations/1.14.1/proguard-annotations-1.14.1.pom
       - https://www.jitpack.io/com/facebook/yoga/proguard-annotations/1.14.1/proguard-annotations-1.14.1.pom
     Required by:
         project :app > com.facebook.react:react-native:0.64.3
   > Could not find com.facebook.fbjni:fbjni-java-only:0.0.3.
     Searched in the following locations:
       - file:/Users/daggerpov/.m2/repository/com/facebook/fbjni/fbjni-java-only/0.0.3/fbjni-java-only-0.0.3.pom
       - file:/Users/daggerpov/Documents/GitHub/GuestApplication/node_modules/react-native/android/com/facebook/fbjni/fbjni-java-only/0.0.3/fbjni-java-only-0.0.3.pom
       - file:/Users/daggerpov/Documents/GitHub/GuestApplication/node_modules/jsc-android/dist/com/facebook/fbjni/fbjni-java-only/0.0.3/fbjni-java-only-0.0.3.pom
       - https://dl.google.com/dl/android/maven2/com/facebook/fbjni/fbjni-java-only/0.0.3/fbjni-java-only-0.0.3.pom
       - https://repo.maven.apache.org/maven2/com/facebook/fbjni/fbjni-java-only/0.0.3/fbjni-java-only-0.0.3.pom
       - https://www.jitpack.io/com/facebook/fbjni/fbjni-java-only/0.0.3/fbjni-java-only-0.0.3.pom
     Required by:
         project :app > com.facebook.react:react-native:0.64.3
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

由于这是昨天的工作,这个答案 https://stackoverflow.com/a/35433372/13368695 对我尝试使用代理没有意义,或者这是我的 ISP 阻止网站或互联网连接缓慢的问题。

编辑:我正在寻找一种方法来替换来自 JCenter、Bintray 和其他已经/即将变得不可用的包。

android/build.gradle:

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

buildscript {
    ext {
        buildToolsVersion = "29.0.3"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.1.0")

        classpath 'com.google.gms:google-services:4.3.10' //added for Firebase

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

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url(new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), "../android"))
        }
        maven {
            // Android JSC is installed from npm
            url(new File(["node", "--print", "require.resolve('jsc-android/package.json')"].execute(null, rootDir).text.trim(), "../dist"))
        }

        google() //for Firebase, Google's Maven repository
        mavenCentral()
        maven { url 'https://www.jitpack.io' }
    }
}

android/app/build.gradle:

dependencies {
    //adding Firebase BoM:
    implementation platform('com.google.firebase:firebase-bom:29.0.2')
    // Add the dependency for the Firebase SDK for Google Analytics
    // When using the BoM, don't specify versions in Firebase dependencies
    implementation 'com.google.firebase:firebase-analytics'
    // TODO Add the dependencies for any other desired Firebase integrations
    // https://firebase.google.com/docs/android/setup#available-libraries



    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules

    def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";
    def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";
    def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true";

    // If your app supports Android versions before Ice Cream Sandwich (API level 14)
    // All fresco packages should use the same version
    if (isGifEnabled || isWebpEnabled) {
        implementation 'com.facebook.fresco:fresco:2.0.0'
        implementation 'com.facebook.fresco:imagepipeline-okhttp3:2.0.0'
    }

    if (isGifEnabled) {
        // For animated gif support
        implementation 'com.facebook.fresco:animated-gif:2.0.0'
    }

    if (isWebpEnabled) {
        // For webp support
        implementation 'com.facebook.fresco:webpsupport:2.0.0'
        if (isWebpAnimatedEnabled) {
            // Animated webp support
            implementation 'com.facebook.fresco:animated-webp:2.0.0'
        }
    }
    
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
      exclude group:'com.facebook.fbjni'
    }
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }
    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    if (enableHermes) {
        debugImplementation files(new File(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute(null, rootDir).text.trim(), "../android/hermes-debug.aar"))
        releaseImplementation files(new File(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute(null, rootDir).text.trim(), "../android/hermes-release.aar"))
    } else {
        implementation jscFlavor
    }
}

【问题讨论】:

  • 可以添加android/build.gradle代码吗?
  • 完成了,我是从 android 和 android/app 文件夹中完成的。

标签: android react-native bintray jcenter


【解决方案1】:

这是 JCenter 的全球性中断。你可以在这里监控状态https://status.gradle.com 它取代了 bintray 状态页面,该页面现在似乎已经完全关闭并返回 502 错误。

更新时间 1 月 13 日 06:35 UTC

JCenter 现已重新上线,系统已全面运行。

【讨论】:

  • 既然这些依赖已经过时了,我该如何放弃使用 JCenter 和 bintray?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-07-14
  • 2018-09-05
  • 2022-01-07
  • 1970-01-01
  • 1970-01-01
  • 2019-02-26
  • 1970-01-01
相关资源
最近更新 更多