Android Studio 3.2.1 - 无法将项目与 gradle 文件同步:@NotNull 参数 'message' 的参数 ... 不能为空

Android Studio 3.2.1 - Cannot sync project with gradle files: Argument for @NotNull parameter 'message' of ... must not be null

我在使用 AndroidStudio 时遇到问题。我刚把它安装在我的 Kubuntu 18.04 机器上,想创建我的第一个项目。 Everyhting 工作正常,项目打开。唯一的问题:我无法 运行 我的应用程序。我什至无法查看设计视图中的活动 - 它永远等待构建完成。当我想要 运行 应用程序时,它没有任何模块。

在网上搜索了一段时间后,我尝试将我的项目与 gradle 文件同步,因为这似乎解决了类似的问题,但一旦这样做,就会发生以下错误:

Argument for @NotNull parameter 'message' of com/android/tools/idea/gradle/project/sync/GradleSyncState.syncFailed must not be null
    java.lang.IllegalArgumentException: Argument for @NotNull parameter 'message' of com/android/tools/idea/gradle/project/sync/GradleSyncState.syncFailed must not be null
        at com.android.tools.idea.gradle.project.sync.GradleSyncState.$$$reportNull$$[=13=](GradleSyncState.java)
        at com.android.tools.idea.gradle.project.sync.GradleSyncState.syncFailed(GradleSyncState.java)
        at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.doPopulateProject(IdeaSyncPopulateProjectTask.java:135)
        at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.populate(IdeaSyncPopulateProjectTask.java:97)
        at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.access[=13=]0(IdeaSyncPopulateProjectTask.java:39)
        at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.run(IdeaSyncPopulateProjectTask.java:86)
        at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:750)
        at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess(CoreProgressManager.java:157)
        at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:580)
        at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:525)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:85)
        at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:144)
        at com.intellij.openapi.progress.impl.CoreProgressManager.run(CoreProgressManager.java:395)
        at com.intellij.openapi.application.impl.ApplicationImpl.run(ApplicationImpl.java:305)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

做了一次后,同步按钮被禁用了,我不能再做一次。我必须重新启动 IDE 才能做到这一点。

我查看了 idea.log 文件以更好地追踪问题,我在那里发现了以下内容:

