当前位置: 首页 > 知识库问答 >
问题:

Gradle在Android Studio中构建项目时给出了NullPointerException

呼延晋
2023-03-14

请有人帮我修复这个在我的Android Studio(2.2)崩溃后出现的错误。我是个新手,所以我不知道该怎么处理。

我试过:

  • 清理项目

我不知道还有什么可以解决这个问题。

这是gradle控制台中带有--stacktrac--debug的错误:

08:33:16.858 [ERROR] [org.gradle.BuildExceptionReporter] 
08:33:16.858 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
08:33:16.858 [ERROR] [org.gradle.BuildExceptionReporter] 
08:33:16.858 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
08:33:16.858 [ERROR] [org.gradle.BuildExceptionReporter] java.lang.NullPointerException (no error message)
08:33:16.858 [ERROR] [org.gradle.BuildExceptionReporter] 
08:33:16.858 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
08:33:16.858 [ERROR] [org.gradle.BuildExceptionReporter] java.lang.NullPointerException
08:33:16.858 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.changedetection.state.TreeSnapshotRepository.removeTreeSnapshotUsage(TreeSnapshotRepository.java:85)
08:33:16.858 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.changedetection.state.CacheBackedFileSnapshotRepository.remove(CacheBackedFileSnapshotRepository.java:47)
08:33:16.858 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository$1$1.run(CacheBackedTaskHistoryRepository.java:84)
08:33:16.858 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.Factories$1.create(Factories.java:22)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:192)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:175)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:106)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.useCache(DefaultCacheFactory.java:187)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:60)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository$1.update(CacheBackedTaskHistoryRepository.java:66)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.afterTask(DefaultTaskArtifactStateRepository.java:135)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:68)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
08:33:16.859 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:153)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.Factories$1.create(Factories.java:22)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:53)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:150)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32)
08:33:16.860 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:98)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:92)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:63)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:92)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:83)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:99)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:46)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.tooling.internal.provider.runner.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:58)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:48)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:30)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:81)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:46)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:52)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
08:33:16.861 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
08:33:16.862 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
08:33:16.862 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
08:33:16.862 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
08:33:16.862 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
08:33:16.862 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
08:33:16.862 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
08:33:16.862 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.util.Swapper.swap(Swapper.java:38)
08:33:16.862 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
08:33:16.863 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
08:33:16.863 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:47)
08:33:16.863 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
08:33:16.863 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
08:33:16.863 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
08:33:16.863 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
08:33:16.864 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
08:33:16.864 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
08:33:16.864 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
08:33:16.864 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41)
08:33:16.864 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
08:33:16.864 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
08:33:16.864 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:237)
08:33:16.864 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
08:33:16.864 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
08:33:16.864 [ERROR] [org.gradle.BuildExceptionReporter] 

提前感谢。

共有2个答案

刘胜泫
2023-03-14

确保如果你有local.properties,sdk.dir和ndk.dir(如果定义)的路径确实存在。在我的例子中,我的项目没有使用ndk,但是我的local.properties是从一个项目中复制的,并且ndk目录无效。我认为这并不重要,但是我下载并提取了ndk到local.properties的路径中,现在它可以工作了。我想我可以很容易地注释/删除local.properties中的行,但是那不会那么有趣...:)

莫欣悦
2023-03-14

我在Android Studio/SDK端尝试的任何东西都不起作用。

所以我不得不走人工路线。一、

  • 转到AndroidStudioProjects目录并手动更改名称(只是在目录名称的末尾添加了“-backup”)
  • 在Android Studio中使用原始项目名称和包名创建了一个新项目,然后关闭了Android Studio
  • 返回到AndroidStudioProjects目录,并复制了备份中的依赖项部分。将文件升级到新项目中的同一文件
  • 将目录从旧项目复制到新项目
  • 打开Android Studio并选择构建

现在开始修复VCS…-!

 类似资料:
  • 我有一个简单的gradle项目,我想建立在Docker容器内 我有一个多级码头建设。第一阶段只是从github克隆项目。第二阶段必须建立项目,所以我可以在最后阶段运行它。但是它失败了 命令<代码>。/gradlew build - stacktrace无法执行并失败,错误为: 和stacktraces: 为什么docker用户没有在工作目录下创建文件的权限,如何添加这些权限?简单的< code >

  • 主要内容:多项目构建的结构,指定常规构建配置,项目指定配置和依赖关系,Gradle多项目构建的示例,子项目配置,参考可以轻松处理各种大小规模的项目。小项目由一个单一的构建文件和一个源代码树构成。 大项目可以将其拆分成更小的,相互依赖的模块,以便更容易理解。Gradle完美支持这种多项目构建的场景。 多项目构建的结构 这种构建有各种形状和大小,但它们都有一些共同的特点 - 在项目的根目录或主目录中都有一个文件。 根目录或主目录都有一个文件。 具有自己的构建文件的子目录(某些多项目构建可能会省略子项

  • 主要内容:Groovy插件,Groovy项目的默认项目布局本章介绍如何使用文件编译和执行Groovy项目。 Groovy插件 Gradle的Groovy插件扩展了Java插件,并为Groovy程序提供了任务。可以使用以下行来应用groovy插件。 完整的构建脚本文件如下。将以下代码复制到文件中。 可以使用以下命令来执行构建脚本。 Groovy项目的默认项目布局 Groovy插件假定Groovy项目有手动做过一定的设置。 包含Groovy源代码; 包含Gr

  • 主要内容:Java默认的项目布局,初始化任务执行,指定Java版本本章介绍如何使用Gradle构建文件来构建一个Java项目。 首先,我们必须向构建脚本中添加Java插件,因为它提供了编译Java源代码,运行单元测试,创建Javadoc和创建JAR文件的任务。 在文件中使用以下代码行。 怎么样,是不是很简单? Java默认的项目布局 每当添加一个插件到构建中,它会假设一个特定的Java项目设置(类似于Maven)。看看下面的目录结构。 目录包含Java源代码;

  • 找不到符号symbol:类JSONObject java文件中存在jsonobject和json数组的所有地方都有红色标记。 我已经将包含所有jar文件的文件夹web inf/lib放在我创建的src/main/webapp目录中。

  • 新安装的android工作室,并开始新的Android项目。当试图运行它时。从Gradle那里得到这个错误 我尝试过重建项目,也尝试过删除文件夹,但没有任何效果。