Huge apk filesize when using OpenCV

坚强是说给别人听的谎言 提交于 2019-12-18 13:47:09

问题


I am building a prototype app with OpenCV. The app currently does not do anything but its apk file size is 6MB. The size is 10 times of normal app size. Is there any way to reduce this size?

Update: I found out that as long as I use android native camera and interface with OpenCV in JNI/C++, the file size can be dependent on the methods you are using in the library. Current my test app with simple filter has size of 700K.


回答1:


You can unzip your .apk file and find two versions of opencv_java.so under the lib folder. Each of them is about 5.6Mb.

Actually opencv_java.so is the OpenCV library. And it is hard task to reduce its size even to 4Mb. But you can easily remove second copy of opencv_java.so from your .apk if you don't need to support old ARMv5 and ARMv6 devices. (The simplest way to build your app without armeabi OpenCV libraries is removing all libs/armeabi folders from OpenCV package and rebuilding your application.)




回答2:


If you are using Android Studio goto build.gradle of your app and add following lines inside android {}

productFlavors {
        x86 {
            ndk {
                abiFilter "x86"
            }
        }
        armv7a {
            ndk {
                abiFilter "armeabi-v7a"
            }
        }
}

This will allow you to create separate apk for separate architecture thus decrease the size of apk by alot.




回答3:


You can use ProGuard to remove the code (from the "binary") that you are not using from OpenCV.



来源:https://stackoverflow.com/questions/8283206/huge-apk-filesize-when-using-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!