简体   繁体   English

与从命令行运行Android Studio相比,Android Studio安装了不同版本的react-native应用程序

[英]Android Studio installs a different version of my react-native app compared to running it from command line

I recently jumped onto a project using react-native and am relatively new to it. 我最近跳入了使用react-native的项目,并且相对较新。 When I run the app on my phone through react-native run-android , it runs the version of the app that I want. 当我通过react-native run-android在手机上运行该应用程序时,它将运行我想要的应用程序版本。 However, when I open the app from the android folder in Android Studio and run it on my phone from there, it runs a different version of the app (different from running through react-native run-android ). 但是,当我从Android Studio中的android文件夹中打开该app并从那里在我的手机上运行该应用程序时,它会运行该应用程序的不同版本(不同于通过react-native run-android )。 I need to open the command line version in Android Studio so I can make a signed APK to upload to the play store. 我需要在Android Studio中打开命令行版本,以便可以将签名的APK上传到Play商店。

Any help as to why this is happening would be appreciated. 任何关于为什么会发生这种情况的帮助将不胜感激。 Thanks in advance. 提前致谢。

I found the problem. 我发现了问题。 For anyone who finds themselves in a similar situation: 对于发现自己处于类似情况的任何人:

Any changes to the react-native code will not apply to the android version until it is rebundled. 除非重新打包,否则对react-native代码的任何更改将不适用于android版本。 This is because when the app is run through react-native run-android it starts a bundling service automatically (same as running npm start ) so it automatically bundles the project. 这是因为当应用程序通过react-native run-android它会自动启动捆绑服务(与运行npm start相同),因此它会自动捆绑项目。 However, when running through android studio, it does not do this. 但是,当通过android studio运行时,它不会执行此操作。 Therefore, you must bundle it yourself before opening it in android studio. 因此,您必须先将其捆绑在一起,然后才能在android studio中打开它。 To do this, run the following command in the cmd in your project directory 为此,请在项目目录中的cmd中运行以下命令

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

After running this, you should be able to open the android folder in android studio and it will run the latest version of your app. 运行此程序后,您应该能够在android studio中打开android文件夹,它将运行您应用程序的最新版本。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM