我使用的OpenCV(C ++不是Java)在一个新的Android应用程序的工作,我是新来的OpenCV都和NDK。我把它建设(和运行)成功地使用下面的摇篮文件,并在Android Studio中我可以选择一个变体和击筑(如86)。
我有2个问题:
有没有一种方法可以让我有一个构建一个APK支持所有架构的变种? (我知道文件大小将更大)我能实现构建,而不指定所有相同的库对每个变种。有没有什么办法可以使构建系统只需拿起库因为每次他们都内的项目和建筑名称组织的?
应用插件:'com.android.application安卓{compileSdkVersion 21buildToolsVersion21.0.0defaultConfig { 的applicationIDuk.co.xxx.androidcppimagereader 17的minSdkVersion targetSdkVersion 21 版本code 1 的versionName1.0}高清libsDir = projectDir.path +/库/productFlavors { 86 { 版本code的Integer.parseInt(3+ defaultConfig.version code) NDK { abiFilter86 MODULENAME处理 STLgnustl_static CFLAGS-I /选择/本地/包括/ OpenCV的-I /选择/本地/包括 LDLIBS libsDir +86 / libopencv_core.a LDLIBS libsDir +86 / libopencv_ts.a LDLIBS libsDir +86 / libopencv_contrib.a LDLIBS libsDir +86 / libopencv_ml.a LDLIBS libsDir +86 / libopencv_java.so LDLIBS日志 LDLIBSZ,jnigraphics } } {的ARMv7 版本code的Integer.parseInt(2+ defaultConfig.version code) NDK { abiFilterarmeabi-V7A MODULENAME处理 STLgnustl_static CFLAGS-I /选择/本地/包括/ OpenCV的-I /选择/本地/包括 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日志 LDLIBSZ,jnigraphics } } 手臂{ 版本code的Integer.parseInt(1+ defaultConfig.version code) NDK { abiFilterarmeabi MODULENAME处理 STLgnustl_static CFLAGS-I /选择/本地/包括/ OpenCV的-I /选择/本地/包括 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日志 LDLIBSZ,jnigraphics } }} buildTypes { 发布 { minifyEnabled假 proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro } }}依赖{ 编译文件树(导演:'库',包括:['的* .jar']) 编译com.android.support:appcompat-v7:21.0.3}
解决方案
使用关键字胖你已经定义了你计划在的build.gradle文件您的APK,包括作为$ C $高亮所有架构后, C以下。这将建立一个FAT二进制文件。观看此视频,了解更多详情 https://www.youtube.com/watch?v=kFtxo7rr2HQ
ARM { 版本code的Integer.parseInt(1+ defaultConfig.version code) NDK { abiFilterarmeabi MODULENAME处理 STLgnustl_static CFLAGS-I /选择/本地/包括/ OpenCV的-I /选择/本地/包括 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日志 LDLIBSZ,jnigraphics } **脂肪**}buildTypes { 发布 { minifyEnabled假 proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro }}
![创建和编写第一个android app,android studio 创建第一个app之hello world](https://p.xsw88.cn/allimgs/daicuo/20230907/3978.png)
I am working on a new android app using OpenCV (C++ not Java) and I am new to both opencv and the NDK. I have it building (and running) succesfully using the Gradle file below and in Android Studio I can select a variant and hit build (e.g. x86).
I have 2 questions:
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'
}
解决方案
Use the keyword "fat" after you have defined all architectures that you plan to include in your apk in the build.gradle file as highlighted in the code below . This will build a FAT binary. Watch this video for more details https://www.youtube.com/watch?v=kFtxo7rr2HQ
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"
}
**fat**
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
相关推荐
最新文章