无法构建 Oculus OpenXR Mobile SDK 和 Oculus Mobile SDK 中的任何项目。

huangapple go评论80阅读模式
英文:

Unable to build any of the projects of Oculus OpenXR Mobile SDK and Oculus Mobile SDK

问题

The Oculus OpenXR Mobile SDK and Oculus Mobile SDK sample projects are configured in such a way that modern versions of Android Studio (like for example Android Studio Flamingo) are not able to load correctly.

The documentation in https://developer.oculus.com/documentation/native/android/mobile-studio-setup-android/ is outdated and does not help much in the process.

英文:

The Oculus OpenXR Mobile SDK and Oculus Mobile SDK sample projects are configured in such a way that modern versions of Android Studio (like for example Android Studio Flamingo) are not able to load correctly.

The documentation in https://developer.oculus.com/documentation/native/android/mobile-studio-setup-android/ is outdated and does not help much in the process.

答案1

得分: 2

以下是您要求的中文翻译部分:

我已经花了2天的时间来使SDK项目正常工作,这篇帖子是为了帮助你节省这两天的时间。
事实是,与Android Studio构建系统相关的一切都非常令人沮丧,因为你必须单独配置许多组件,这些组件通常不兼容,而且很多时候Android Studio会使用缓存信息,你必须告诉它清除缓存以便使用你所做的更改等等。
此外,SDK项目的构建方式使得Android Studio无法正确管理它们,会出现问题:

  1. 在选择“文件/项目结构”时,“Android Gradle插件版本”和“Gradle版本”字段总是为空,即使你输入一些值也是无效的:文件不会被修改,如果你再次打开对话框,它们还是空的。
  2. 如果它检测到有新版本的“Gradle插件”,向导无法定位活动版本(尽管奇怪的是它已经检测到有新版本,所以理论上它知道你使用的版本)。
  3. Android Studio无法找到文件“gradle-wrapper.properties”。在“文件/设置/构建、执行、部署/Gradle”中,如果你选择从“gradle-wrapper.properties”文件中使用Gradle,它会显示一个错误,指示找不到文件“gradle-wrapper.properties”。

本教程是为了在Android Studio Flamingo | 2022.2.1 Patch 2中编译项目,这是截止到今天(2023年5月5日)的最新版本,并且我们还将更新Gradle插件到版本7.0.2(因为我无法使其在7.4.2中工作)。

我在Windows上运行了所有操作,事实上,我懒得在Mac或Linux上尝试一切,所以我希望即使你的操作系统不是Windows,至少这些步骤也会对你有所帮助。我将在一个干净的Windows虚拟机上执行所有步骤,这台机器从未安装过Android Studio、Java或其他任何东西,而且我将在不创建任何环境变量的情况下执行所有操作。

  1. 下载并安装Android Studio。
  2. 下载带有SDK的zip文件,我下载了ovr_openxr_mobile_sdk_53.0.zip。解压它。
  3. 使用Android Studio打开任何一个项目,我打开了(OculusSDKRoot)XrSamples\XrSpatialAnchor\Projects\Android文件夹。

Android Studio将开始下载和执行库文件,过一会儿,它将显示如下错误:

无法构建 Oculus OpenXR Mobile SDK 和 Oculus Mobile SDK 中的任何项目。

正如你所看到的,它告诉我们要么在环境变量中添加SDK的路径,要么在(OculusSDKRoot)\local.properties文件中添加(这个文件在SDK中不存在)。
4. 创建文件(OculusSDKRoot)\local.properties,内容如下(将"Josea"替换为你的用户名)。

sdk.dir=C\:\\Users\\Josea\\AppData\\Local\\Android\\Sdk
  1. 单击“同步项目与Gradle文件”按钮,或选择“文件/同步项目与Gradle文件”菜单选项。现在将显示以下错误消息:

无法构建 Oculus OpenXR Mobile SDK 和 Oculus Mobile SDK 中的任何项目。

指示我们必须安装一个兼容的NDK,他们指出默认版本是21.0.6613669。
6. 在工具栏中,点击“SDK管理器”按钮(一个带有向下箭头的3D立方体),或者选择菜单选项“文件/设置”,然后在左侧选择“外观和行为/系统设置/Android SDK”选项。
7. 在“SDK平台”选项卡中选择“Android 8.0(奥利奥)”,因为这是Android版本,API级别为26,这是SDK项目配置的版本号。
8. 在“SDK工具”选项卡中点击“显示包详情”复选框,以显示不同版本的组件,然后打开“NDK(Side by side)”,选择版本21.0.6613669,并接受。

  1. 单击“同步项目与Gradle文件”按钮,或选择“文件/同步项目与Gradle文件”菜单选项。现在将显示以下错误消息:

无法构建 Oculus OpenXR Mobile SDK 和 Oculus Mobile SDK 中的任何项目。

  1. 这个错误是因为Android Studio默认使用的JDK版本与项目配置的Gradle插件版本和Gradle版本不兼容。
  2. 打开(OculusSDKRoot)build.gradle文件。在那里,你可以找到以下行:
classpath 'com.android.tools.build:gradle:4.0.0'.

4.0.0.0是程序配置的Graddle插件版本。这个插件必须与某个版本的Gradle一起运行,而这个Gradle版本必须与某个版本的Java一起运行。

如果你转到https://developer.android.com/build/releases/gradle-plugin#updating-gradle并点击“旧版本”按钮,你会看到插件版本4.0.0.0需要Gradle 6.1.1的版本,而这个Gradle版本我们必须找出它对应的Java版本。

因为这是一个非常过时的版本,我们要更新所有东西,所以修改文件(OculusSDKRoot)build.gradle,并将那一行改为版本7.0.2。如果你查看那个表(https://developer.android.com/build/releases/gradle-plugin#updating-gradle),插件版本7.0所需的Gradle版本是7.0。现在我们只需要知道Gradle 7.0必须运行在哪个Java版本上。如果你转到https://developer.android.com/build/releases/gradle-plugin#updating-gradle,你可以查看它是版本16。

  1. 修改文件(OculusSDKRoot)build.gradle,并将Gradle插件
英文:

I have spent 2 days 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, 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 and I'll do everything without creating any environment variable.
     
  4. Download and install Android Studio.
  5. Download the zip with the SDK, I downloaded ovr_openxr_mobile_sdk_53.0.zip. Unzip it.
  6. 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:

无法构建 Oculus OpenXR Mobile SDK 和 Oculus Mobile SDK 中的任何项目。

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
  1. 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: 

无法构建 Oculus OpenXR Mobile SDK 和 Oculus Mobile SDK 中的任何项目。

Indicating that we must install a compatible NDK, and they indicate that the default version would be 21.0.6613669.
 
6. In the toolbar, press the SDK Manager button (a 3D cube with a down arrow) or by selecting the menu option File/Setttings and selecting 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.

  1. 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: 
    无法构建 Oculus OpenXR Mobile SDK 和 Oculus Mobile SDK 中的任何项目。

  2. 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.

  3. 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"
  1. Do the same with the file (OculusSDKRoot)VrApp.gradle
  2. 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
  1. 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...
  2. 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

无法构建 Oculus OpenXR Mobile SDK 和 Oculus Mobile SDK 中的任何项目。
 
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

  1. 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....
  2. 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.
  3. 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!
 
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.

huangapple
  • 本文由 发表于 2023年6月5日 23:33:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76407950.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定