2018-10-22 22:38:32,254 [d thread 3]   INFO - xecution.GradleExecutionHelper - Passing command-line args to Gradle Tooling API: -Didea.version=3.2 -Djava.awt.headless=true -Pandroid.injected.build.model.only=true -Pandroid.injected.build.model.only.advanced=true -Pandroid.injected.invoked.from.ide=true -Pandroid.injected.build.model.only.versioned=3 -Pandroid.injected.studio.version=3.2.1.0 -Pandroid.builder.sdkDownload=false --init-script /tmp/ijinit.gradle --offline 
2018-10-22 22:38:43,063 [d thread 3]   INFO - e.project.sync.GradleSyncState - Started setup of project 'TestApp'. 
2018-10-22 22:38:43,065 [e-1136-b06]   INFO - idea.project.IndexingSuspender - Consuming IndexingSuspender activation event: SETUP_STARTED 
2018-10-22 22:38:43,263 [e-1136-b06]   INFO - ule.android.SdkModuleSetupStep - Set Android SDK 'Android API 28 Platform (1)' (/home/myusername/Android/Sdk) to module 'app' 
2018-10-22 22:38:43,567 [d thread 3]   WARN - ea.IdeaSyncPopulateProjectTask - Sync failed: null 
java.lang.RuntimeException: java.lang.NullPointerException
    at com.intellij.openapi.application.impl.LaterInvocator.invokeAndWait(LaterInvocator.java:179)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:651)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:656)
    at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.executeOnEdt(ExternalSystemApiUtil.java:480)
    at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.executeProjectChangeAction(ExternalSystemApiUtil.java:469)
    at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManagerImpl.dispose(ProjectDataManagerImpl.java:442)
    at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManagerImpl.importData(ProjectDataManagerImpl.java:163)
    at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManagerImpl.importData(ProjectDataManagerImpl.java:221)
    at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManagerImpl.importData(ProjectDataManagerImpl.java:228)
    at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.doPopulateProject(IdeaSyncPopulateProjectTask.java:120)
    at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.populate(IdeaSyncPopulateProjectTask.java:97)
    at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.access[=14=]0(IdeaSyncPopulateProjectTask.java:39)
    at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.run(IdeaSyncPopulateProjectTask.java:86)
    at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:750)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess(CoreProgressManager.java:157)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:580)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:525)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:85)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:144)
    at com.intellij.openapi.progress.impl.CoreProgressManager.run(CoreProgressManager.java:395)
    at com.intellij.openapi.application.impl.ApplicationImpl.run(ApplicationImpl.java:305)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at com.intellij.openapi.extensions.Extensions.disposeArea(Extensions.java:171)
    at com.intellij.openapi.module.impl.ModuleImpl.dispose(ModuleImpl.java:146)
    at com.intellij.openapi.util.Disposer.execute(Disposer.java:48)
    at com.intellij.openapi.util.Disposer.execute(Disposer.java:44)
    at com.intellij.openapi.util.objectTree.ObjectTree.executeActionWithRecursiveGuard(ObjectTree.java:169)
    at com.intellij.openapi.util.objectTree.ObjectTree.executeUnregistered(ObjectTree.java:181)
    at com.intellij.openapi.util.objectTree.ObjectTree.executeAll(ObjectTree.java:140)
    at com.intellij.openapi.util.Disposer.dispose(Disposer.java:129)
    at com.intellij.openapi.util.Disposer.dispose(Disposer.java:125)
    at com.intellij.openapi.module.impl.ModuleManagerImpl$ModuleModelImpl.dispose(ModuleManagerImpl.java:895)
    at com.intellij.openapi.externalSystem.service.project.AbstractIdeModifiableModelsProvider.dispose(AbstractIdeModifiableModelsProvider.java:476)
    at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManagerImpl.execute(ProjectDataManagerImpl.java:445)
    at com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange.run(DisposeAwareProjectChange.java:36)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1010)
    at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.lambda$executeProjectChangeAction(ExternalSystemApiUtil.java:469)
    at com.intellij.openapi.application.TransactionGuardImpl.run(TransactionGuardImpl.java:315)
    at com.intellij.openapi.application.impl.LaterInvocator.run(LaterInvocator.java:156)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:447)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:431)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:415)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
    at java.awt.EventQueue.access0(EventQueue.java:98)
    at java.awt.EventQueue.run(EventQueue.java:715)
    at java.awt.EventQueue.run(EventQueue.java:709)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:822)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:763)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:423)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
2018-10-22 22:38:43,570 [e-1136-b06]  ERROR - intellij.openapi.progress.Task - Argument for @NotNull parameter 'message' of com/android/tools/idea/gradle/project/sync/GradleSyncState.syncFailed must not be null 
java.lang.IllegalArgumentException: Argument for @NotNull parameter 'message' of com/android/tools/idea/gradle/project/sync/GradleSyncState.syncFailed must not be null
    at com.android.tools.idea.gradle.project.sync.GradleSyncState.$$$reportNull$$[=14=](GradleSyncState.java)
    at com.android.tools.idea.gradle.project.sync.GradleSyncState.syncFailed(GradleSyncState.java)
    at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.doPopulateProject(IdeaSyncPopulateProjectTask.java:135)
    at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.populate(IdeaSyncPopulateProjectTask.java:97)
    at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.access[=14=]0(IdeaSyncPopulateProjectTask.java:39)
    at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.run(IdeaSyncPopulateProjectTask.java:86)
    at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:750)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess(CoreProgressManager.java:157)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:580)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:525)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:85)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:144)
    at com.intellij.openapi.progress.impl.CoreProgressManager.run(CoreProgressManager.java:395)
    at com.intellij.openapi.application.impl.ApplicationImpl.run(ApplicationImpl.java:305)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
