【问题标题】:Error when trying to run my React Native app on Android尝试在 Android 上运行我的 React Native 应用程序时出错
【发布时间】:2021-10-20 09:55:09
【问题描述】:

我已经构建了我的 React Native 应用程序,并使用我的 iOS 设备进行了几个月的测试和故障排除。现在我正在尝试第一次在 Android 上构建和测试该应用程序。问题是,我在尝试运行我的应用程序的 Android 版本时不断出错。经过数小时的调试和故障排除后,我尝试创建一个新的 RN 项目,看看它是否可以在我的模拟器和设备上运行。我让那部分工作,然后我想将现有应用项目的文件复制/粘贴到新项目中。

我将现有资产、样式、源 JS 文件和 package.json 文件粘贴到新项目中,运行 npm install,然后我得到了与原始项目中完全相同的错误消息我运行react-native run-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

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugAssets'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find com.facebook.yoga:proguard-annotations:1.14.1.
     Searched in the following locations:
       - 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
       - file:/Users/MyUser/.m2/repository/com/facebook/yoga/proguard-annotations/1.14.1/proguard-annotations-1.14.1.pom
       - file:/Users/MyUser/MyAppFolder/MyApp/node_modules/react-native/android/com/facebook/yoga/proguard-annotations/1.14.1/proguard-annotations-1.14.1.pom
       - file:/Users/MyUser/MyAppFolder/MyApp/node_modules/jsc-android/dist/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.2
   > Could not find com.facebook.fbjni:fbjni-java-only:0.0.3.
     Searched in the following locations:
       - 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
       - file:/Users/MyUser/.m2/repository/com/facebook/fbjni/fbjni-java-only/0.0.3/fbjni-java-only-0.0.3.pom
       - file:/Users/MyUser/MyAppFolder/MyApp/node_modules/react-native/android/com/facebook/fbjni/fbjni-java-only/0.0.3/fbjni-java-only-0.0.3.pom
       - file:/Users/MyUser/MyAppFolder/MyApp/node_modules/jsc-android/dist/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.2
   > Could not find com.yqritc:android-scalablevideoview:1.0.4.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/yqritc/android-scalablevideoview/1.0.4/android-scalablevideoview-1.0.4.pom
       - https://repo.maven.apache.org/maven2/com/yqritc/android-scalablevideoview/1.0.4/android-scalablevideoview-1.0.4.pom
       - file:/Users/MyUser/.m2/repository/com/yqritc/android-scalablevideoview/1.0.4/android-scalablevideoview-1.0.4.pom
       - file:/Users/MyUser/MyAppFolder/MyApp/node_modules/react-native/android/com/yqritc/android-scalablevideoview/1.0.4/android-scalablevideoview-1.0.4.pom
       - file:/Users/MyUser/MyAppFolder/MyApp/node_modules/jsc-android/dist/com/yqritc/android-scalablevideoview/1.0.4/android-scalablevideoview-1.0.4.pom
       - https://www.jitpack.io/com/yqritc/android-scalablevideoview/1.0.4/android-scalablevideoview-1.0.4.pom
     Required by:
         project :app > project :react-native-video

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 10s

    at makeError (/Users/MyUser/MyAppFolder/MyApp/node_modules/execa/index.js:174:9)
    at /Users/MyUser/MyAppFolder/MyApp/node_modules/execa/index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (/Users/MyUser/MyAppFolder/MyApp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:5)
    at async Command.handleAction (/Users/MyUser/MyAppFolder/MyApp/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:186:9)

我尝试在 android 文件夹中运行 ./gradlew clean,但没有任何运气。我的 build.gradle 文件如下所示:

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

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        ndkVersion = "20.1.5948944"
        kotlinVersion = "1.3.72"
    }
    repositories {
        repositories {
            google()
            maven { url 'https://maven.google.com' }
            mavenLocal()
            mavenCentral()

           // jcenter()
            maven {
                // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
                url "$rootDir/../node_modules/react-native/android"
            }
        }
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.1")
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()

        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")
        }

        maven { url 'https://www.jitpack.io' }
    }
}

如果您知道该怎么做或遇到类似问题,请告诉我!

【问题讨论】:

    标签: android react-native android-studio gradle


    【解决方案1】:

    我遇到了同样的问题,并通过卸载 react-native-video (npm uninstall --save react-native-video) 暂时解决了这个问题。这不是一个很好的答案,因为我需要那个组件,但我还没有完整的解决方案。我想不知何故 com.yqritc:android-scalablevideoview:1.0.4。 react-native-video 需要,但已丢失或删除。欢迎提出其他想法。

    更新:已解决!在您的 Android 文件夹中的 build.gradle 中,您需要像这样在所有项目(而不是构建依赖项)中添加存储库“jcenter()”...

    allprojects {
        repositories {
            mavenCentral()
            mavenLocal()
            jcenter()
    }
    

    【讨论】:

    • 已解决!上面也进行了编辑。在 Android 文件夹中的 build.gradle 中,您需要像这样在所有项目(而不是构建依赖项)中添加存储库“jcenter()”... allprojects { repositories { mavenCentral() mavenLocal() jcenter() }
    • react-native init 首次运行时呈现出多么可笑的现状!现在,我每次构建时都会在我的 gradle 文件和终端日志中看到警告,因为 jcenter 在 ages 之前已被弃用,并且很快就会被完全删除!无论如何,感谢您对这个奇怪而令人沮丧的问题的回答。 +1
    • @Kenny83 我完全同意。使用 React Native 是一种糟糕的体验。这是许多无法“开箱即用”或具有与现实世界相匹配的文档的事情之一。一切似乎都已经过时了,似乎没有人关心他们是否发布了有效的东西。
    • @SpliFF 是的,你一针见血!特别是你所说的包开发人员不关心他们的包是否真的有效。是不是很气人?!
    • jcenter() 不再有效
    【解决方案2】:

    最好只从 android/build.gradle 中的 jcenter() 拉取特定的包:

    allprojects {
        repositories {
            .... # Keep the rest
            jcenter() {
                content {
                    includeModule("com.yqritc", "android-scalablevideoview")
                }
            }
        }
    }
    

    【讨论】:

      【解决方案3】:

      因为 jCenter 已从最新的 react native 中删除,并且 com.yqritc:android-scalablevideoview 仅在此处发布,所以您需要再次将 jCenter 添加为存储库,但我建议您定义包,以便不会从 jCenter 获取/获取其他依赖项了。因为 jCenter 不再允许对任何包进行任何更新,所以所有其他包都应该从 mavenCentral 获取。

      您可以像这样将 jcenter 添加到 android/build.gradle:

      allprojects {
          repositories {
              .... # Keep the rest
              jcenter() {
                  content {
                      includeModule("com.yqritc", "android-scalablevideoview")
                  }
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-04
        • 1970-01-01
        • 2020-01-23
        • 2021-11-11
        • 1970-01-01
        • 2017-05-21
        相关资源
        最近更新 更多