You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio中gradlew build报错:Sceneform依赖无法解析

解决Sceneform依赖类找不到的编译错误

问题核心

执行./gradlew build构建Android项目时,无法解析com.gorisse.thomas.sceneform相关类(如ArFragment、ModelRenderable、TransformableNode),编译报cannot find symbol错误。

解决方案

1. 修正导入包名

Thomas维护的Sceneform分支包结构与旧版官方Sceneform存在差异,需修正导入路径:

// 修正后的正确导入语句
import com.gorisse.thomas.sceneform.ar.ArFragment;
import com.gorisse.thomas.sceneform.rendering.ModelRenderable;
import com.gorisse.thomas.sceneform.ux.TransformableNode;

2. 配置完整依赖

在app模块的build.gradle(或build.gradle.kts)中添加完整的Sceneform依赖项:

// AR核心功能(包含ArFragment、ModelRenderable等核心类)
implementation 'com.gorisse.thomas.sceneform:sceneform-ar:1.21.0'
// UX交互组件(包含TransformableNode)
implementation 'com.gorisse.thomas.sceneform:sceneform-ux:1.21.0'
// 资产加载工具(可选,用于3D模型资源加载)
implementation 'com.gorisse.thomas.sceneform:sceneform-assets:1.21.0'

3. 确认仓库配置

在项目级settings.gradle(或settings.gradle.kts)的依赖管理中,确保添加MavenCentral仓库(Thomas的Sceneform发布在此):

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral() // 必须添加此仓库
    }
}

4. 彻底清理缓存

执行以下命令清除Gradle缓存,避免依赖解析异常:

./gradlew clean cleanBuildCache

同时在Android Studio中执行File -> Invalidate Caches... -> Invalidate and Restart,清除IDE本地缓存。

5. 检查版本兼容性

Sceneform 1.21.0要求:

  • Android Gradle Plugin(AGP)版本 ≥ 7.0.0
  • Gradle版本 ≥ 7.0.0
    确保项目级build.gradle中AGP版本符合要求:
plugins {
    id 'com.android.application' version '7.4.2' apply false
    // 其他插件配置...
}

验证执行

完成上述步骤后,重新执行构建命令:

./gradlew build

内容的提问来源于stack exchange,提问作者Anandhanarayan K

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 11:01:19