cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to build the mobile SDK examples. With Android Studio Dolphin | 2021.3.1 Patch

simoncl
Honored Guest

Hi.

 

Following these instructions. https://developer.oculus.com/documentation/native/android/mobile-studio-basics/

 

First I hit. 

Task 'prepareKotlinBuildScriptModel' not found in project ':VrSamples:VrCubeWorld_Framework:Projects:Android'.

 

So adding 

task prepareKotlinBuildScriptModel {

}

I then hit. 

 

Exception during working with external system: java.lang.AssertionError

 

Any help would be appreciated.

I can successfully build and emulate standard android apps and NDK apps using Vulkan. 

3 REPLIES 3

Anonymous
Not applicable

I had also trouble compiling it when I followed instructions. I de-tangled one of the examples from the other ones and also changed the build system to cmake: https://github.com/berndporr/OculusSpatialAnchor

eugene_walkers
Honored Guest

Hey,

Pls check my answer in that topic, probably you'll find it helpful

https://forums.oculusvr.com/t5/Quest-Development/Android-Studio-unable-to-build-any-projects-in-SDK-...

joseangelmt
Honored Guest
I have spent 2 days of my life to get the SDK projects working and this post is for you to save those two days.
 
The truth is that everything related to the Android Studio build system is very frustrating because you must configure a lot of components separately, components that are often not compatible with each other, and also many times Android Studio works with cached information and you have to tell it to clear the cache to work with the changes you made, etc..
 
In addition, the SDK projects are built in such a way that Android Studio is not able to manage them correctly and problems appear:
 
1. When selecting File/Project Structure, the Android Gradle Plugin Version and Gradle Version fields always appear empty and even if you enter some value, it is useless: no file is modified and if you open the dialog box again, they are empty again.
2. If it detects that there is a newer version of the Gradle plugin, the wizard is not able to locate the active version (although curiously it has detected that there is a newer version so that in theory it knows which version you are in).
3. Android Studio is unable to find the file 'gradle-wrapper.properties'. In File/Settings/Build, Execution, Deployment/Gradle if you select Use Gradle from: 'gradle-wrapper.properties' file, it will show you an error indicating that it does not find the file 'gradle-wrapper.properties'.
 
This tutorial is to get the projects compiled in Android Studio Flamingo | 2022.2.1 Patch 2 which is the latest version as of today (May 5, 2023) and in it, we will also update the Gradle plugin to version 7.0.2 (because I have not been able to make it work in 7.4.2). 
 
I've run everything on Windows and the truth is that I'm too lazy to try everything on Mac or Linux, because I've already lost 2 days of my life in this, so I hope that even if your OS is not Windows, at least these steps will help you. I'm going to do the steps on a virtual machine with clean Windows, a machine that has never had Android Studio or Java, or anything else installed.
 
1. Download and install Android Studio.
2. Download the zip with the SDK, I downloaded ovr_openxr_mobile_sdk_53.0.zip. Unzip it.
3. Open with Android Studio any of the projects, I have opened the (OculusSDKRoot)XrSamples\XrSpatialAnchor\Projects\Android folder.
 
Android Studio will start downloading and executing libraries and after a while, it will show you an error like the following:
 
Captura1.png
4. As you can see, it tells us to add the path to the SDK either in an environment variable or in the (OculusSDKRoot)\local.properties file (which does not exist in the SDK). Create that file with the next content (changing "Josea" with your user name).
 
sdk.dir=C\:\Usersers\\Josea\AppData\Local\Android\Sdk
 
5. Click the Sync Project with Gradle Files button or select the File/Sync Project with Gradle Files menu option. Now the following error message will be displayed: 
 
Captura2.png
 
Indicating that we must install a compatible NDK, and they indicate that the default version would be 21.0.6613669.
 
