首页 > 解决方案 > 无法从 Visual Studio Code 运行新创建的 React Native 项目

问题描述

我是本机反应的新手,我总是使用 Visual Studio 2019。在那里我使用 Xamarin。如您所知,当您下载 Visual Studio 并使用 xamarin 时,Android SDK 安装在

C:\Program Files (x86)\Android\android-sdk\platform-tools

adb 所在的位置C:\Program Files (x86)\Android\android-sdk\platform-tools

所以我创建了一个local.properties并添加了sdk.dir=C:\Program Files (x86)\Android\android-sdk\platform-tools

然后我在 android 上运行我的 react native 项目。

此外,除了下面我得到的错误之外,java.io.IOException: The filename, directory name, or volume label syntax is incorrect 我还没有找到任何模拟器,这很奇怪,因为我在上面的路径中安装了所有模拟器。所以我插入了我的安卓设备。

如果这与 Visual Studio 2019 安装的 android SDK 有关,请指导我

调试输出

[Warning] Target simulator is not supported for Android platform. 
 If you want to use particular device or simulator for launching Android app,
 please specify device id (as in 'adb devices' output) instead.

[Info] Using Android SDK location defined in android/local.properties file: C:\Program Files (x86)\Android\android-sdk\platform-tools.

[Info] Starting React Native Packager.

[Info] Attaching to running React Native packager

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1296 file(s) to forward-jetify. Using 8 workers...
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
info Installing the app...
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.

> Configure project :app

�[33mInstalling unimodules:�[0m
 �[32munimodules-core�[33m@�[31m6.0.0�[0m from �[35mD:\Projects\NovelLator\node_modules\@unimodules\core�[0m
 �[32munimodules-react-native-adapter�[33m@�[31m5.7.0�[0m from �[35mD:\Projects\NovelLator\node_modules\@unimodules\react-native-adapter�[0m
 �[32mexpo-application�[33m@�[31m2.4.1�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-application�[0m
 �[32mexpo-constants�[33m@�[31m9.3.5�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-constants�[0m
 �[32mexpo-error-recovery�[33m@�[31m1.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-error-recovery�[0m
 �[32mexpo-file-system�[33m@�[31m9.3.0�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-file-system�[0m
 �[32mexpo-font�[33m@�[31m8.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-font�[0m
 �[32mexpo-image-loader�[33m@�[31m1.3.0�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-image-loader�[0m
 �[32mexpo-keep-awake�[33m@�[31m8.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-keep-awake�[0m
 �[32mexpo-linear-gradient�[33m@�[31m8.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-linear-gradient�[0m
 �[32mexpo-location�[33m@�[31m10.0.0�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-location�[0m
 �[32mexpo-permissions�[33m@�[31m10.0.0�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-permissions�[0m
 �[32mexpo-secure-store�[33m@�[31m9.3.0�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-secure-store�[0m
 �[32mexpo-splash-screen�[33m@�[31m0.8.1�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-splash-screen�[0m
 �[32mexpo-sqlite�[33m@�[31m8.5.0�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-sqlite�[0m
 �[32mexpo-updates�[33m@�[31m0.4.1�[0m from �[35mD:\Projects\NovelLator\node_modules\expo-updates�[0m
 �[32munimodules-app-loader�[33m@�[31m1.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\unimodules-app-loader�[0m
 �[32munimodules-barcode-scanner-interface�[33m@�[31m5.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\unimodules-barcode-scanner-interface�[0m
 �[32munimodules-camera-interface�[33m@�[31m5.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\unimodules-camera-interface�[0m
 �[32munimodules-constants-interface�[33m@�[31m5.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\unimodules-constants-interface�[0m
 �[32munimodules-face-detector-interface�[33m@�[31m5.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\unimodules-face-detector-interface�[0m
 �[32munimodules-file-system-interface�[33m@�[31m5.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\unimodules-file-system-interface�[0m
 �[32munimodules-font-interface�[33m@�[31m5.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\unimodules-font-interface�[0m
 �[32munimodules-image-loader-interface�[33m@�[31m5.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\unimodules-image-loader-interface�[0m
 �[32munimodules-permissions-interface�[33m@�[31m5.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\unimodules-permissions-interface�[0m
 �[32munimodules-sensors-interface�[33m@�[31m5.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\unimodules-sensors-interface�[0m
 �[32munimodules-task-manager-interface�[33m@�[31m5.4.0�[0m from �[35mD:\Projects\NovelLator\node_modules\unimodules-task-manager-interface�[0m

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\Projects\NovelLator\node_modules\react-native-reanimated\android\build.gradle' line: 89

* What went wrong:
A problem occurred configuring project ':react-native-reanimated'.
> java.io.IOException: The filename, directory name, or volume label syntax is incorrect

* 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 18s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

这是我的 build.grade。

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

buildscript {
    ext {
        buildToolsVersion = "29.0.2"
        minSdkVersion = 21
        compileSdkVersion = 29
        targetSdkVersion = 29
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.3")

        // 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("$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' }
    }
}

C:\Program Files (x86)\Android\android-sdk\build-tools我有 29.0.2 地图版本。

标签: androidreact-nativevisual-studio-codesdk

解决方案


如果你是 Windows 用户,

您已经手动使用 android studio 或 CMD 打开了模拟器。

这是为什么?

react-native run-android 命令不会在 Windows 中自动启动模拟器。


推荐阅读