首页 > 解决方案 > 在发布版本 android 中显示 epub 的问题

问题描述

我尝试使用epubjs-rn包通过下面的代码显示我的 epub,在调试版本中一切正常,当我获得发布版本和测试时,epub book 不显示并在开始显示时修复加载,我在 android studio 控制台中调试并发现同样的错误:

I/ReactNativeJS: readBookEpub   id: 4868
I/ReactNativeJS: source: http://localhost:8899/4868/
E/ReactNativeJS: Empty Response

我的代码:

_showEpub(bookName) {
        console.log("_showEpub");


        
        const targetPath = 'http://127.0.0.1:8899/' + bookName + '.epub';




        //------------------------------------------------------show Epub 
        try {
            this.streamer.start()
                .then((origin) => {
                    console.log("Served from:", origin);
                    // this.streamer.check('http://127.0.0.1:8899/moby-dick.epub').then((t) => console.log("hiii"+t));
                    return this.streamer.get(targetPath);
                })
                .then((src) => {
                    console.log("Loading from:", src);
                    return this.setState({ urlBook: src });
                });
        }
        catch (err) {
            console.log("Error: " + err);
        }
        //---------------------------------------------------


    }

对于 show book ,我从我的服务器下载 bookRNBackgroundDownloader并保存,然后将其解压缩到资产文件夹以在本地阅读,我的解压缩功能:

  _unZipBook(bookName) {
        console.log("_unZipBook")

        const sourcePath = Dirs.DocumentDir + '/FaraSource/e/' + bookName + '.zip';

        const targetPath = `${Dirs.DocumentDir}/assets/${bookName}`;

        unzip(sourcePath, targetPath)
            .then((path) => {

                console.log("unZip " + bookName + "in" + targetPath);
                this._showEpub(bookName);
                // return url;
            })
    }

任何人都可以帮助我解决这个问题吗?

标签: react-native-androidepub

解决方案


我解决了这个问题,必须在 AndroidManifest 中添加一行

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>

更多阅读


推荐阅读