6. Click the SDK Manager button (a 3D cube with a down arrow) or by selecting the menu option File/Settings and select on the left side Appareance & Behavior/System Settings/Android SDK.
7. In the SDK Platforms tab select Android 8.0 (Oreo), as this is the Android version with API Level 26 number which is the version number for which the SDK projects are configured.
8. In the SDK Tools tab click on the Show Package Details checkbox to display the different versions of the components and open NDK (Side by side) and select version 21.0.6613669. Accept.
9. Click the Sync Project with Gradle Files button or select the File/Sync Project with Gradle Files menu option. Now the following error message will be displayed: 
 
Captura3.png
10. This error is caused because the version of the JDK being used by default with this version of Android Studio is not compatible with the version of the Gradle Plugin and the version of Gradle configured with the project.
11. Open the (OculusSDKRoot)build.gradle file. There you can locate that we have the following line:
 
classpath 'com.android.tools.build:gradle:4.0.0'.
 
The 4.0.0.0 is the version of the Graddle Plugin that the program has configured. This plugin must run with a certain version of Gradle, and in turn, this version of Gradle must run with a certain version of Java.
 
If you go to https://developer.android.com/build/releases/gradle-plugin#updating-gradle and click on the Older versions button you will see that version 4.0.0.0 of the plugin requires a version of Gradle 6.1.1, and this version of Gradle we would have to look for which version of Java corresponds to it.
 
As it is an incredibly outdated version, we are going to update everything, so modify the file (OculusSDKRoot)build.gradle and change that line to version 7.0.2. If you look at that table, the Gradle version required for the plugin version 7.0 is 7.0. Now we only need to know the Java version on which Gradle 7.0 must run. If you go to https://developer.android.com/build/releases/gradle-plugin#updating-gradle you can check that it is 16.
 
12. Modify the file (OculusSDKRoot)build.gradle and change the Gradle plugin version to 7.0.2:
 
classpath "com.android.tools.build:gradle:7.0.2"
 
13. Do the same with the file (OculusSDKRoot)VrApp.gradle
14. Now we must specify the version of Gradle that corresponds with this version of the plugin. The version is specified in the gradle-wrapper.properties that in the Oculus SDK appears in the path: (OculusSDKRoot)gradle/wrapper/gradle-wrapper.properties.
 
Open this file and replace the value that appears in the distributionUrl variable with the following:
 
distributionUrl=https://services.gradle.org/distributions/gradle-7.0.2-all.zip
15. In theory we have correctly configured the Gradle Plugin and the Gradle version to use, but if you press the Sync Projects with Gradle Files button you will see that it does not work.
 
The problem is that Android Studio is not locating the gradle-wrapper.properties file that we just modified. Let's check it.
16. Select File/Settings/Build, Execution, Deployment/Build Tools/Gradle: If you notice an error appears to the right of Use Gradle from: 'gradle-wrapper.properfies' file:
 
Captura4.png
 
I have analyzed the files that Android Studio opens with Process Monitor and I have seen that it really tries to open the file in the path: (OculusSDKRoot)XrSamples\XrSpatialAnchor\Projects\Android\gradle\wrapper\gradle-wrapper.properties, and not in the path (OculusSDKRoot)gradle\wrapper\gradle-wrapper.properties, so we just must copy the folder (OculusSDKRoot)gradle in (OculusSDKRoot)XrSamples\XrSpatialAnchorjects\Android
 
17. Select File/Settings/Build, Execution, Deployment/Build Tools/Gradle again. Now the error message is no longer displayed because Android Studio does locate the gradle-wrapper.properfies file.
 
All that remains is to specify the Java version with which Gradle should be run.
18. In Gradle JDK press the arrow button and select in the context menu the option Download JDK...
19. In the Download JDK dialog box select Version 16 (which I remind you was the Java version compatible with Gradle 7.0). You will see that Amazon Corretto 16.0.2 is automatically selected in Vendor. Click Download and OK in the Settings dialog box.
19. Now we must clear caches. Select the File/Invalidate caches... option and in the dialog box, check all the checkboxes and click OK to restart Android Studio.
 
And you're done!
 
Remember that you must copy in each project (XrBodyFaceEyeSocial, XrBodyTrackingFB, ....) in their Projects/Android directories the gradle directory that you have in the SDK root directory.