React Native:Android Studio 在构建时不会自动打包

编程入门 行业动态 更新时间:2024-10-13 00:36:31
本文介绍了React Native:Android Studio 在构建时不会自动打包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在构建一个 React Native 应用程序,我们正在发布生产版本.我注意到在我的 iOS 应用程序中一切正常(有一个生成阶段会生成离线包)但是当我在 Android Studio 中运行发布版本时,我的应用程序构建但它崩溃了,因为它找不到包.

解决方案

我能够解决我自己的问题:

我们更改了构建类型/风格以匹配所需的配置.

React Native 自带的 react.gradle 文件有 Debug 和 Release 的配置,这些是一个常见的构建任务本机应用程序.但是一旦你改变了,你需要告诉 android 中的 react 库你是否希望它为你打包.

您可以在应用的 build.gradle 中找到它(在./android/app/build.gradle).一整块指南都被注释掉了,解释了你该怎么做.

就我而言,我必须在之前 申请自:../../node_modules/react-native/react.gradle">

ext.react = [bundleInNameDebug: 假,bundleInNameBeta: 真,bundleInNameRelease: 真]

NameDebug、NameBeta、NameRelease 都是我配置的自定义 BuildTypes/BuildFlavors.

I am building a react native application and we're doing the production release. I noticed that everything works in my iOS app (there's a build phase that generates the offline bundle) but when I run the release build in Android Studio, my app builds but it crashes because it can't find the bundle.

解决方案

I was able to resolve my own question:

We changed our build types/flavors to match our desired configuration.

The react.gradle file that comes with React Native has a configuration for Debug and Release, these are the common build tasks in a native application. BUT once you change things up you need to tell the react library in android whether or not you want it to bundle for you.

You can find this in your app's build.gradle (under ./android/app/build.gradle). There's an entire block of guidelines commented out that explain you what to do.

In my case I had to add the following code before apply from: "../../node_modules/react-native/react.gradle"

ext.react = [ bundleInNameDebug: false, bundleInNameBeta: true, bundleInNameRelease: true ]

NameDebug, NameBeta, NameRelease are all custom BuildTypes/BuildFlavors I have configured.

更多推荐

React Native:Android Studio 在构建时不会自动打包

本文发布于:2023-10-11 14:26:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1481965.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Native   React   Studio   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!