React Native:Android Studio 在构建时不会自动打包 [英] React Native: Android Studio doesn't automatically bundle when building
问题描述
我正在构建一个 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 在构建时不会自动打包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!