Opencascade Android 工作室

Opencascade Android Studio

我正在尝试在以下 url.

的帮助下在 Opencascade 上构建一个 Android 应用程序

http://www.opencascade.com/doc/occt-7.0.0/overview/html/samples_java_android_occt.html

一切正常,除了我遇到以下错误:

07-12 17:13:09.711: E/occtJniViewer(16333): Error: native library "gnustl_shared" is unavailable:

07-12 17:13:09.711: E/occtJniViewer(16333):   dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.opencascade.jnisample-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libgnustl_shared.so"

Error: native library "freetype" is unavailable:

07-12 17:13:09.711: E/occtJniViewer(16333):   dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.opencascade.jnisample-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libfreetype.so"

Error: native library "freeimage" is unavailable:

07-12 17:13:09.711: E/occtJniViewer(16333):   dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.opencascade.jnisample-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libfreeimage.so"

Error: native library "TKernel" is unavailable:

07-12 17:13:09.711: E/occtJniViewer(16333):   dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.opencascade.jnisample-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libTKernel.so"

我无法添加 gnustl_shared 库和其他 .so files。请建议步骤,因为上面 link 没有提供太多关于这些的详细信息。

任何帮助都会有很大的帮助。谢谢。

OpenCascade 不提供任何用于构建应用程序的二进制文件。 在 Windows OS :

中为 Android 构建您自己的 .so 二进制文件
  1. 仔细按照此处给出的步骤进行操作 Building with CMake for Android
  2. 仅使用 Open Cascade 安装程序附带的 FreetypeFreeImage此示例不需要其他内容。
  3. 成功配置并生成 CMake 文件后,按照步骤 1 URL。
  4. 为 Android 创建二进制文件时会出现很多问题。遵循以下技巧:

    一个。与 declspec(dllexport) x 有关的错误。它来自 OCC 内部 freetype-x.x.x/include/config/ftoption.h 附带的第 3 方库 freetype。可以通过注释掉错误中给出的行号(如果使用 OCC 7.0.0 则为 282)并输入 #define FT_EXPORT_DEF(x) x 来解决。

    b。使用make命令重新开始构建。

    c。将 freetype.so 粘贴到 freetype-xx/lib 中。从 ..\android-ndk\platforms\android-xx\arch-arm\usr\lib 复制 libEGL.so 并将其粘贴到 freetype-xx/lib.

    d。打开步骤 1 中给出的 CMake 输出文件夹的 inc 文件夹。复制 ..\android-ndk\platforms\android-xx\arch-arm\usr\include 中的内容并粘贴到 inc 文件夹中。按照步骤 4.b.

注意:android-xx 取决于 ANDROID_NATIVE_API_LEVEL。可以是android-15.

  1. 如果没有错误则继续执行步骤 1 URL。
  2. 安装成功后,进入CMake输出目录,在任何子文件夹(可能是lin32/gcc/lib)中寻找lib文件夹。在 lib 文件夹内,所有必需的二进制文件都将在那里。
  3. 我已经创建了二进制文件。 download from here 并将二进制文件复制到项目的 jnilibs 文件夹中。
  4. 除了 freetype 之外,不需要其他第 3 方库。

现在回到问题 - gnustl_shared 不需要添加为外部二进制文件。

app\build.gradle里面使用下面的代码

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 24
        buildToolsVersion = "24.0.2"

        defaultConfig.with {
            applicationId = "com.occ_poc_as"
            minSdkVersion.apiLevel = 21
            targetSdkVersion.apiLevel = 24
            versionCode = 1
            versionName = "1.0"
        }
        buildTypes {
            release {
                minifyEnabled = false
                proguardFiles.add(file('proguard-android.txt'))
            }
        }

        ndk {
            moduleName = "OcctJni_Viewer"
            cppFlags.add("-I${file(getOpenCascadeDir())}".toString())
            cppFlags.add("-frtti")
            cppFlags.add("-fexceptions")
            stl = "gnustl_shared"
            toolchain = 'clang'
            ldLibs.addAll(['android', 'log', 'EGL', 'GLESv2'])
            cppFlags.addAll(['-Wall', '-std=c++11'])
            CFlags.addAll(['-Wall', '-std=c++11'])
        }

        productFlavors {
            // for detailed abiFilter descriptions, refer to "Supported ABIs" @
            // https://developer.android.com/ndk/guides/abis.html#sa
            create("arm7") {
                ndk.with {
                    abiFilters.add("armeabi-v7a")
                    ldFlags.add("-L${file('src/main/jniLibs/armeabi-v7a')}".toString())
                    File curDir = file('./')
                    curDir = file(curDir.absolutePath)
                    String libsDir = curDir.absolutePath + "\src\main\jniLibs\armeabi-v7a\"
                    ldLibs.add(libsDir + "libfreetype.so")



                ldLibs.add(libsDir + "libTKBRep.so")
                ldLibs.add(libsDir + "libTKernel.so")
                ldLibs.add(libsDir + "libTKG2d.so")
                ldLibs.add(libsDir + "libTKG3d.so")
                ldLibs.add(libsDir + "libTKGeomAlgo.so")

                ldLibs.add(libsDir + "libTKGeomBase.so")
                ldLibs.add(libsDir + "libTKMath.so")
                ldLibs.add(libsDir + "libTKPrim.so")
                ldLibs.add(libsDir + "libTKTopAlgo.so")
                ldLibs.add(libsDir + "libTKBO.so")

                ldLibs.add(libsDir + "libTKBool.so")
                ldLibs.add(libsDir + "libTKFillet.so")
                ldLibs.add(libsDir + "libTKHLR.so")
                ldLibs.add(libsDir + "libTKIGES.so")
                ldLibs.add(libsDir + "libTKMesh.so")

                ldLibs.add(libsDir + "libTKOffset.so")
                ldLibs.add(libsDir + "libTKOpenGl.so")
                ldLibs.add(libsDir + "libTKService.so")
                ldLibs.add(libsDir + "libTKShHealing.so")
                ldLibs.add(libsDir + "libTKSTEP.so")

                ldLibs.add(libsDir + "libTKSTEP209.so")
                ldLibs.add(libsDir + "libTKSTEPAttr.so")
                ldLibs.add(libsDir + "libTKSTEPBase.so")
                ldLibs.add(libsDir + "libTKV3d.so")
                ldLibs.add(libsDir + "libTKXSBase.so")


                }

            }

        }
    }

}

def getOpenCascadeDir() {
    Properties properties = new Properties()
    properties.load(new File(rootDir.absolutePath + "/local.properties").newDataInputStream())
    def externalModuleDir = properties.getProperty('occ.dir', null)
    if (externalModuleDir == null) {
        throw new GradleException(
                "OpenCascade location not found. Define location with occ.dir in the local.properties file!")
    }
    return externalModuleDir
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar', '.so'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
}

local.properties 内添加以下代码段。

sdk.dir=D\:\Software\android_sdk
ndk.dir=D\:\Software\android-ndk-r12b-windows-x86_64\android-ndk-r12b
occ.dir=D\:\Workspace\OCCT\inc

对于 OcctJniActivity.java 移除 freeimage。将 TKJniSample 替换为

     // application code
     || !loadLibVerbose ("OcctJni_Viewer",  aLoaded, aFailed))

注意

  1. 使用最新的 gradle 样本实验。

  2. 不要忘记在 assest 文件夹中添加着色器。其他的本例不需要

  3. 我用过 OCC 7.0.0 和最新的 Android Studio。

我正在附加 source code and OCC/include 文件夹。