没有消息的Gradle项目同步失败,在命令行上工作

时间:2018-02-04 13:58:47

标签: android android-gradle android-studio-3.1

在Android Studio中,同步失败:

  

Gradle项目同步失败。基本功能(例如编辑,调试)将无法正常工作。

命令行gradle installDebug有效。 "消息"中没有消息。视图。在idea.log中,出现了以下NullPointerException

2018-02-04 14:53:15,233 [ thread 15]   WARN - ea.IdeaSyncPopulateProjectTask - Sync failed: null 
java.lang.RuntimeException: java.lang.NullPointerException
    at com.intellij.openapi.application.impl.LaterInvocator.invokeAndWait(LaterInvocator.java:188)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:680)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:685)
    at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.executeOnEdt(ExternalSystemApiUtil.java:469)
    at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.executeProjectChangeAction(ExternalSystemApiUtil.java:458)
    at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager.dispose(ProjectDataManager.java:401)
    at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager.importData(ProjectDataManager.java:156)
    at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager.importData(ProjectDataManager.java:198)
    at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager.importData(ProjectDataManager.java:204)
    at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.doSelectiveImport(IdeaSyncPopulateProjectTask.java:206)
    at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.populate(IdeaSyncPopulateProjectTask.java:156)
    at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask.access$000(IdeaSyncPopulateProjectTask.java:51)
    at com.android.tools.idea.gradle.project.sync.idea.IdeaSyncPopulateProjectTask$1.run(IdeaSyncPopulateProjectTask.java:144)
    at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:726)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:176)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:556)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:501)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:66)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:163)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$1.run(ProgressManagerImpl.java:137)
    at com.intellij.openapi.application.impl.ApplicationImpl$2.run(ApplicationImpl.java:334)
    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:168)
    at com.intellij.openapi.module.impl.ModuleImpl.dispose(ModuleImpl.java:153)
    at com.intellij.openapi.util.Disposer$1.execute(Disposer.java:48)
    at com.intellij.openapi.util.Disposer$1.execute(Disposer.java:44)
    at com.intellij.openapi.util.objectTree.ObjectTree.executeActionWithRecursiveGuard(ObjectTree.java:151)
    at com.intellij.openapi.util.objectTree.ObjectTree.executeUnregistered(ObjectTree.java:163)
    at com.intellij.openapi.util.objectTree.ObjectTree.executeAll(ObjectTree.java:132)
    at com.intellij.openapi.util.Disposer.dispose(Disposer.java:123)
    at com.intellij.openapi.util.Disposer.dispose(Disposer.java:119)
    at com.intellij.openapi.module.impl.ModuleManagerImpl$ModuleModelImpl.dispose(ModuleManagerImpl.java:836)
    at com.intellij.openapi.externalSystem.service.project.AbstractIdeModifiableModelsProvider.dispose(AbstractIdeModifiableModelsProvider.java:421)
    at com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager$3.execute(ProjectDataManager.java:404)
    at com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange.run(DisposeAwareProjectChange.java:36)
    at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.lambda$null$6(ExternalSystemApiUtil.java:458)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1023)
    at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.lambda$executeProjectChangeAction$7(ExternalSystemApiUtil.java:458)
    at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:303)
    at com.intellij.openapi.application.impl.LaterInvocator$1.run(LaterInvocator.java:165)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:410)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:399)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
    at java.awt.EventQueue.access$500(EventQueue.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:715)
    at java.awt.EventQueue$3.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:827)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:655)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:365)
    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-02-04 14:53:15,234 [ thread 15]   INFO - e.project.sync.GradleSyncState - Gradle sync failed (4s 121ms) 

Using Invalidate Caches/Restart and removing the .gradle folder没有帮助。为什么是这样?它是如何修复的?

3 个答案:

答案 0 :(得分:3)

在设置>中取消设置本地gradle分发后构建,执行,部署> Gradle(设置用于调试此问题),Android Studio提供从gradle:3.0.1更新为gradle:3.0.0。这解决了它。

以前的步骤:

  • google()存储库添加到buildscriptallprojects
  • compileSdkVersiontargetSdkVersion升级为27
  • 将所有com.android.support库升级到26.1.0

答案 1 :(得分:1)

将Android Studio升级到3.1.3后,我遇到了类似的错误。我不记得我之前的确切版本 - 版本2系列。

我收到这些错误的原因是因为我使用的Gradle插件版本太低了。

buildscript {
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    ...
}

将版本从2.2.3更新为2.3.3后,Android Studio就可以继续使用,并为我提供更有意义的错误消息,例如

  

Gradle sync失败:支持的最低Gradle版本为3.3。当前版本是2.14.1。如果使用gradle包装器,请尝试将gradle / wrapper / gradle-wrapper.properties中的distributionUrl编辑为gradle-3.3-all.zip

从那里开始,只需要解决版本兼容性问题。

答案 2 :(得分:1)

对我来说,这是一个简单的解决方案:我已经从项目中删除了一个模块,却忘记了从settings.gradle删除它

也许这可以帮助某人