React-Native,Pdf 在 android 模拟器上显示,但在实际 android 设备上出现错误

React-Native, Pdf showing on android simulator but getting error on actual android device

我已经安装了 react-native-pdf 和 rn-fetch-blob 包来显示 pdf file.It 在模拟器上工作正常但由于某些原因我得到 "Error: open failed: ENOENT (No such file or directory)".

下面是我的代码:

import React, { Component } from 'react';
import {
  StyleSheet,
  Dimensions,
  View
} from 'react-native';

import Pdf from 'react-native-pdf';


// Screen that shows the contents of a PDF
export default class OpenPdf extends Component {

  static navigationOptions = {
    title: 'Product Variants'
  };

  render() {
    const source = require('../assets/Product_Variants_Electric_Connections.pdf');

    return (
        <View style={{width: '100%', height: '100%'}}>
          <Pdf style={styles.pdf}
          source={source}

          onLoadComplete={(numberOfPages, filePath) => {
              alert(`number of pages: ${numberOfPages}`);
          }}
          onPageChanged={(page, numberOfPages) => {
              alert(`current page: ${page}`);
          }}
          onError={(error) => {
              alert(`error`+error);
          }}
      />
      </View>
  );
  }
}

const styles = StyleSheet.create({
  container: {
      flex: 1,
      justifyContent: 'center',
      alignItems: 'center'
  },
  pdf: {
      flex: 1,
      width: Dimensions.get('window').width
  }
});

我已经浏览了很多链接,none 问题与我的相似。 请提出我遗漏的建议。

正如上面@Hardik Virani 在评论中所建议的那样,我已经删除了本地 url 并像下面那样做了:

render() {
    const source = {uri:'bundle-assets://Product_Variants_Electric_Connections.pdf', cache: true};

    return (
        <View style={{width: '100%', height: '100%'}}>
          <Pdf style={styles.pdf}
          source={source}

      />
      </View>
  );

记住 只需将您的实际 pdf 放在项目的 android/app/src/main/assets/pdf 文件夹中。