Android构建系统gradle
Posted
技术标签:
【中文标题】Android构建系统gradle【英文标题】:Android build system gradle 【发布时间】:2012-11-27 21:49:46 【问题描述】:我正在测试仍处于测试阶段的 androids 新构建系统。 我已经实现了一些产生以下错误的代码:
No such property: resolutionResult for class: org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver$ErrorHandlingResolvedConfiguration
build.gradle
buildscript
repositories
mavenCentral()
dependencies
classpath 'com.android.tools.build:gradle:0.2'
apply plugin: 'android'
android
sourceSets
main
manifest
srcFile 'AndroidManifest.xml'
java
srcDir 'src'
res
srcDir 'res'
assets
srcDir 'assets'
resources
srcDir 'src'
我也尝试过样品,但会引发同样的错误。怎么了?
Gradle 版本
------------------------------------------------------------
Gradle 1.3
------------------------------------------------------------
Gradle build time: Dienstag, 20. November 2012 11:37 Uhr UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.6.0_25 (Sun Microsystems Inc. 20.0-b11)
OS: Windows 7 6.1 amd64
完整的 Gradle 堆栈跟踪
org.gradle.listener.ListenerNotificationException: Failed to notify project evaluation listener.
at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:97)
at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at $Proxy9.afterEvaluate(Unknown Source)
at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:47)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:463)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:75)
at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:23)
at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:21)
at org.gradle.api.internal.Actions$CompositeAction.execute(Actions.java:67)
at org.gradle.api.internal.Actions$TransformingActionAdapter.execute(Actions.java:96)
at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:439)
at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:434)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:32)
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.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:38)
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:39)
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:25)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:137)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:48)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.Main.main(Main.java:39)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
Caused by: groovy.lang.MissingPropertyException: No such property: resolutionResult for class: org.gradle.api.internal.artifacts.ivyservice.ErrorHandingArtifactDependencyResolver$ErrorHandlingResolvedConfiguration
at com.android.build.gradle.BasePlugin.resolveDependencyForConfig(BasePlugin.groovy:641)
at com.android.build.gradle.BasePlugin$resolveDependencyForConfig.callCurrent(Unknown Source)
at com.android.build.gradle.BasePlugin.resolveDependencies(BasePlugin.groovy:584)
at com.android.build.gradle.BasePlugin$resolveDependencies.callCurrent(Unknown Source)
at com.android.build.gradle.AppPlugin.createAndroidTasks(AppPlugin.groovy:116)
at com.android.build.gradle.AppPlugin.this$3$createAndroidTasks(AppPlugin.groovy)
at com.android.build.gradle.AppPlugin$_apply_closure5.doCall(AppPlugin.groovy:73)
at org.gradle.listener.BroadcastDispatch$ClosureInvocationHandler.dispatch(BroadcastDispatch.java:116)
at org.gradle.listener.BroadcastDispatch$ClosureInvocationHandler.dispatch(BroadcastDispatch.java:101)
at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:88)
... 33 more
我已尝试降级到 Gradle 1.2。现在我又遇到了一个例外。
------------------------------------------------------------
Gradle 1.2
------------------------------------------------------------
Gradle build time: Mittwoch, 12. September 2012 10:46 Uhr UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.6.0_25 (Sun Microsystems Inc. 20.0-b11)
OS: Windows 7 6.1 amd64
降级到 Gradle 1.2 后的 Stacktrace
:prepareReleaseDependencies
:compileReleaseAidl FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileReleaseAidl'.
> target cannot be null.
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileReleaseAidl'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:68)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:34)
at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter$1.run(CacheLockHandlingTaskExecuter.java:34)
at org.gradle.cache.internal.DefaultCacheAccess$3.create(DefaultCacheAccess.java:243)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:188)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:241)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:137)
at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter.execute(CacheLockHandlingTaskExecuter.java:32)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:55)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:247)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.executeTask(DefaultTaskPlanExecutor.java:52)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.processTask(DefaultTaskPlanExecutor.java:38)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:30)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:83)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
at org.gradle.cache.internal.DefaultCacheAccess$2.create(DefaultCacheAccess.java:118)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:133)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:116)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:129)
at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExecuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:158)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:38)
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:39)
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:25)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:30)
at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:22)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:200)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:173)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:138)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:48)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.Main.main(Main.java:39)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
Caused by: java.lang.NullPointerException: target cannot be null.
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:208)
at com.android.builder.AndroidBuilder.setTarget(AndroidBuilder.java:131)
at com.android.builder.AndroidBuilder$setTarget.call(Unknown Source)
at com.android.build.gradle.internal.ProductionAppVariant.createBuilder(ProductionAppVariant.groovy:90)
at com.android.build.gradle.internal.ProductionAppVariant$createBuilder.call(Unknown Source)
at com.android.build.gradle.BasePlugin.getAndroidBuilder(BasePlugin.groovy:133)
at com.android.build.gradle.BasePlugin$getAndroidBuilder.call(Unknown Source)
at com.android.build.gradle.BaseTask.getBuilder(BaseTask.groovy:33)
at com.android.build.gradle.CompileAidlTask_Decorated.getBuilder(Unknown Source)
at com.android.build.gradle.CompileAidlTask_Decorated$getBuilder.callCurrent(Unknown Source)
at com.android.build.gradle.CompileAidlTask.generate(CompileAidlTask.groovy:39)
at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:216)
at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:122)
at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
at com.android.build.gradle.CompileAidlTask_Decorated.invokeMethod(Unknown Source)
at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$4.execute(AnnotationProcessingTaskFactory.java:161)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$4.execute(AnnotationProcessingTaskFactory.java:156)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:472)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:461)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:60)
... 58 more
【问题讨论】:
你能发布完整的堆栈跟踪吗?我的预感是您正在针对错误版本的 Gradle 运行它(可能是早期版本或预览版本?)这是配置解析期间引发的内部错误,因此 Android 插件可能正在尝试访问不存在的 Gradle 属性在您安装的 Gradle 中。gradle -v
说什么?
在答案中添加了完整的堆栈跟踪和 gradle 版本。
Android 插件是为 Gradle 1.2 构建的。尝试降级您的 Gradle 安装,看看是否有帮助。
我更进一步,但是在构建应用程序时会引发另一个异常。在编辑后的帖子中查看更多内容
您必须将target
属性设置为您的应用所针对的平台版本。你关注tools.android.com/tech-docs/new-build-system/…了吗?
【参考方案1】:
0.2 版是使用 Gradle 1.2 开发的(1.3 尚未发布)。我们知道我们现在正在使用一些内部的东西,所以它可能在 1.3 上被破坏了(还没有测试,很快就会测试)。
目前,请使用 Gradle 1.2
【讨论】:
快速更新,我们修复了这个问题,因此下一次更新将可用于 1.3(实际上,它需要 1.3,我们已进行检查以确保使用正确的版本)。 Gradle 1.4 已经发布了。我希望 Gradle 插件不会在每个新的 gradle 版本中都被破坏。 Maven 现在更稳定了。 这真的是我们的错。我们正在使用孵化功能。下一个版本将在 1.3/1.4 上运行(我们都在测试) 看起来像 .3,支持 1.3/1.4 在 AOSP 工具结帐中可用(稳定性未知)。请参阅tools.android.com/tech-docs/new-build-system 上的“贡献” 0.3 仍在开发中,需要一个尚未发布的平台版本。【参考方案2】:您需要将compliedSdkVersion 17
添加到您的 gradle.build 文件中:
编辑:我刚刚创建的参考项目。建筑、标志等https://github.com/yegdroid/gradle_demo
// // 一个遵循所有约定的基本 Android 应用程序 // 构建脚本 存储库 mavenCentral() 依赖 类路径'com.android.tools.build:gradle:0.3' 应用插件:'android' 安卓 testBuildType = "调试" 默认配置 版本代码 = 1 版本名称 = "0.1" minSdkVersion = 9 targetSdkVersion = 17 compileSdkVersion 17 buildConfig "private final static boolean DEFAULT = true;", \ "私有最终静态字符串 FOO = \"foo\";" 构建类型 调试 packageNameSuffix = ".debug" buildConfig "私有最终静态布尔 DEBUG2 = false;" aaptOptions noCompress "txt" 源集 主要的 显现 srcFile 'AndroidManifest.xml' 爪哇 srcDir 'src' 资源 srcDir 'res' 资产 srcDir '资产' 资源 srcDir 'src'【讨论】:
以上是关于Android构建系统gradle的主要内容,如果未能解决你的问题,请参考以下文章
我找到了两个 gradle android 插件 - 两者之间有啥关系吗?
Gradle Android 构建项目错误:找不到元数据资源
centos7.6 nodejs开发及打包android apk环境,涉及vscodenodejscordovapm2jdk8gradleandroid sdk