无法转换为com.android.tools.idea.gradle.invoker.GradleInvoker

时间:2017-01-23 12:58:27

标签: java android intellij-idea intellij-plugin

我正在尝试使用IntelliJ SDK api构建一个android studio插件,并获得以下异常,并且无法找到其解决方案的任何线索:

java.lang.ClassCastException: com.android.tools.idea.gradle.invoker.GradleInvoker cannot be cast to com.android.tools.idea.gradle.invoker.GradleInvoker
    at com.android.tools.idea.gradle.invoker.GradleInvoker.getInstance(GradleInvoker.java:83)
    at com.accenture.codecoverage.plugin.android.action.UpdateReportOnSonar$1$1.run(UpdateReportOnSonar.java:91)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:149)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:109)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:99)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:85)
    at com.accenture.codecoverage.plugin.android.action.UpdateReportOnSonar$1.run(UpdateReportOnSonar.java:56)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:934)
    at com.accenture.codecoverage.plugin.android.action.UpdateReportOnSonar.actionPerformed(UpdateReportOnSonar.java:46)
    at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:199)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:215)
    at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.lambda$actionPerformed$2(ActionMenuItem.java:315)
    at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:920)
    at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:130)
    at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:295)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$fireActionPerformed$0(ActionMenuItem.java:112)
    at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:91)
    at com.intellij.openapi.application.TransactionGuardImpl.access$300(TransactionGuardImpl.java:41)
    at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:116)
    at com.intellij.openapi.application.TransactionGuardImpl.submitTransaction(TransactionGuardImpl.java:126)
    at com.intellij.openapi.application.TransactionGuard.submitTransaction(TransactionGuard.java:122)
    at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:112)
    at com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:513)
    at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:45)
    at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:533)
    at java.awt.Component.processMouseEvent(Component.java:6533)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6298)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    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:80)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:843)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:675)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:391)
    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)

调用以下代码行时出现上述错误:

GradleInvoker.getInstance(mProject).executeTasks(gradleReportTasks);

任何人都可以就此问题提出建议吗?

谢谢, Sumeet。

1 个答案:

答案 0 :(得分:0)

我已经下载了最新版本的Android Studio(V2.3),然后检查最新的android.jar文件是否存在于Studio内容包中,并对API“com.android.tools.idea.gradle.invoker”感到惊讶.GradleInvoker“从最新的jar文件中删除了,这意味着这个API已被弃用到早期版本中,我们并没有意识到这一点,这就是为什么我们得到了奇怪的错误,正如我在这个问题中提到的那样。

你需要改变你的逻辑,并使用另一个API代替GradleInvoker类来实现你的结果,但在此之前请保持你的android studio最新版本V2.3

我希望它能帮到你......

谢谢, Sumeet。