7f2debb2 |
1 | OCCT JniViewer sample for Android {#samples_java_android_occt} |
2 | ================== |
3 | |
4 | This sample demonstrates simple way of using OCCT libraries in Android application written using Java. |
5 | |
6 | The connection between Java and OCCT (C++) level is provided by proxy library, libTKJniSample.so, written in C++ with exported JNI methods of Java class OcctJniRenderer. |
7 | The proxy library contains single C++ class OcctJni_Viewer encapsulating OCCT viewer and providing functionality to manipulate this viewer |
8 | and to import OCCT shapes from several supported formats of CAD files (IGES, STEP, BREP). |
9 | |
10 | This sample demonstrates indirect method of wrapping C++ to Java using manually created proxy library. |
11 | Alternative method is available, wrapping individual OCCT classes to Java equivalents so that their full API is available to Java user |
12 | and the code can be programmed on Java level similarly to C++ one. |
13 | See description of OCCT Java Wrapper in Advanced Samples and Tools on OCCT web site at |
bbe85f2b |
14 | https://www.opencascade.com/content/advanced-samples-and-tools |
7f2debb2 |
15 | |
bbe85f2b |
16 | Install Android Studio 4.0+ and install building tools (check Tools -> SDK Manager): |
17 | - Android SDK (API level 21 or higher). |
18 | - Android SDK build tools. |
19 | - Android NDK r16 or higher (coming with CMake toolchain). |
20 | Using NDK r18 or newer will require changing ANDROID_STL in project settings. |
21 | - CMake 3.10+. |
7f2debb2 |
22 | |
bbe85f2b |
23 | Specify this folder location in Android Studio for opening project. |
24 | You might need re-entering Android SDK explicitly in File -> Project Structure -> SDK Location settings (SDK, NDK, JDK locations). |
7f2debb2 |
25 | |
bbe85f2b |
26 | This sample expects OCCT to be already build - please refer to appropriate CMake building instructions in OCCT documentation. |
27 | The following variables should be added into file gradle.properties (see gradle.properties.template as template): |
28 | - `OCCT_ROOT` - path to OCCT installation folder. |
29 | - `FREETYPE_ROOT` - path to FreeType installation folder. |
7f2debb2 |
30 | |
31 | FreeImage is optional and does not required for this sample, however you should include all extra libraries used for OCCT building |
32 | and load the explicitly from Java code within OcctJniActivity::loadNatives() method, including toolkits from OCCT itself in proper order: |
33 | ~~~~ |
34 | if (!loadLibVerbose ("TKernel", aLoaded, aFailed) |
35 | || !loadLibVerbose ("TKMath", aLoaded, aFailed) |
36 | || !loadLibVerbose ("TKG2d", aLoaded, aFailed) |
37 | ~~~~ |
bbe85f2b |
38 | Note that C++ STL library is not part of Android system, and application must package this library as well as extra component ("gnustl_shared" by default - see also `ANDROID_STL`). |
7f2debb2 |
39 | |
bbe85f2b |
40 | After successful build via Build -> Rebuild Project, the application can be packaged to Android: |
41 | - Deploy and run application on connected device or emulator directly from Android Studio using adb interface by menu items "Run" and "Debug". This would sign package with debug certificate. |
42 | - Prepare signed end-user package using wizard Build -> Generate signed APK. |