调试 gradle 任务 compileReleaseJavaWithJavac

Debugging gradle task compileReleaseJavaWithJavac

我正在编写一个自定义 gradle 插件,它生成代码并注入一些新的 gradle 任务。我目前的问题是 gradlew check 任务 compileReleaseJavaWithJavaccompileDebugJavaWithJavac 失败。

windows 任务运行正常,Linux 和 mac 任务失败。这可能是路径或目录分隔符错误的提示。

这是确切的错误:

:examples:app:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
/the/full/path/to/file/MainActivity.java:10: error: package R does not exist
        setContentView(R.layout.activity_main);
                        ^
1 error

我现在的问题是如何调试该特殊任务?我想查看 class 路径,因为我猜那里出了问题。

在你说之前 嘿,R 文件没有生成:它是。我在文件系统中看到了文件。

当我在 mac 上禁用并行任务时,我玩得更多了,它也编译得很好。然而在travis上它仍然失败。

更新回复:

目前我只知道:

  • 这不是 Travis-ci 的问题,因为我在 linux 上本地复制了它 机.
  • 与R包无关,为默认包,无需导入。
  • 这与 appcompat 错误无关,随机更改构建成功。
  • 似乎与增量构建有关,, also this 并尝试将其设置为 false。

Story: Don't compile a source file when the API of its compile dependencies has not changed

Currently, changing the body of a method invalidates all class files that have been compiled against the method's class. Instead, only the method's class should be recompiled. Similarly, changing a resource file invalidates all class files that included that resource file in the compile classpath. Instead, resource files should be ignored when compiling.

We don't necessarily need a full incremental Java compilation to improve this. For example, the Java compilation task may consider the API of the compile classpath - if it has changed, then compile all source files, and if it has not, skip the task (assuming everything else is up to date). This means that a change to a method body does not propagate through the dependency graph.

第一次构建时出现 Stracktrace 错误(第二次构建成功):

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':examples:app:compileReleaseJavaWithJavac'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
...
Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.
        at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:48)

也许this warning, Java8 or annotations是相关的。我希望这有帮助,我离开是因为我所做的任何更改都会使构建成功并且很难理解真正的问题。

我配置了 Java 8 个用法,例如 this:

android {
  ...
  defaultConfig {
    ...
    jackOptions {
      enabled true
    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

上一个回复:

尝试使用您的真实包将下一个导入添加到您的 MainActivity.java

import your.package.R;

R 文件未正确生成,因为之前的错误如下:

COMPILE-Error: package android.support.v7.app does not exist

我刚测试过。我在 linux 机器上下载了你的项目(这不是 travis-ci 问题)。

我用下一行替换了依赖关系,它起作用了:

compile "com.android.support:appcompat-v7:25.0.0"

所以我建议你加上{ }:

compile "com.android.support:appcompat-v7:${project.supportLibVersion}"

真的,我不确定,现在它总是在没有建议的更改的情况下工作。

也许确实是关于并行选项问题并且在第二个 运行 上工作,但我们很接近。