简体   繁体   中英

Is there a way to reduce the size of the application?

I am facing a problem with the size of the application after I converted it from WebView to PdfView
Regardless of the size of the files in assets
The size of the application after exporting in PdfView size is 23 MB
In WebView 8 MB

Is it because of these plugins you put in gradle?

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

PdfView

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();

    }

}

Is there a way to reduce the size of the application? knowing that the application without these codes in webview is 8 megabytes, and after converting webview to PDF-view it becomes 23 megabytes

If you generate your app as an .AAB file and upload to the playstore then it will create specific APKs for the device it is installing on, and they will be as small as possible.

If your app uses native files, there are specific files for each hardward architecture, if you use an APK it will have all the architecture files (all but one being unused) if you use an AAB then when the APK is generated it will only have the native file you need.

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

AAB is becoming the defactor standard instead of AAB.

If you want to calculate the APK size of an APK generated from an AAB you can use bundle tool: https://developer.android.com/studio/command-line/bundletool


Also the library you are using: https://github.com/barteksc/AndroidPdfViewer

Has a native library that is 16 meg

Why resulting apk is so big? Android PdfViewer depends on PdfiumAndroid, which is set of native libraries (almost 16 MB) for many architectures. Apk must contain all this libraries to run on every device available on market. Fortunately, Google Play allows us to upload multiple apks, eg one per every architecture. There is good article on automatically splitting your application into multiple apks, available here. Most important section is Improving multiple APKs creation and versionCode handling with APK Splits, but whole article is worth reading. You only need to do this in your application, no need for forking PdfiumAndroid or so.

So using this PdfViewer your app will be 16meg bigger than your WebView Option. :-)

The library has not had changes pushed to it in over 2 years. It may be that it isn't up to date with the way AAB's figure out their splits. Your best bet would be to fork the library and see if updating the AGP version etc gives you any better results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM