Gradle 0.9.+/0.9.2 错误:无法加载类“com.android.builder.testing.api.DeviceProvider”
Posted
技术标签:
【中文标题】Gradle 0.9.+/0.9.2 错误:无法加载类“com.android.builder.testing.api.DeviceProvider”【英文标题】:Gradle 0.9.+/0.9.2 error: Unable to load class 'com.android.builder.testing.api.DeviceProvider' 【发布时间】:2014-05-05 09:50:22 【问题描述】:今天早上,所有 Android Studio 项目都开始失败 Gradle sync/build/clean:
> Could not create plugin of type 'AppPlugin'.
堆栈跟踪看起来像:
* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':Project'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:177)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:38)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:25)
at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:507)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:82)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:31)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:45)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:42)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:60)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:45)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator.runCommand(DaemonStateCoordinator.java:186)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.doBuild(StartBuildOrRespondWithBusy.java:49)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.java:36)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.java:32)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.java:51)
at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.handleCommand(DefaultIncomingConnectionHandler.java:155)
at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.receiveAndHandleCommand(DefaultIncomingConnectionHandler.java:128)
at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.run(DefaultIncomingConnectionHandler.java:116)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
Caused by: org.gradle.api.plugins.PluginInstantiationException: Could not create plugin of type 'AppPlugin'.
at org.gradle.api.internal.plugins.DefaultPluginRegistry.loadPlugin(DefaultPluginRegistry.java:69)
at org.gradle.api.internal.plugins.DefaultPluginContainer.providePlugin(DefaultPluginContainer.java:103)
at org.gradle.api.internal.plugins.DefaultPluginContainer.addPluginInternal(DefaultPluginContainer.java:68)
at org.gradle.api.internal.plugins.DefaultPluginContainer.apply(DefaultPluginContainer.java:34)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:101)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:32)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:72)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:114)
at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:39)
at org.gradle.api.Project$apply.call(Unknown Source)
at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.groovy:34)
at org.gradle.api.Script$apply.callCurrent(Unknown Source)
at build_5mm5fv0emagtc49feqskf025g1.run(/projectdir/build.gradle:9)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
... 53 more
Caused by: java.lang.NoClassDefFoundError: com/android/builder/testing/api/DeviceProvider
at com.android.build.gradle.AppPlugin.$getStaticMetaClass(AppPlugin.groovy)
at com.android.build.gradle.BasePlugin.<init>(BasePlugin.groovy:1908)
at com.android.build.gradle.AppPlugin.<init>(AppPlugin.groovy:37)
at org.gradle.api.internal.DependencyInjectingInstantiator.newInstance(DependencyInjectingInstantiator.java:62)
at org.gradle.api.internal.plugins.DefaultPluginRegistry.loadPlugin(DefaultPluginRegistry.java:67)
... 66 more
Caused by: java.lang.ClassNotFoundException: com.android.builder.testing.api.DeviceProvider
... 71 more
有一个bug report 有相当多的活动,但还没有解决方案。
这是 Android Studio 0.5.2,gradle 版本 1.11/0.9.2。
想法?
【问题讨论】:
我遇到了同样的错误:/我提交了我的问题 u.u 你确实需要编辑标题以指定 1.11,否则这会让你听起来像一个“企业”老兄,在抱怨史前版本不工作。 【参考方案1】:根据错误报告中的最新消息,问题是 0.9.2 版正在从 Maven 中心提供,即使所有必要的组件都不可用(并且 gradle 不会将其注册为问题)。这会破坏事情,因为缺少碎片。 0.9.2 版现在完全可用并且可以正常工作,但如果您看到此错误,则说明您的 gradle 缓存已损坏。
修复:
gradle --refresh-dependencies
或删除
~/.gradle/caches
然后重新同步。
之前的修复,更新见上文。
根据the bug report中的cmets,看来version 0.9.2是这个问题的根源。
要修复,将 gradle 版本固定到已知良好的版本 0.9.1
而不是 0.9.+
、0.+
、+
等。
在您的 build.gradle
文件中,更改
classpath 'com.android.tools.build:gradle:0.9.+'
到
classpath 'com.android.tools.build:gradle:0.9.1'
【讨论】:
我会推荐 0.9.1;它有重要的错误修正。 0.9.2 似乎是糟糕的版本。 @ChristopherFranciscobuild.gradle
在解决这个问题将近 2 小时后,删除缓存目录 (~/.gradle/caches) 并将类路径更改为 'com.android.tools.build:gradle:0.9.1' (而不是'0.9.+') 对我有用。非常感谢@blahdiblah
@JasonHartley 缓存位于您的主目录 .gradle 文件夹中,而不是项目 .gradle 文件夹中。是这个问题吗?
./gradlew --refresh-dependencies
成功了!再次感谢@blahdiblah。【参考方案2】:
为了使用最新的 Gradle 版本 0.9.+,您还必须更新 gradlewrapper.properties
文件。
打开位于youProjectPath/gradle/wrapper/gradlewrapper.properties
路径下的gradlewrapper.properties
文件:
更改distributionUrl
网址来源
distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
到
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
之后,我把 build.gradle 依赖改成了
classpath 'com.android.tools.build:gradle:0.9.+'
并在良好时同步 gradle 文件和所有内容。
干杯
【讨论】:
以上是关于Gradle 0.9.+/0.9.2 错误:无法加载类“com.android.builder.testing.api.DeviceProvider”的主要内容,如果未能解决你的问题,请参考以下文章
从 0.9.2 更新到 0.9.5 后出现错误“java.lang.IllegalArgumentException: Illegal group reference”