react-native加载静态图片或html , 显示文件找不到

测试手机为android

`

//webview用的是react-native-webview


import React, { Component, } from 'react';
import { View, Text, Platform, Image, } from 'react-native'
import { WebView } from 'react-native-webview';
export default class Antv extends Component {
    constructor(props) {
    super(props);
    this.state = {
  
    }
}
render() {
return (
  <View style={{height: 300}}>
    <WebView
        ref={ref => (this.webViewRef = ref)}
        // onMessage={this.onMessage}
        originWhitelist={['*']}
        // allowFileAccess={true}
        // source={{uri:    'file:///android_asset/china_gdp.html'}}
        source={{uri: 'file:///android_asset/base/gdp.html'}}
        javaScriptEnabled={true}
        // decelerationRate='normal'
        scrollEnabled={true}
        // useWebKit={true}
        // mediaPlaybackRequiresUserAction={true}
        // mixedContentMode="compatibility"
        // allowingReadAccessToURL="*"
        // domStorageEnabled={true}
        // onLoadEnd={() => this.setState({ loading: false })}
    />
    <Image
        style={{width: 100, height: 100}}
        source={{uri: 'file:///android_asset/base/CustomerAnalysis.png'}}
    />
  </View>
)
}
}

`
android/app/src/main/assets
image

这样写完以后,运行,手机显示如下
image
webview显示没找到文件,Image也没有显示
这是哪里的问题呢?

阅读 2.8k
1 个回答

file 后面要接绝对路径,你代码中的地址是相对于项目根目录的path

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题