【问题标题】:problem to show epub in release build android在发布版本 android 中显示 epub 的问题
【发布时间】:2020-08-26 09:24:07
【问题描述】:

我尝试使用 epubjs-rn 包通过以下代码显示我的 epub,调试构建中的一切都正常,当我获得发布构建和测试时,epub 书不显示并修复加载开始显现, 我在 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,我通过RNBackgroundDownloader从我的服务器下载书并保存,然后将其解压缩到asset文件夹中以在本地阅读, 我的解压功能:

  _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-android epub


    【解决方案1】:

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

    AndroidManifest.xml

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

    more read

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-12
      • 2023-01-10
      • 2017-05-29
      相关资源
      最近更新 更多