尝试从Android设备(1+ 5吨)加载应用程序时遇到此问题
error: bundling failed: Invariant Violation: invalid asset resolution
at invariant (~/project/node_modules/metro/node_modules/fbjs/lib/invariant.js:40:15)
at ModuleResolver._getFileResolvedModule (~/project/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:175:9)
at ModuleResolver.resolveDependency (~/project/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:116:19)
at ResolutionRequest.resolveDependency (~/project/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:49:18)
at DependencyGraph.resolveDependency (~/project/node_modules/metro/src/node-haste/DependencyGraph.js:218:16)
at Object.resolve (~/project/node_modules/metro/src/lib/transformHelpers.js:141:30)
at dependencies.map.result (~/project/node_modules/metro/src/DeltaBundler/traverseDependencies.js:373:31)
at Array.map (<anonymous>)
at resolveDependencies (~/project/node_modules/metro/src/DeltaBundler/traverseDependencies.js:369:18)
at ~/project/node_modules/metro/src/DeltaBundler/traverseDependencies.js:188:33
BUNDLE [android, dev] ./index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.
尝试:
- react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
- react-native start --reset-cache
- rm -rf node_module & yarn install
任何帮助将不胜感激
答案 0 :(得分:0)
修复:删除“ .ios”。图片名称之外 由于我的应用程序当前只能在ios上运行,因此某些图像名称(例如“ welcome@2.ios.png”)中存在一些残差-因此在android上运行时,react native无法找到任何资源
答案 1 :(得分:0)
当您使用 React Native Platform Api (https://reactnative.dev/docs/platform) 时, 如果您的资产文件夹中有 2 个文件来显示不同的 UI,一个用于 Android,另一个用于 Ios,则在调用图像时,您必须删除文件名中的 Os 类型。
我的意思是,buttonIcon.android.png || buttonIcon.ios.png => buttonIcon.png
React Native Platform api 将进行切换。
例如:
var displayShareButton = () => { if(data != undefined && Platform.OS === "android") { 返回( <可触摸不透明度 style={styles.shareButton} onPress={() => shareSomething()} > <图片 style={styles.shareImage} source={require("../assets/buttonIcon.png")}/> ) } }
希望它能解决问题:)