在react-native项目中更改android和ios的条目文件路径 [英] Change entry file path of android and ios in react-native project
问题描述
在使用 react-native init awesomeProject 启动新项目后,我尝试重构我的项目,将 index.ios.js 和 index.android。 ios 在名为 src 的公共文件夹中。
After starting a new project with react-native init awesomeProject, i try to restructure my project, putting index.ios.js and index.android.ios inside a common folder named src.
当我执行 react-native run-android 时,我收到以下错误:
When i execute react-native run-android, i get the following error:
我必须在正确的路径中更改为react-native搜索条目文件?
Where i have to change to react-native search for entry files in the right path?
推荐答案
我在react-native 0.35上使用了以下步骤
I've used the following steps on react-native 0.35
对于开发,你需要打开一个文件
For development you need to open a file
MyProject / android / app / src / main / java / com / MyProject / MainApplication.java
并覆盖 ReactNativeHost
的方法,名为 getJSMainModuleName
:
package com.MyProject;
// ...
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
// ...
// ADD THE LINES BELOW
@Override
protected String getJSMainModuleName() {
return "src/index.android";
}
// ADD THE LINES ABOVE
};
// ...
}
这样应用程序将知道从打包服务器获取模块的位置。
This way the app will know where to fetch the module from a packager server.
对于生产,当您使用 cd android&& ./gradlew assembleRelease
你必须修改一个文件
For production, when you build your APK using cd android && ./gradlew assembleRelease
you'll have to modify a file
MyProject / android / app / build.gradle
并添加自定义构建选项,确保在申请之前放置它们:../../node_modules /react-native/react.gradle
line:
and add custom build options, make sure to place them before apply from: "../../node_modules/react-native/react.gradle"
line:
apply plugin: "com.android.application"
import com.android.build.OutputFile
// ...
// ADD THE LINES BELOW
project.ext.react = [
// the entry file for bundle generation
entryFile: "src/index.android.js",
]
// ADD THE LINES ABOVE
// ...
apply from: "../../node_modules/react-native/react.gradle"
不幸的是我现在没有iOS设置,但我还是帮不上你。
Unfortunately I don't have iOS setup right now, I can't help you with that yet.
这篇关于在react-native项目中更改android和ios的条目文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!