Android构建系统gradle

时间:2012-12-10 13:13:04

标签: android gradle android-build

我正在测试仍然处于测试阶段的新构建系统。 我已经实现了一些生成以下错误的代码:

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

Full Gradle Stacktrace

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

2 个答案:

答案 0 :(得分:4)

0.2版是使用Gradle 1.2开发的(1.3还没有出版)。我们知道我们现在正在使用一些内部的东西,所以它可能在1.3上打破(尚未测试,很快就会完成)。

目前,请使用Gradle 1.2

答案 1 :(得分:2)

您需要将compliedSdkVersion 17添加到您的gradle.build文件中:

编辑:我刚创建的参考项目。建筑,标志等https://github.com/yegdroid/gradle_demo

//
// A basic Android application that follows all the conventions
//
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.3'
    }
}
apply plugin: 'android'

android {
    testBuildType = "debug"

    defaultConfig {
        versionCode = 1
        versionName = "0.1"
        minSdkVersion = 9
        targetSdkVersion = 17


        compileSdkVersion 17
        buildConfig "private final static boolean DEFAULT = true;", \
                    "private final static String FOO = \"foo\";"
    }

    buildTypes {
        debug {
            packageNameSuffix = ".debug"

            buildConfig "private final static boolean DEBUG2 = false;"
        }
    }

    aaptOptions {
        noCompress "txt"
    }
    sourceSets {
          main {
              manifest {
                  srcFile 'AndroidManifest.xml'
              }
              java {
                  srcDir 'src'
              }
              res {
                  srcDir 'res'
              }
              assets {
                  srcDir 'assets'
              }
              resources {
                  srcDir 'src'
              }
          }
      }
}