Setup Android Studio for Daydream and Oculus development from the NDK

Thankfully Daydream is really easy to work on.  However, Oculus will require a bit of a on your own homework assignment as I can't redistribute their SDK for them.  Daydream's SDK distributes through a maven repository.  So to setup Daydream and make it easy to upgrade for the NDK development.  However, let's assume that you have downloaded Oculus Mobile SDK and have placed it in a known path <oculusPath> for the reference here:  we need to tell Android how to build the C++ by finding the include directories, the library files to link with and ultimately the library files as dependencies so Gradle knows to package them with the APK.

repositories {
maven {
url "http://google.bintray.com/googlevr" }
flatDir {
dirs "<oculusPath>/VrAppFramework/Libs/Android" dirs "<oculusPath>/VrApi/Libs/Android" dirs "<oculusPath>/VrAppSupport/SystemUtils/Libs/Android" }
}
The above sets up the maven repo for Daydream and Cardboard.  Then specifies the local directories gradle can use to find the libs when packaging the app.  Next, we use CMake to identify how to build our product:
android {
    < ... snip ... >
    defaultConfig {
        < ... snip ... >
        externalNativeBuild {
            cmake {
                abiFilters "armeabi-v7a"                cppFlags.addAll( [
                        "-std=c++14"
                ] )
            }
        }
    }
The above sets up the build to use CMake and specifies that we only want the armeabi-v7a ABI.  While Daydream and Cardboard could conceivably use x86, arm64 etc, oculus only supports armeabi-v7a.  So we either set it up here or in a build flavor.  Next we need to tell Java that we should package those libraries so do that here:
dependencies {
    oculusCompile 'com.oculus.vrappframework:VrAppFramework'    oculusCompile 'com.oculus.vrapi:VrApi'    daydreamCompile 'com.google.vr:sdk-base:1.10.0'    daydreamCompile 'com.google.vr:sdk-audio:1.10.0'}
The above tells java that if it's the oculus variant, it should package Oculus libs and if we're compiling daydreamCompile, we should grab those variants.  Finally to actually grab the daydream sdk automatically:
task extractGoogleVrNDK {
    doLast {
        configurations.compile.each {
            if (it.name.contains("sdk-base") || it.name.contains("sdk-audio")) {
                def file = it.absoluteFile
                copy {
                    from zipTree(file)
                    into "src/main/jniLibs"                    include "jni/**/libgvr*.so"                }
            }
        }
    }
}

task deleteGoogleVRNDK(type: Delete) {
    delete "src"}

tasks.whenTaskAdded { task ->
    if (task.name.startsWith('generate')) {
        task.dependsOn extractGoogleVrNDK
    }
}
The above sets up the custom tasks needed to grab the Daydream aar, and then extracts the libraries that we'll be using for linking packaging.  Finally just use the libraries and include directories as you normally would with a CMakeFile.txt setup.  Please post any questions and I'll elaborate further.

Comments

Popular posts from this blog

Drone VR Software Architecture

Build Snapdragon Flight Drone

Soldering new connectors for the drone