Opencascade Android Studio [英] Opencascade Android Studio

查看:117
本文介绍了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.请建议步骤,因为上面的链接并未提供有关这些步骤的详细信息.

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

解决方案

OpenCascade不提供任何用于构建应用程序的二进制文件. 在Windows OS中为Android构建自己的.so二进制文件:

  1. 按照此处精心给出的步骤使用CMake for Android构建
  2. 仅使用Open Cascade安装程序随附的Freetype. FreeImage和其他不是此样本所必需的.
  3. 成功配置并生成CMake文件后,请遵循步骤1的URL.
  4. 为Android创建二进制文件时会有很多问题.请遵循以下技巧:

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

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

    c.在freetype-xx/lib中粘贴freetype.so.从..\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的网址操作.
  2. 成功安装后,转到CMake输出目录,然后在任何子文件夹(可能是lin32/gcc/lib)中查找lib文件夹.在lib文件夹中,所有必需的二进制文件将在这里.
  3. 我已经创建了二进制文件. 从此处下载,然后将二进制文件复制到jnilibs文件夹中项目.
  4. 除了freetype之外,不需要其他任何第三方库.

现在回到问题-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.

我正在附上源代码 OCC/include 文件夹.

I am trying to build an Android application on Opencascade with the help of below url.

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

Everything works fine except I am stuck in below errors :

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"

I am not able to add gnustl_shared library and other .so files. Please suggest steps as the above link does not provide much detail about these.

Any help will be of great assistance. Thanks.

解决方案

OpenCascade does not provide any binaries for building an application. Build your own .so binaries file for Android in Windows OS :

  1. Follow the steps carefully given here Building with CMake for Android
  2. Use only Freetype that comes with Open Cascade installer. FreeImageand others are not required for this sample.
  3. After successful configuration and generation of CMake files, follow the step 1 URL.
  4. There will be lots of issues while creating binary files for Android. Follow the below tricks :

    a. Error related to declspec(dllexport) x. It comes in 3rd party library freetype that comes with OCC inside freetype-x.x.x/include/config/ftoption.h. It can resolved by commenting out the line number (282 if OCC 7.0.0 is used) given in the error and entering #define FT_EXPORT_DEF(x) x in place of it.

    b. Use the make command to start building again.

    c. Paste freetype.so in freetype-xx/lib. Copy libEGL.so from ..\android-ndk\platforms\android-xx\arch-arm\usr\lib and paste it in freetype-xx/lib.

    d. Open inc folder for CMake output folder given in step 1. Copy the contents in ..\android-ndk\platforms\android-xx\arch-arm\usr\include and paste in inc folder. Follow step 4.b.

NOTE : android-xx depends on ANDROID_NATIVE_API_LEVEL. It can be android-15.

  1. If no errors are there then continue to follow the step 1 URL.
  2. After successful installation, go to CMake output directory and look for lib folder in any subfolders (may be lin32/gcc/lib). Inside lib folder all the required binary files will be there.
  3. I've created the binaries. download from here and copy the binaries in jnilibs folder in project.
  4. Apart from freetype no other 3rd party library is required.

Now coming back to the question - gnustl_shared is not reuired to add as an external binary.

Inside app\build.gradle use below code

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'
}

Inside local.properties add below snippets.

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

For OcctJniActivity.java remove freeimage. replace TKJniSample with

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

NOTE :

  1. Use latest gradle experiment for the sample.

  2. Don't forget to add Shaders in assest folder. Others are not required for this sample

  3. I have used OCC 7.0.0 and latest Android Studio.

I am attaching source code and OCC/include folder.

这篇关于Opencascade Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