I have searched for this a lot, but didn't get a solution and hence posting this.
Scenario: I'm building an Android app which uses opencv library. When I build the APK file the size of apk is '66' MB which is too much for my app.I'm using the latest version of OpenCV
Analysis : When I analyze the apk file, I could see that the size is too big due to 'libopencv_java3.so' file in all architectures like amr64, armeabi, mips, x86 etc. If I remove all those files and build APK, then the size is 7 MB only, which can work only with OpenCVManager installed in the target device
Problem : I don't want my app users to install another app (OpenCVManager) to run my app. So, just want to know, what all are the possible solutions to reduce the apk size of the app to work without the help of OpenCVManager ?
This is a simplified version of this(1) SO answer. Download latest OpenCV sdk for Android from OpenCV.org and decompress the zip file. Import OpenCV to Android Studio, From File -> New -> Import Module, choose sdk/java folder in the unzipped opencv archive. Update build.
You can compress an APK file (rar, zip), but it has to be decompressed in order to work. ProGuard is a free Java class file shrinker, optimizer, obfuscator, and preverifier. It detects and removes unused classes, fields, methods, and attributes. It optimizes bytecode and removes unused instructions.
You can enable ABI splitting in the build.gradle file like this:
android {
// Some other configuration here...
splits {
abi {
enable true
reset()
include 'x86', 'armeabi', 'armeabi-v7a', 'mips'
universalApk false
}
}
}
Refer this link https://realm.io/news/reducing-apk-size-native-libraries/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With