简体   繁体   English

如何使用 npx 创建新的 React Native App?

[英]How can i create new react native App using npx?

I didn't use react-native for a few months.我有几个月没有使用 react-native 了。 It looks like some things have changed meanwhile.看起来有些事情同时发生了变化。 In the official documentation they recommend to uninstall react-native-cli and to use npx react-native init instead.在官方文档中,他们建议卸载react-native-cli并改用npx react-native init I did this but ended up with an error because I didn't install that package globally.我这样做但最终出现错误,因为我没有在全球范围内安装 package。 However, if I install react-native globally, it results in an error when I run the project, saying that I should remove the global package.但是,如果我全局安装react-native ,运行项目时会报错,提示我应该去掉全局的package。

What is the proper way to create a react app nowadays?现在创建 React 应用程序的正确方法是什么?

  1. npm uninstall --global react-native-cli npm uninstall --global react-native-cli
  2. Install node js ( i use node js version 12.10.0 here ), i dont use the latest one because there is a bug i cant run my react native app安装 node js(在这里使用 node js 版本 12.10.0 ),我不使用最新的,因为有一个错误,我无法运行我的React Native 应用程序
  3. install python2 jdk8 and yarn安装python2 jdk8yarn
  4. install android studio and sdk and add ANDROID_HOME to environment variable安装 android studio 和 sdk 并将 ANDROID_HOME 添加到环境变量
  5. use npx react-native init ProjectName to create new project使用npx react-native init ProjectName创建新项目
  6. use yarn react-native run-android or yarn react-native run-ios to run the project使用yarn react-native run-androidyarn react-native run-ios来运行项目

@Raeygzz if you want to use react-native related command add yarn/npx in the beginning of the command @Raeygzz 如果你想使用 react-native 相关命令在命令的开头添加 yarn/npx

yarn react-native run-android
yarn react-native run-ios

or或者

npx react-native run-android
npx react-native run-ios
  1. if you want to create apk debug use in your root project如果你想在你的根项目中创建 apk 调试使用

    cd android && gradlew assembleDebug cd android && gradlew assembleDebug

  2. apk release in your root project在您的根项目中发布 apk

    cd android && gradlew assembleRelease cd android && gradlew assembleRelease

  3. Debug with bundle in your root project在根项目中使用 bundle 进行调试

    yarn react native run-android纱线反应本机运行Android

and get the apk file in并获取apk文件

android\app\build\outputs\apk\debug

i usually do this if the device i working on doesn't have an usb cable, so i copy the file there, and sent it to the cloud, download it to device and install it, after that i just shake the phone and go to settings and setup debug server ex: 10.xxx.xxx:8081 then run yarn start in cmd shake the device and choose refresh如果我使用的设备没有 USB 电缆,我通常会这样做,所以我将文件复制到那里,然后将其发送到云端,将其下载到设备并安装它,然后我只需摇晃手机并转到设置和设置调试服务器例如:10.xxx.xxx:8081 然后在 cmd 中运行 yarn start 摇动设备并选择刷新

the difference is here between react-native run-android and gradlew assembleDebug react-native run-android Vs ./gradlew assembleDebug不同之处在于 react-native run-android 和 gradlew assembleDebug react-native run-android Vs ./gradlew assembleDebug

查看他们的官方文档npx

Thanks @Gus Nando for the detail... and if i want to make a debug build for android using npx then what should i follow.感谢@Gus Nando 提供的详细信息……如果我想使用 npx 为 android 进行调试构建,那么我应该遵循什么。 And also if there is any changes or change in set of way to create debug as well as production build for both android and ios platform.此外,如果为 android 和 ios 平台创建调试和生产构建的方式有任何更改或更改。

Any kind of info related to npx will be of much help.任何与 npx 相关的信息都会有很大帮助。 Thanks in advance提前致谢

The first thing you need to do is delete react-native-cli:您需要做的第一件事是删除react-native-cli:

npm uninstall react-native-cli or npm uninstall --global react-native-cli npm uninstall react-native-clinpm uninstall --global react-native-cli

Then, install Expo CLI if you have NodeJS 10 LTS or greater installed: npm install -g expo-cli然后,如果您安装了 NodeJS 10 LTS 或更高版本,请安装 Expo CLI: npm install -g expo-cli

You should be able to make new react native app now with expo-cli like that : expo init ProjectName您现在应该能够使用 expo-cli 制作新的 React Native 应用程序,如下所示: expo init ProjectName

Expo is a tool that allows you to set up a development environment on your phone. Expo 是一种工具,可让您在手机上设置开发环境。 For more information, see the documentation here: https://expo.io/有关更多信息,请参阅此处的文档: https : //expo.io/

It is the most efficient and fastest way to develop, test and deploy an application它是开发、测试和部署应用程序的最有效、最快捷的方式

尝试使用npx react-native init projectName然后使用cd projectName将目录更改为项目并使用react-native run-android运行项目

it's easy: in case of developing in windows just do the following command in your prefered terminal with administrative access: npx react-native init YourPrjName这很简单:如果在 windows 中进行开发,只需在具有管理权限的首选终端中执行以下命令:npx react-native init YourPrjName

for details take a look at this brief video https://youtu.be/A5pXsiBVKTY有关详细信息,请观看此简短视频https://youtu.be/A5pXsiBVKTY

and don't forget to use lower case except for project name并且不要忘记使用小写字母,除了项目名称

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我使用命令“npx react-native init Sarfaraz”在我们的文件夹中安装本机应用程序时 - When I install react native app in our folder by using comand "npx react-native init Sarfaraz" 如何修复“npx react-native run-android”错误? - How can i fix 'npx react-native run-android' error? 如何为create-react-native-app生成apk文件(使用EXPO.IO组件) - How can I generate apk file for create-react-native-app (using EXPO.IO component) 我无法执行 npx react-native run-android,Java 错误; 无法确定任务“:app:compileDebugJavaWithJavac”的依赖关系。 LINUX - I can't do npx react-native run-android, Java error; Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'. LINUX 当我尝试运行 npx react-native run-android 时,任务:应用程序:mergeDebugAssets 失败 - Task :app:mergeDebugAssets FAILED when I try to run npx react-native run-android 当我运行“npx react-native run-ad”时,Fresh React Native App 不会安装在模拟器上 - Fresh React Native App won't install on emulator when I run "npx react-native run-ad" 如何使用按钮 onpress 创建新的反应原生标签 - How to create new react native Tag using button onpress 如何在我的新应用中使用Android原生图标? - How can I use Android native icons in my new app? 如果我使用ReactJS创建一个Web应用程序,我可以重用代码来构建一个使用React Native的移动应用程序吗? - If I create a web app with ReactJS, can I reuse the code to build a mobile app with React Native? 无法使用“npx react-native init SampleApp”创建反应原生项目 - Not able to create react native project with “npx react-native init SampleApp”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM