【问题标题】:React Native: Change the Entry file path index.android.js to specified custom file pathReact Native:将Entry文件路径index.android.js改为指定的自定义文件路径
【发布时间】:2017-01-10 13:05:16
【问题描述】:

我需要将 Entry 文件路径更改为 src/XXXApp.android.js 而不是指向默认的 index.android.js 文件。我想将 JS 文件保存在单独的 ./src 文件夹中。

所以我在 ./android/app/build.gradle 中进行了更改,例如

 project.ext.react = [
    bundleAssetName: "src/XXXApp.android.bundle",
    entryFile: file("../../src/XXXApp.android.js"),
    root: "../../../../",
    inputExcludes: ["android/**", "./**"]
 ]

并在 .\node_modules\react-native\react.gradle 文件中

def bundleAssetName = config.bundleAssetName ?:"src/XXXApp.android.bundle"
def entryFile = config.entryFile ?: "src/XXXApp.android.js"

但是开发包服务器总是指向 localhost:8081/index.android/bundle. 。我手动尝试了 URL:localhost:8081/src/XXXApp.android.bundle 并检索数据。 但是在设备调试 loadJs 总是尝试 localhost:8081/index.android/bundle.

请分享解决方案,更新android入口文件配置的正确位置。提前感谢您的宝贵解决方案。

【问题讨论】:

    标签: android reactjs react-native


    【解决方案1】:

    在您的 MainActivity 中,您可以覆盖 ReactActivity 的 getJSBundleFile() 方法。您可以在此处指定捆绑文件名和路径。代码推送使用相同的方法覆盖 reactjs 包路径。

    【讨论】:

    • 在 0.35 版本中,getJSBundleFile() 已从 ReactActivity 中删除。所以你需要在 ReactNativeHost() 的实现中实现 getJSBundleFile() 和/或 getBundleAssetName,通常在你的自定义应用程序中
    猜你喜欢
    • 1970-01-01
    • 2017-06-19
    • 2023-04-09
    • 1970-01-01
    • 2019-08-22
    • 2020-08-04
    • 1970-01-01
    • 2015-06-05
    • 1970-01-01
    相关资源
    最近更新 更多