58904

Opencascade Android Studio

Question:

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

<a href="http://www.opencascade.com/doc/occt-7.0.0/overview/html/samples_java_android_occt.html" rel="nofollow">http://www.opencascade.com/doc/occt-7.0.0/overview/html/samples_java_android_occt.html</a>

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.

Answer1:

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

<ol><li>Follow the steps carefully given here <a href="https://dev.opencascade.org/doc/overview/html/occt_dev_guides__building_android.html" rel="nofollow">Building with CMake for Android</a></li> <li>Use only Freetype that comes with Open Cascade installer. FreeImageand others are not required for this sample.</li> <li>After successful configuration and generation of CMake files, follow the step 1 URL.</li> <li>

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.

</li> </ol>

<strong>NOTE</strong> : android-xx depends on ANDROID_NATIVE_API_LEVEL. It can be android-15.

<ol start="5"><li>If no errors are there then continue to follow the step 1 URL.</li> <li>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.</li> <li>I've created the binaries. <a href="https://www.dropbox.com/sh/0bzx0t25qpcfg97/AACdCNuRMQzCsNcqRL58e7l-a?dl=0" rel="nofollow">download from here</a> and copy the binaries in jnilibs folder in project.</li> <li>Apart from freetype no other 3rd party library is required. </li> </ol>

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))

<strong>NOTE</strong> :

<ol><li>

Use latest gradle experiment for the sample.

</li> <li>

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

</li> <li>

I have used OCC 7.0.0 and latest Android Studio.

</li> </ol>

I am attaching <a href="https://www.dropbox.com/s/dt06jkatcr5b5b2/OcctJniViewer.zip?dl=0" rel="nofollow">source code</a> and <a href="https://www.dropbox.com/s/1luz4j3hskfmgh4/inc.zip?dl=0" rel="nofollow">OCC/include</a> folder.

Recommend

  • Looping through .dat files in R and extracting only specific data as columns
  • ctrl+space key binding not working for commenting in Sublime Text 3
  • Paper.js Subraster Added Behind Rectangle Instead of in Front
  • Identify C++ style comments with asm-mode in Emacs Lisp
  • R - Keep log of all plots
  • How can I use the return of a MAPLE procedure as a function directly
  • MySpace DOM?
  • StreamWriter won't flush to NetworkStream
  • Plot a table with R
  • How to share a database between ASP.NET MVC 5 application and .NET console application?
  • Extract data between rows r
  • Special chars in Amazon S3 keys?
  • Subversion reverting resolved file
  • Greek letters in legend in R
  • composer dependency stating in doesn't have php-xsl
  • Certain Arabic text gets incorrectly shown while other Arabic text gets showed normally?
  • Emacs lua-mode issue: (void-function interactively-called-p)
  • Want to understand iframe breakout code
  • Wrapping text in spinner android
  • Run multiple queries from 1 SQL file showing result in multiple tables
  • Xcode 4 NSLog Macro link in Xcode 3
  • $wpdb not working in file of WordPress plugin
  • Meteor helpers not available in Angular template
  • Is there a javascript serializer for JSON.Net?
  • Using $this when not in object context
  • How do I fake an specific browser client when using Java's Net library?
  • How reduce the height of an mschart by breaking up the y-axis
  • Perl system calls when running as another user using sudo
  • Where to put my custom functions in Wordpress?
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • Buffer size for converting unsigned long to string
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How to get Windows thread pool to call class member function?
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Binding checkboxes to object values in AngularJs
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal