cancel
Showing results for 
Search instead for 
Did you mean: 

Tried to use Oculus Go and CMake [NDK] together: "More than one externalNativeBuild path specified"

mcc
Expert Protege
I have an existing C/C++ project. It works on desktop with the Oculus SDK for Windows. I want to run it on Oculus Go.

My existing project is built using CMake. Because the project has several complex dependencies, it would be a major imposition to switch from CMake to ndkBuild or whatever. Luckily the Android docs https://www.google.ca/search?q=ndk+cmake+gradle claim cmake is supported in current ndk+gradle.

I downloaded ovr_sdk_mobile_1.16.0. I was not able to get Android Studio to work on my computer but I am able to compile and deploy the included VrSamples/VrCubeWorld_Framework sample using gradlew. I am happy using gradlew.

For my next step I attempt to insert the code from my game into the VrCubeWorld_Framework sample. I start by just modifying build.gradle for VrCubeWorld_Framework. It is attached. What I did is I added 
cmake { arguments "-DOCULUS_ANDROID_EMBED=TRUE" }
to the "defaultConfig { externalNativeBuild {} }" block, and
externalNativeBuild { cmake { path "../../lovr/CMakeLists.txt" } }
to the android {} block. This is what the google documentation said to do.

Now when I run gradlew I get this error:







FAILURE: Build failed with an exception.


* What went wrong:


A problem occurred configuring project ':VrSamples:VrCubeWorld_Framework:Projects:Android'.


> More than one externalNativeBuild path specified

I am not familiar with Gradle but I looked on google and it turned up the gradle source code (!). It looks like you cannot use ndkBuild and Cmake in the same project.

I try commenting out the ndk and ndkBuild in my externalNativeBuild but I still get the error. So I try searching the directory for "externalNativeBuild" and— oh no!—VrApp.gradle, which VrCubeWorld_Framework includes with "apply from", is using externalNativeBuild! It looks as if I cannot use ovr_sdk_mobile_1.16.0 without using ndkBuild and I can't use ndkBuild and CMake in the same project.

Here is my question:

Has anyone ever used CMake with Oculus Go? Is there sample code?

Can I somehow include the VrApp/VrAppFramework/VrAppSupport code as a library, so that I can quarantine the ndkBuild and CMake in separate gradle files?

Can I somehow build *my* CMake code as a library, which is automatically built when VrAppSupport is built?

CMake is a very common program, it seems surprising if literally you cannot use it with the Oculus Go.
3 REPLIES 3

fgeorg
Explorer
I'm running into the same issue. This post seems to suggest that if you're using Android studio you have to convert the existing ndkBuild code to use cmake.

mcc
Expert Protege
I was looking into this today. Here is what I learned:
* You cannot mix cmake and ndkBuild in one project. However, in a "multi-project build", you can use ndkBuild in some of the subprojects and CMake in other subprojects.
* I was successfully able to add CMake to the VrCubeWorld_Framework sample by creating a separate project (i.e., a separate directory with its own `build.gradle`) and `include`-ing it in the VrCubeWorld_Framework `settings.gradle`.
* The 
VrCubeWorld_Framework project is already a multi-project build because `:VrAppFramework:Projects:Android`, `:VrAppSupport:VrGUI:Projects:Android` et al are all separate subprojects. While `:VrAppSupport:VrGUI:Projects:Android` would be very hard to convert to CMake, converting only the `VrCubeWorld_Framework` subproject to CMake should be very easy because it only contains one cpp file. If I am successfully able to do this I will post back to report…

mcc
Expert Protege
Wanted to come back and report on this.

I eventually managed to get my project working on Oculus despite using CMake. The way I did this was by copying the ndkBuild script used by VrCubeWorld, creating a separate gradle subproject to use CMake, and including my cmake-built library as a prebuilt shared library module within the ndkBuild script. In order for this to work I have to run gradle twice every time I build (I think this is a bug, and have told google so), but it works, however awkwardly…

@imperativity if I can, I would like to strongly urge you to create a version of the SDK which uses CMake rather than ndkBuild, or create an SDK sample which uses CMake. Google is promoting CMake over ndkBuild heavily so more people will wind up doing CMake NDK projects in future. But trying to bridge ndkBuild and CMake meant that my Oculus Mobile port project took literal weeks longer than it would have if I had had a working example of how to use CMake to start, and even now that it "works" it results in this weird "run gradle twice" requirement… I'm not sure I would have been able to get this working at all if I didn't have a certain amount of experience with Android tooling, so it's possible sometime in future who is newer to Android/Make will not be able to figure it out and their project will never finish…