有没有办法减小应用程序的大小?

问题描述

将应用程序从 WebView 转换为 PdfView 后,我遇到了应用程序大小问题
无论资产中的文件有多大
以PdfView大小导出后的应用程序大小为23 MB
在 WebView 中 8 MB

是不是因为你在gradle里放了这些插件?

ndkVersion "22.1.7171670"
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'

PDF 视图

import android.content.Intent;
import android.os.Bundle;
import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnRenderListener;    
import androidx.appcompat.app.AppCompatActivity;

public class Web_Activity extends AppCompatActivity {
    private AdView mAdView;

    int pageNum;
    PDFView pdfView;
    String Title;


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);


        pdfView=(PDFView)findViewById(R.id.pdfView1);

        final Intent intent = getIntent();
        final String link = intent.getStringExtra("link");

        pdfView.fromAsset(""+link)
                .onRender(new OnRenderListener()
                {
                    @Override
                    public void onInitiallyRendered
                            (int nbPages,float pageWidth,float pageHeight)
                    {
                        pdfView.fitToWidth();
                    }
                }).load();

    }

}

有没有办法减小应用程序的大小?知道 webview中没有这些代码的应用程序是8兆字节,之后 将 webview 转换为 PDF-view 变成 23 兆字节

解决方法

如果您将应用生成为 .AAB 文件并上传到 Playstore,那么它会为其安装的设备创建特定的 APK,并且它们将尽可能小。

如果您的应用程序使用本机文件,则每个硬件架构都有特定的文件,如果您使用 APK,它将拥有所有架构文件(只有一个未使用),如果您使用 AAB,那么当 APK 生成时将只有您需要的本机文件。

https://developer.android.com/guide/app-bundle

AAB 正在成为 defactor 标准,而不是 AAB。

如果您想计算从 AAB 生成的 APK 的 APK 大小,您可以使用捆绑工具:https://developer.android.com/studio/command-line/bundletool


还有您正在使用的库:https://github.com/barteksc/AndroidPdfViewer

有一个 16 兆的本地库

为什么生成的 apk 这么大? Android PdfViewer 依赖于 PdfiumAndroid,PdfiumAndroid 是一组用于许多架构的本机库(近 16 MB)。 Apk 必须包含所有这些库才能在市场上可用的每个设备上运行。幸运的是,Google Play 允许我们上传多个 apk,例如每个架构一个。有一篇关于自动将您的应用程序拆分为多个 apk 的好文章,可在此处获得。最重要的部分是使用 APK Splits 改进多个 APK 创建和 versionCode 处理,但整篇文章值得一读。您只需要在您的应用程序中执行此操作,无需分叉 PdfiumAndroid 左右。

因此,使用此 PdfViewer,您的应用将比您的 WebView Option 大 16meg。 :-)

该库已超过 2 年没有更改过。可能是因为 AAB 弄清楚他们的分裂的方式不是最新的。最好的办法是 fork 库,看看更新 AGP 版本等是否会给你带来更好的结果。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...