我正在尝试在React Native应用的Gradle构建过程中生成源映射,并在应用程序中读取源映射文件。
我使用了这个项目作为起点:https://github.com/philipshurpik/react-native-source-maps。
我没有成功地将其包含进来,所以我尝试了一些修改。
在
应用程序代码使用https://github.com/itinance/react-native-fs 来读取文件。这是我首先检查文件是否存在的方法:
我错过了什么?如何将源映射文件放在应用程序可以读取的位置?
我使用了这个项目作为起点:https://github.com/philipshurpik/react-native-source-maps。
我没有成功地将其包含进来,所以我尝试了一些修改。
在
app/gradle.build
中我添加了以下内容:
project.ext.react = [
extraPackagerArgs: ["--sourcemap-output", "$buildDir/intermediates/assets/release/index.map"]
]
确实,在运行发布版本时,我可以看到index.map
文件位于android/app/build/intermediates/assets/release
下,但是当我将 APK 部署到设备或模拟器时,在 Android 的文件系统中无法找到此文件。而且,在构建后,我也无法在android/app/src/main/assets
中看到包文件或任何文件,但在android/app/build/intermediates/assets/release
下却能看到。应用程序代码使用https://github.com/itinance/react-native-fs 来读取文件。这是我首先检查文件是否存在的方法:
const fileExists = await RNFS.existsAssets(`$ {RNFS.DocumentDirectoryPath} / index.map`)
但这个文件在那里不存在。 RNFS.DocumentDirectoryPath
返回/data/user/0/mypackagename/files
,当我检查时(使用具有root访问权限的adb shell),它是空的。我错过了什么?如何将源映射文件放在应用程序可以读取的位置?