Most applications on Android are developed in Java, and Android provides a rich framework of classes to support this. It is, however, also possible to develop parts of an application in native C/C++ code using the Android NDK. This is intended for accessing existing C/C++ codebases or potentially optimizing performance critical functions.
The general approach is to build a native C/C++ shared library containing functions that are exposed using the JNI naming scheme. A Java application can then load the library and map the native functions to Java methods, which can then be called like any other method in Java. Using this approach it is now possible to create ARToolKit applications on Android.
Certain parts of these applications, must be implemented in Java, other parts can be written in C/C++. Therefore, applications will typically be a combination of C/C++, Java, and the “glue” in between.
This SDK includes components in both C/C++ and Java to permit the development of ARToolKit applications on Android. These components include:
-
ARToolKit core modules. These are native static libraries which can be used to build a shared library.
-
ARToolKitWrapper: a C++ wrapper around ARToolKit, providing high level access to ARToolKit functions and marker management, with C and JNI interfaces. This is a native shared library that can be included in an Android application.
-
ARBaseLib: a Java Android library that communicates with ARToolKitWrapper. By using the classes provided ARBaseLib, an Android application gains easy access to the native functionality of ARToolKit.
With these components, several development strategies are possible, ranging in complexity:
-
Native development by creating a new shared library that links to the ARToolKit static libraries.
-
Native development by creating a new shared library that utilizes ARToolKitWrapper.
-
Java development using the provided ARBaseLib (Java) and ARToolKitWrapper (native) libraries.
Video Capture on Android
The ARToolKit port includes almost all of the core modules; the notable exception being the video capture module, which in other ARToolKit versions provides a standard interface for accessing video capture on different platforms and hardware.
Android does not currently permit camera access from native code. Instead, only Java code can open the camera and capture frames. Additionally, a live camera preview must be included in the current Activity’s view for frames to be captured. This means that ARToolKit itself cannot initiate video capture, but must instead wait on the Java application to pass video information and frames using JNI.
Therefore, video capture requires coordination between corresponding libraries on either side of JNI. While this forces a slightly fragmented approach, ARToolKitWrapper and ARBaseLib libraries are provided to handle the issue. Alternatively, the ARNative example included in the SDK demonstrates how to pass video independently of these libraries.
至于校准,属于独立篇章,之后看。
Developing with ARToolKitWrapper and ARBaseLib
You can copy the entire libs directory from: android/libs
Please ensure that you run the build.sh and build native.sh prior to copying the directory.
Read the Android Native Development for more information. Note: There are subdirectories for each CPU architecture, including armeabi, armeabi-v7a, mips and x86. It is the same library built for different instruction sets. The appropriate version is automatically chosen at runtime.
##ARBaseLib ARBaseLib provides additional classes to simplify development.
ARBaseLib is an Android library, meaning that it isn't an Android application itself, but can make use of the Android framework. Android applications can reference the library, and AndroidStudio will take care of including the necessary files when the APK is built and deployed. This allows reusable components to be placed in the library and used in many different examples and applications.
To use ARBaseLib, import the ARBaseLib as new module to your AndroidStudio project:
1. **File/Project Structure…** 2. Add a new module with the **+** button at the top left of by pressing ⌘+N (OSX) Alt+Insert (Windows) 3. Select **Import .JAR/.AAR Package** hit Next 4. Select the file with the ... on the right of the first text field. The ARBaseLib.aar file is located in $ARTOOLKIT5ROOT/AndroidStuiodProjects/ARBaseLibProj/arBaseLib/build/outputs/aar/