[Android--Tool]Gradle sync started: NullPointerException: null

简述

用Android Studio打开一个工程后,从Event log看到Gradle sync started: 但是似乎一直sync失败,一直打出NullPointerException: null。当然工程也就无法调试。

详细log

null
java.lang.NullPointerException
    at com.intellij.openapi.util.io.FileUtilRt.toSystemIndependentName(FileUtilRt.java:207)
    at com.intellij.openapi.util.io.FileUtil.toSystemIndependentName(FileUtil.java:634)
    at org.jetbrains.android.sdk.AndroidSdkUtils.getPlatformDir(AndroidSdkUtils.java:218)
    at org.jetbrains.android.sdk.AndroidSdkUtils.getPlatformAndAddOnJars(AndroidSdkUtils.java:122)
    at org.jetbrains.android.sdk.AndroidSdkUtils.getLibraryRootsForTarget(AndroidSdkUtils.java:156)
    at com.android.tools.idea.gradle.project.PostProjectSetupTasksExecutor.ensureValidSdks(PostProjectSetupTasksExecutor.java:434)
    at com.android.tools.idea.gradle.project.PostProjectSetupTasksExecutor.access$200(PostProjectSetupTasksExecutor.java:108)
    at com.android.tools.idea.gradle.project.PostProjectSetupTasksExecutor$1.run(PostProjectSetupTasksExecutor.java:171)
    at com.intellij.openapi.roots.impl.ProjectRootManagerImpl.mergeRootsChangesDuring(ProjectRootManagerImpl.java:328)
    at com.android.tools.idea.gradle.util.Projects$2$1.run(Projects.java:157)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:931)
    at com.android.tools.idea.gradle.util.Projects$2.run(Projects.java:153)
    at com.intellij.util.ui.UIUtil.invokeAndWaitIfNeeded(UIUtil.java:2369)
    at com.android.tools.idea.gradle.util.Projects.executeProjectChanges(Projects.java:150)
    at com.android.tools.idea.gradle.project.PostProjectSetupTasksExecutor.onProjectSyncCompletion(PostProjectSetupTasksExecutor.java:166)
    at com.android.tools.idea.gradle.util.Projects$1.run(Projects.java:138)
    at com.intellij.util.ui.UIUtil.invokeAndWaitIfNeeded(UIUtil.java:2369)
    at com.android.tools.idea.gradle.util.Projects.populate(Projects.java:115)
    at com.android.tools.idea.gradle.project.ProjectSetUpTask$2.run(ProjectSetUpTask.java:113)
    at com.intellij.ide.startup.impl.StartupManagerImpl$7.run(StartupManagerImpl.java:369)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:734)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:569)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:382)
    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)

提示一个IDE内部错误。

解决

重新打开一个AS工程,Gradle sync OK。
再看原来的工程,代码中一些类都无法解析了,Build tool配置不对?因为更新了SDK一些东西就发生了这个问题。重新建了一个Project就好了。
也有提到可能因为gradle版本不对引起,需要将build.gradle中classpatch修改为1.5.0。不过我这里的问题不是这个引起。

你可能感兴趣的:(android,gradle,sync,fail)