我正在开发一款新的Android应用程序,使用OpenCV(使用C++而不是Java),我对opencv和NDK都很陌生。我已经使用下面的Gradle文件构建(并运行)成功,并且在Android Studio中我可以选择一个变体并进行构建(例如x86)。
我的问题有两个:
- Is there a way I can have a variant that builds an APK supporting all architectures? (I know file size will be bigger)
Can i achieve a build without specifying all the same libs for each variant. Is there any way I can make the build system just pick up the libraries each time since they are all inside the project and organised by architecture name?
apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.0.0" defaultConfig { applicationId "uk.co.xxx.androidcppimagereader" minSdkVersion 17 targetSdkVersion 21 versionCode 1 versionName "1.0" } def libsDir = projectDir.path + "/libs/" productFlavors { x86 { versionCode Integer.parseInt("3" + defaultConfig.versionCode) ndk { abiFilter "x86" moduleName "Processing" stl "gnustl_static" cFlags "-I/opt/local/include/opencv -I/opt/local/include" ldLibs libsDir + "x86/libopencv_core.a" ldLibs libsDir + "x86/libopencv_ts.a" ldLibs libsDir + "x86/libopencv_contrib.a" ldLibs libsDir + "x86/libopencv_ml.a" ldLibs libsDir + "x86/libopencv_java.so" ldLibs "log" ldLibs "z", "jnigraphics" } } armv7 { versionCode Integer.parseInt("2" + defaultConfig.versionCode) ndk { abiFilter "armeabi-v7a" moduleName "Processing" stl "gnustl_static" cFlags "-I/opt/local/include/opencv -I/opt/local/include" ldLibs libsDir + "armeabi-v7a/libopencv_core.a" ldLibs libsDir + "armeabi-v7a/libopencv_ts.a" ldLibs libsDir + "armeabi-v7a/libopencv_contrib.a" ldLibs libsDir + "armeabi-v7a/libopencv_ml.a" ldLibs libsDir + "armeabi-v7a/libopencv_java.so" ldLibs "log" ldLibs "z", "jnigraphics" } } arm { versionCode Integer.parseInt("1" + defaultConfig.versionCode) ndk { abiFilter "armeabi" moduleName "Processing" stl "gnustl_static" cFlags "-I/opt/local/include/opencv -I/opt/local/include" ldLibs libsDir + "armeabi/libopencv_core.a" ldLibs libsDir + "armeabi/libopencv_ts.a" ldLibs libsDir + "armeabi/libopencv_contrib.a" ldLibs libsDir + "armeabi/libopencv_ml.a" ldLibs libsDir + "armeabi/libopencv_java.so" ldLibs "log" ldLibs "z", "jnigraphics" } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.3' }