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

我粘贴了我现有的资源、样式、源JS文件和包.将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)

我try 在android文件夹中运行./gradlew clean次,但没有任何运气.我的身材.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' }
    }
}

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

推荐答案

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

更新:已解决!在你的身材里.gradle在您的Android文件夹中,您需要在所有项目(而不是构建依赖项)中添加存储库"jcenter()",如下所示...

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

React-native相关问答推荐

Appcenter构建失败错误号::EEXIST -文件存在于syserr_fail2_in

react 本机 TextInput 将其他元素移出屏幕

React Native:如何以编程方式对图像进行黑白过滤?

'未能找到 React 根视图的片段' React Native Android RNScreens

如何在 React Navigation 5 中将父函数传递给子屏幕?

在向后滑动时执行操作(react-navigation )

React Native 上传到 S3 存储空间

library not found for -lRCTGeolocation

为什么 Android Studio 强制使用 Android 支持库中的 Androidx?

由于端口 8081 sunproxyadmin,无法打包 react native

ScrollView visible Scroll Bar

React Native 元素搜索栏边界线未清除

带有 xcode 模拟器的 react-native 有非常慢的alert

未计算文件的 React-Native Bundle Error 错误 SHA-1

如何将本地文本文件加载到 React Native Project 中的字符串变量中?

[React-Native][Jest]SyntaxError: Unexpected token import

Unexpected token on "export default const"

Node.js 在 React-Native 中的作用是什么?

React本机IOS,当TextInput获得焦点时,按钮按下不注册

如何在 React Native 中强制禁用 iOS 暗模式