cancel
Showing results for 
Search instead for 
Did you mean: 

Android Studio unable to build any projects in SDK/Build instructions incorrect

TimmyTommyTim
Honored Guest

After spending probably 8 hours trying to install and configure Android Studio I have come to the conclusion that either the SDK or instructions for building any of the SDK samples are outdated.  Is there any plan to update the instructions for ones that might work?  For example, any instructions related to the NDK  or the "Project Structure" window is pretty much totally incorrect.  I have had to literally uninstall and re-install Android Studio 4 times today.  If I had to list specific errors, there would be at least 10 different mismatches and errors, like NDK is missing a "platforms" directory, Task 'prepareKotlinBuildScriptModel' not found in project, and many other unsolved/undocumented issues.

10 REPLIES 10

TimmyTommyTim
Honored Guest

 

 

pro_zac
Heroic Explorer

What instructions are you following? Are you referring to the Native Android Development Software Setup?

https://developer.oculus.com/documentation/native/android/mobile-studio-setup-android/

 

I see that under "Verify Installation of Correct Packages and Version" it tells you to install Android 8.0. This should be Android 10.0. Relevant link: https://developer.oculus.com/blog/meta-quest-apps-must-target-android-10-starting-september-29/

 

Regardless of which page it is, they each have a pair of buttons in the bottom left for reporting bugs and commenting on the quality of the page. I recommend submitting your feedback there so that it is routed to the correct team at Meta. 

 

 

gerald.guyomard
Honored Guest

I am in the exact same situation as you: ovr_sdk_mobile looks outdated and cannot build out of the box with latest Android Studio (Chipmunk 2021.2.1 Patch 1).

The furthest I could get:

- add a stub in project's build.gradle: 

task prepareKotlinBuildScriptModel {

}


- remove line in cflags.mk to have C++ code compile

LOCAL_CFLAGS    += -Werror       # error on warnings

 - Refrain from upgrading android gradle plugin from 4.o to 7.2.1 (reached a dead end with gradle dependencies)

After this the project could sync gradle stuff but compilation fails after passing the build of the native lib on:
Execution failed for task ':VrSamples:VrCubeWorld_Framework:Projects:Android:compileDebugJavaWithJavac'.
> Failed to calculate the value of task ':VrSamples:VrCubeWorld_Framework:Projects:Android:compileDebugJavaWithJavac' property 'options.generatedSourceOutputDirectory'.
> Querying the mapped value of map(java.io.File property(org.gradle.api.file.Directory, fixed(class org.gradle.api.internal.file.DefaultFilePropertyFactory$FixedDirectory, /Users/Gerald/Downloads/ovr_sdk_mobile_1_original_WIP/VrSamples/VrCubeWorld_Framework/Projects/Android/build/generated/ap_generated_sources/debug/out)) org.gradle.api.internal.file.DefaultFilePropertyFactory$ToFileTransformer@313cfcdd) before task ':VrSamples:VrCubeWorld_Framework:Projects:Android:compileDebugJavaWithJavac' has completed is not supported

PXY_XR
Honored Guest

same problem android studio 2021.2.1

eugene_walkers
Honored Guest

The same issue for me. All instructions are outdated, can't launch or even sync test project with SDK

Upd.:

I found solution and was able to sync the test project. As I tried to launch VrCubeWorld_Framework project so I'll describe things I did for that project (I believe it should be applied for any project you want to launch)

I opened VrCubeWorld_Framework only (not a root project)

1) Project Structure -> Modules -> set android ndk version (I set as 25.1.8937393)

Add ndk.dir to vr-sample local.properties file. That is optional thing, but you will not get additional warning

2) Set gradle version to 6.9.1. I tried to launch 7.6, but got an error

3) Copy gradle directory (with gradle wrapper inside) from root project (OculusSDK) to VrCubeWorld_Framework folder

4) add task for VrCubeWorld_Framework inside build.gradle

task prepareKotlinBuildScriptModel {

}

After that it synced succesfully and project tab was updated like this

Снимок.PNG

Next step: I tried to "make a project" and got error. It said me "sdk 33.0.1 is corrupted, please, reinstall" (i use 33.0.1 sdk). In that case you need to go to your androidSDK/build-tools and copy dx.bat and lib/dx.jar from 29.0.2 sdk (it will be downloaded during sync if missing) to the same locations for your sdk build tools (33.0.1 in my case). I found this solution here https://ngoclb.com/2022/11/android-build-failed-installed-build-tools-revision-33.0.1-is-corrupted..... but I did not replaced existing files, only added missing (to not break my 33.0.1 sdk tools)

After that I got error from cpp files like "this variable is declared, but not used"

I used solution provided by gerald.guyomard (thank you!)

- remove line in cflags.mk to have C++ code compile

LOCAL_CFLAGS    += -Werror       # error on warnings

After that on build project I got an error "keystore file not found for signing config 'debug'"

There are several solutions I found in Internet, I used next one:

Open git terminal and go to VrCubeWorld_Framework/Projects/Android

keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000
I filled needed fields in console and got debug.keystore file that should be renamed to android.debug.keystore
Adter that build -> make project was succeded. I didn't try yet to launch it on my oculus quest, will do it later

P.S.: don't change OculusSDK packaging and do not extract VrSamples as it uses "parent folder" to get needed files

P.P.S: I didn't try to make this project up-to-date to target sdk and other yet, that's just my guide how to build existing on

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
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).
4. Create the file (OculusSDKRoot)\local.properties with the next content (changing "Josea" with your user name).
 
sdk.dir=C\:\\Users\\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. In the toolbar the press the SDK Manager button (a 3D cube with a down arrow) or by selecting the menu option File/Setttings and select on the left side the option 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 and 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 is 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 (https://developer.android.com/build/releases/gradle-plugin#updating-gradle), 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 version 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.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 versions 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 inside (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... menu option and in the dialog box, check all the checkboxes and click OK to restart Android Studio.
 
And you're done!
 
EDIT: IF YOU WANT TO DEBUG YOUR APPLICATION you have to install the Android APK Support plugin, otherwise the breakpoints will not be hit and in Run/Edif configurations you will not see the "Debugger" tab.
 
1. Select the menu option File/Settings.
2. Select in the left panel Plugins.
3. Search Android APK Support.
4. Check the checkbox. It will ask to install the Android NDK plugin. Accept.
5. Press OK.
 
Now you can debug correctly.
 
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.

 

@joseangelmt You're a life saver! I followed your steps and it worked for me, saving me hours of frustration. Much appreciated!

But I still meet some errors when I deployed to Occulus Qurest 2, can you give some help?

Caused by: com.android.builder.errors.EvalIssueException: [CXX1405] error when building with ndkBuild using D:\Meta\Open XR\XrSamples\XrSpatialAnchor\Projects\Android\jni\Android.mk: Build command failed.error1.pngerror2.pngerror3.png

 

Hi joseangelmt:

I found the problem, because my folder has space, 

thank you very much!