问题
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