2018-10-22 22:38:43,572 [e-1136-b06]  ERROR - intellij.openapi.progress.Task - Android Studio 3.2.1  Build #AI-181.5540.7.32.5056338 
2018-10-22 22:38:43,572 [e-1136-b06]  ERROR - intellij.openapi.progress.Task - JDK: 1.8.0_152-release 
2018-10-22 22:38:43,572 [e-1136-b06]  ERROR - intellij.openapi.progress.Task - VM: OpenJDK 64-Bit Server VM 
2018-10-22 22:38:43,572 [e-1136-b06]  ERROR - intellij.openapi.progress.Task - Vendor: JetBrains s.r.o 
2018-10-22 22:38:43,572 [e-1136-b06]  ERROR - intellij.openapi.progress.Task - OS: Linux 
2018-10-22 22:38:43,572 [e-1136-b06]  ERROR - intellij.openapi.progress.Task - Last Action: Android.SyncProject

该项目似乎无法同步到我的 gradle 文件。 运行ning 我的应用程序的实际问题可能是基于这个问题。有没有人以前遇到过这个问题或者可以告诉我如何解决这个问题来帮助我?

我是 AndroidStudio 的新手,也是 Gradle。

检查这个: Argument for @NotNull parameter 'module' of com/intellij/openapi/roots/ModuleRootManager.getInstance must not be null

顺便说一下,我通常会在更新 android studio 后删除项目文件夹中的 .idea.gradle 文件夹,更新后几乎可以解决所有新错误。

好吧,我终于明白原因了

问题是,我的项目文件夹与我的主文件夹位于不同的硬盘分区上。包含我的 android 项目的文件夹已通过 link 符号 link 编辑到我的主文件夹。

我无法判断是符号 link 还是其他分区导致了问题。我还没有检查过。如果您将它放在同一个分区上但使用符号 link 编辑 link,也许它会起作用。在没有符号 links 的另一个分区上使用时,它可能会起作用。但对于遇到此问题的任何人 -> 检查其中一个是否也是您的原因。

一些额外信息:我的 android 项目文件夹位于使用 ZFS 格式化的硬盘分区上。

我遇到了同样的问题。我将 ~/Android/Sdk 文件夹移动到另一个分区并放置了一个符号 link!!!

我的解决方案: 删除 .android , .AndroidStudio3.2 , .gradle 文件夹 再次启动 studio.sh 并让它像第一次一样进行初始化。然后转到文件->设置->系统设置->Android SDK 并将新位置指定为 Android SDK 文件夹作为绝对路径(不是符号 links)。

在此之后,它就像魅力一样。

遇到同样的问题,浪费了一天的时间重新安装所有东西,现在才弄明白。如果您为项目创建符号 link 并指定通过该符号 link 的路径,就会发生这种情况。只要指定项目路径,走很长的路就可以了。

我通过重命名项目文件夹然后重新打开 android studio 解决了问题,android studio 会告诉你找不到项目,然后从 [=12] 中删除项目=] 工作室当前打开列表。重命名项目文件夹并再次通过 android studio 打开它。

重命名项目文件夹并将重命名的文件夹添加为新项目后出现类似问题。

  • 通过臭名昭著的 "Invalidate Caches / Restart" 选项解决了这个问题

(在我删除旧项目 link 之前还不够)

我刚刚在 Android Studio 3.4 上看到了这个版本:我在 IDE 中看到的唯一错误消息是 Gradle 同步失败,但在 idea.log 有一个 NullPointerException 并且它的回溯起源于 com.intellij.openapi.extensions.Extensions.disposeArea 并且就像问题中的那个一样。

对我有用的修复:

  1. rm .idea/modules.xml

  2. 然后再次尝试 Gradle 同步。

这也导致该文件自动重新生成。新版本与旧版本具有完全相同的条目,外加一些用于各种库依赖项的额外条目。不确定这些条目的缺失是问题的原因,还是无关的事故。

在此之前,我尝试了 "Invalidate Caches / Restart...",但它对我的情况不起作用。另外 double-checked 并且在我的项目路径中没有符号链接,或者 Android Studio 或 Android SDK 的路径。

我在 Android Studio 3.4 中遇到了同样的问题。 我设法通过恢复我之前删除的 app-name.iml 文件来修复它。

我也遇到了同样的问题,通过关闭 android studio,删除项目文件夹中的 .idea 和 .gradle 文件,然后重新打开 android studio,简单地解决了这个问题。