- Overview
- Video
- Steps
- 1.8.1. Download Android Studio
- 1.8.2. Install 32-bit libraries
- 1.8.3. Unpack Android Studio
- 1.8.4. Run Android Studio
- 1.8.5. Select standard installation options
- 1.8.6. Wait for components to install
- 1.8.7. Run SDK Manager
- 1.8.8. Select CMake, LLDB, NDK components
- 1.8.9. Accept license
- 1.8.10. Wait for CMake, LLDB, NDK to install
- 1.8.11. Start Android code sample import
- 1.8.12. Import 'Hello GL2' sample
- 1.8.13. Try to run 'Hello GL2' sample
- 1.8.14. Start AVD creation
- 1.8.15. Select device definition
- 1.8.16. Download system image
- 1.8.17. Select system image
- 1.8.18. Select software graphics renderer
- 1.8.19. Run 'Hello GL2' sample
- 1.8.20. Observe 'Hello GL2' sample
- 1.8.21. Start a new Android Studio project
- 1.8.22. Include C++ support
- 1.8.23. Select empty activity
- 1.8.24. Turn on C++11, exceptions, and RTTI
- 1.8.25. Run the project
- 1.8.26. Clone OSG alongside the project
- 1.8.27. Clone sample OSG application alongside the project
- 1.8.28. Copy Android part into the project
- 1.8.29. Update RenderActivity
- 1.8.30. Update AndroidManifest
- 1.8.31. Update CMakeLists
- 1.8.32. Specify target ABIs
- 1.8.33. Build the project
- 1.8.34. Try to run the project
- 1.8.35. Observe error
- 1.8.36. Fix osgNativeLib reference
- 1.8.37. Run the project
This tutorial is part of OpenSceneGraph cross-platform guide.
In this tutorial we build and run sample OpenSceneGraph application under Android. The application displays provided model with simple GLSL shaders.
Note: this tutorial requires OpenSceneGraph model (see 1.1. Create a cube)
Video depicts running and building sample OpenSceneGraph application with Android Studio 2.3.1 under Xubuntu 16.04.
Note: steps below use frames from the video as screenshots. Watch the video to see all details.
Download the latest version of Android Studio. It contains all the tools you need to develop for Android.
According to Android Studio installation instructions 64-bit Ubuntu needs several 32-bit libraries to make Android Studio work.
Install necessary 32-bit libraries with the following command:
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
Extract Android Studio archive into your home directory.
Run Android Studio with the following commands:
cd ~
./android-studio/bin/studio.sh
Select standard installation options.
Wait for standard components to install.
Select Configure -> SDK Manager to run SDK Manager, which we will use to install additional components.
We need CMake, LLDB, and NDK components to build C++ for Android.
Select them in SDK Tools tab of SDK Manager.
To install CMake, LLDB, and NDK, we need to accept the license.
Wait for additional components to install.
Select Import an Android code sample.
Locate 'Hello GL2' sample and import it.
When we try to run 'Hello GL2' sample, an empty list of devices is presented.
We need to create Android Virtual Device to run 'Hello GL2' sample.
Select device definition. This is effectively the size of AVD.
This tutorial uses Nexus One 3.7" with 480x800 resolution.
Download armeabi-v7a system image. It emulates ARMv7, which is the most widespread architecture for Android.
You may install other system images to test your application on other architectures.
Select downloaded system image.
This step is optional. You only need to select software graphics renderer if you run Android Studio in an environment that lacks 3D acceleration.
Select created AVD to run the sample.
You should see green triangle. This means AVD can display GLES2 graphics.
Start a new Android Studio project.
This option adds sample C++ native library to the project.
We will use its CMakeLists.txt file later.
Since we only need one screen, select empty activity.
Turn on C++11, exceptions, and RTTI, because they are necessary to build OpenSceneGraph.
Run the project. It should display a screen with Hello from C++ text.
Clone OpenSceneGraph alongside the project with the following commands:
cd ~
cd AndroidStudioProjects
git clone https://github.com/openscenegraph/OpenSceneGraph
Note: you must place OpenSceneGraph alongside the project, because sample OpenSceneGraph application's Android part requires it.
Clone sample OpenSceneGraph application alongside the project with the following commands:
cd ~
cd AndroidStudioProjects
git clone https://github.com/ogstudio/openscenegraph-cross-platform-guide-application
Note: you must place sample OpenSceneGraph application alongside the project, because sample OpenSceneGraph application's Android part requires it.
Copy Android part into the project with the following commands:
cd ~
cd AndroidStudioProjects
cp -R openscenegraph-cross-platform-guide-application/android/app your_project
Sample OpenSceneGraph application's android/app directory contains RenderActivity with backing native library, box model, and a few supporting files.
android/app is almost all you need to run OpenSceneGraph application under Android.
Import your package's R
class inside RenderActivity, so that it can
reference box model from you project's resources.
- Request GLES2 support by adding
<uses-feature android:glEsVersion="0x00020000"/>
- Make RenderActivity the main activity by referencing it with
<activity android:name="org.opengamestudio.osgapp.RenderActivity">
Reference RenderActivity's backing native library's CMakeLists file by adding
include(CMakeLists-osgNativeLib.txt)
to the project's CMakeLists file.
This step is optional.
By default, Android Studio builds the project for all supported architectures. Each architecture requires its own build of OpenSceneGraph. OpenSceneGraph build for single architecture takes about 1.5G.
We restrict the project to ARMv7 ABI to save disk space.
This builds OpenSceneGraph as static libraries and links them
to RenderActivity's backing native library called osgNativeLib
.
Note: make note of the native library's full name.
Try to run the project.
The logs say that osgNativeLib
is missing.
As you noted above, the name should read like osgNativeLibd
.
d
postfix is a side effect of building OpenSceneGraph in Debug mode.
Open osgNativeLib.java
and reference osgNativeLibd
instead of osgNativeLib
.
You should now see red cube displayed.