尝试在 Android 上运行我的 React Native 应用程序时出错

Sim*_*egn 1 android gradle android-studio react-native

我已经构建了我的 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)
Run Code Online (Sandbox Code Playgroud)

我试图./gradlew clean在没有任何运气的情况下在 android-folder 中运行。我的 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' }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

Har*_*ogi 17

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

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


tre*_*man 10

我遇到了同样的问题,并通过卸载 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()
}
Run Code Online (Sandbox Code Playgroud)

  • jcenter() 不再起作用 (7认同)
  • 第一次运行“react-native init”时会出现多么可笑的现状!现在,每次构建时,我的 gradle 文件和终端日志中都会出现警告,因为 jcenter 已在**多年前被弃用,并将很快被完全删除!无论如何,感谢您对这个奇怪且令人沮丧的问题的回答。+1 (6认同)
  • @Kenny83 我完全同意。React Native 的使用体验非常糟糕。这是许多无法“开箱即用”或没有与现实世界相匹配的文档的事情之一。一切似乎都已经过时了,似乎没有人关心他们是否发布了有用的东西。 (6认同)
  • @SpliFF 是的,你击中了要害!特别是你所说的软件包开发人员不关心他们的软件包是否实际工作。真让人气愤不是吗?! (2认同)