Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce the apk size of my Android app with openCv library integrated

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 ?

like image 742
AKHIL Avatar asked Feb 03 '17 07:02

AKHIL


People also ask

Can we use OpenCV for Android app?

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.

Can you compress APK files?

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.


1 Answers

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/

like image 94
Mayur Gangurde Avatar answered Oct 12 '22 20:10

Mayur Gangurde