Opencascade Android Studio

浪尽此生 提交于 2019-12-23 02:21:11

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/38349139/opencascade-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!