Android apk file too big when using FFMPeg encoder library - android

I'm developing an app which creates x264 videos with the following library:
com.arthenica:mobile-ffmpeg-full:4.2.2.LTS
but the result apk file is too big (~71mb), so I tried:
com.arthenica:mobile-ffmpeg-min-gpl:4.2.2.LTS
and this way, as the library downloads only a few codecs -included the ones I need- apk size was reduced to ~49mb, what is much better, but still looks too big to me, so I'd need to know if any of you know a better way to reduce apk size, because people generally refuse to download such big apps
Regarding the rest of the app (drawables, resources and so) they're well optimized, because if I remove this library and rebuild, the size of the app drops to 10mb
I was reading this question:
FFMPEG Android Library Increase Size
and user S.R suggests to compress all cpu architecture models in one archive file and extract target cpu lib based on cpu model on app's directory and load ffmpeg from there, but I really don't know how to do that.
I'm checking my app's folder structure and noticed there are this next folders regarding ffmpeg lib:
arm64-v8a => ~16mb
armeabi-v7a => ~29mb
x86 => ~17mb
x86_64 => ~21mb
But not sure if I could remove any of them, and as you can see armeabi-v7a is the largest.

As per your requirement, FFmpeg is the best option to so much of video processing task but the problem with FFmpeg is it will increase the size of the app. So I will suggest you to compile this FFMPEG library in your project, it also has many inbuilt functions like add music, add image on Video etc. It will definitely help you with your work as well as size is also very small ~11mb.
You can use Android App Bundle (aab) to reduce app size
further.

use
implementation "com.arthenica:mobile-ffmpeg-min:4.4.LTS"
according to documentation

Related

Qt Android: Put videos inside app directory files

I have around 10 video files in the sizes of 10 MB each. I want to have them inside the /data/user/0/org.my.app/files. Somehow they need to be included in the .apk and installed here.
Right now they are living in this structure in Qt project:
DISTFILES += \
assets/video/video1.mp4
The goal is to be able to play the videos using
Video {
source: appPath + "/assets/video/video1.mp4"
}
The ideal way is just using .qrc but it has been problems before when putting videos there.
With video, it's usually impractical to try to make it a resource since the size of the QRC will explode and result in long compile times and a large executable.
I've had luck delivering videos with a Qt Android app by using the native Java AssetManager: https://developer.android.com/reference/android/content/res/AssetManager
You'll need to use a CustomActivity in Java-land and integrate with it using JNI as demonstrated here: https://doc.qt.io/qt-5/qtandroidextras-customactivity-example.html
Or as #splaytreez points out you can use Qt's builtin support for Android Assets as documented here: https://doc.qt.io/qt-5/porting-to-android.html
Also, depending on the size of your video and what it does to your APK size, you may want to use the AAB bundle as discussed here: https://developer.android.com/guide/app-bundle/

JavaCv and FFMpeg

I was given a task to merge an Image and Audio to make a video file out of them in android. I successfully finished the task by using javacv ffmpeg but after so much of compression my app size is still around 15mb. After analysing the apk, I've found that libavcodec.so is occupying 64% of the size. Since my app relies on that, I can't exclude the file.
So my question is "Is it feasible to complete this task with very less apk size? Like around < 5Mb?"
Yes you can. If you really want to use javacv than you can remove unnecessary parts from the sources and recompile them. More info in JavaCPP repo
As the easiest solluton of this problem you can just remove some unused .so files.
Finally, ffmpeg is not necessary here and you can find another solution. For example you can use an online service (I've found transloadit and it is free for small apps) or write your own native or java code. It is not easy but possible

How to load an online android module at run-time?

Is it possible to split my Android apk of 512MB into different parts or modules.
Compile small part of it into a release Apk (small Apk size) for Play Store.
Then fetch the remaining parts or modules from online or your own server during first time install on a device.
Thats:
Small Apk to Google Play Store
Fetch remaining big files after first install.
I am using Android Studio.
Of course you can, that can be easily achieved if you got to split heavy resources(like images, videos, databases). Here you must write some logic which will download that resources and will work with them after a successful download.
I cant imagine a situation when you must to split a code in a separate module, compiled code is light and dont increase apk size so much as another resources. Code can become heavy when there is a lot of code from libraries, in that case I suggest you to learn about Proguard Shrink.
Also you can learn why in android is not possible to load java modules in runtime. On of the reasons is performance given by JIT
Here a is workaround with ndk How do I import shared object libraries at runtime in Android?

Mupdf compile with only pdf support

I was working on a lightweight pdf viewer, and I wanted the size to be of the range of 5 MBs,
I am using mupdf , but the compiled .so file itself is around 16.6 MBs,
Is there a way to compile mupdf with only pdf support and not the others like xps, images, etc.
Like this app on google play, the file of .so file is just 3 MBs
https://play.google.com/store/apps/details?id=de.geraldthaler.octopuspdf,
Any help will be greatly appreciated.
I figured, It was because of the font packs,
compiling without extra font packs generates very small .so's
If this is still relevant:
There is a configuration file In MuPDF source that lets you throw out features before you generate the library, called config.h located in directory mupdf/include/fitz.
By setting the appropriate #define statements, XPS, EPUB, etc. can be opted out. The biggest space saver is however opting out certain fonts. In essence you can restrict your library to PDF's Base-14 (Helvetica, Times-Roman, Courier, Symbol and ZapfDingbats) fonts. You also can opt out support for various image format support.
Taking all that together should bring you down well below 5 MB.

how to reduce android app size?

First of all , I am using android studio for development of android app. I have build an android app for OCR using tesseract library. The app is currently working great and giving desire output but my problem is with its size. The size of the build app is 30 MB which is high compared to other OCR app available. I have tried "minifyenabled = true" but it reduce just 300 kb of size. So my question is how to reduce size of my app?
You can use APK splits to build smaller versions of your app that target individual device architectures. For an example of this, see the San Angeles demo project.
You can get a further reduction by removing the libpngt.so/libjpgt.so files if your app doesn't need them.
Using ProGuard may help too.
Regarding tesseract lib size have a look at options provided by tesseract itself. Description is in article less is better. Be aware some of options are experimental, so check your OCR quality.
Use the 3.01 version of Tesseract .trainddata files.
How to reduce size of tessdata used for TessBaseAPI in android?
Read the answer in http://stackoverflow.com/questions/25101534/reducing-android-app-apk-size you will get the solution. And for the record always try to reduce duplicating codes
App sizes largely increases due to 3rd party libraries and images. Please have a look at what all images you have used and try reducing their sizes where all possible.
One more thing you can do is use Lint to check for unused resources and remove them if any.
Just right click on app directory -> Analyze -> Run Inspection By name
and then type in Unused resources.
Size of your android app plays a decisive role in application development where devices work on pay-by-the-byte plans.
So, here are a few ways of reducing the size of your android app.
Avoid using Pngs ( use vector images ) .
Use pngcrush for compressing the png .
Url: https://pmt.sourceforge.io/pngcrush/
Try to get most of the images from a server rather than keeping them in source code.
Use Dynamic Delivery concept to load on-demand features during runtime.
Avoid using third party #libraries which can be done simply by a few lines of code.
"Android Size Analyzer" this #plugin helps you in reducing the size of the app by giving you suggestions.
Switch to Android App #Bundles from #APKs while publishing app or releasing updates. In this way , App is built based on CPU architecture (ABI), Language and Screen Density of the device.
Documentation: https://developer.android.com/studio/build/configure-apk-splits
Important :
Set minifyEnabled and shrinkResources to true in your gradle.
If you want to read more, you can visit my linkedIn profile post.
Url : https://www.linkedin.com/posts/abhishek-gupta-9b32b816b_android-app-development-activity-6609095411581972480-heF8

Categories

Resources