2

I'm writing a custom gradle plugin which generated code and injects some new gradle tasks. My problem is currently that on gradlew check the task compileReleaseJavaWithJavac or compileDebugJavaWithJavac fails.

On windows the task runs fine, on Linux and on mac the task fails. This might be a hint that there is a error with the path or directory separator.

Here is the exact error:

: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

My question is now how can I debug that special task? I would like to see the class path since I guess there goes something wrong.

Before you say but hey the R file is not generated: It is. I see the file in the file system.

I was playing a little more when I disable parallel task on a mac it compiles fine too. However on travis it still fails.

rekire
  • 47,260
  • 30
  • 167
  • 264
  • Please, add your travis.yml content to the question or a link to the file. – albodelu Oct 30 '16 at 05:50
  • 1
    @ardock here it is: https://github.com/rekire/PojoBooster/blob/d6b51c81191ecb99017585a28764bb7793da3afe/.travis.yml – rekire Oct 30 '16 at 06:36

1 Answers1

1

Updated response:

Currently i only know that:

  • It's not a Travis-ci issue because I reproduced it locally on a linux machine.
  • It's not related to R package, it's the default package and the import is unnecessary.
  • It's not related to the appcompat error, build is successful with any random change.
  • Seems something related to incremental builds, see this, also this and try to set it to 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 error on first build (second build successful):

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)

Perhaps this warning, Java8 or annotations are related. I hope this helped, I leave because any change I do, makes the build successful and it's hard to understand the real issue.

I configured Java 8 usage like this:

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

Previous response:

Try to add to your MainActivity.java the next import using your real package:

import your.package.R;

R file is not correctly generated due to previous errors like this:

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

I just tested it. I downloaded your project on a linux machine (it's not a travis-ci issue).

I replaced the dependency by the next line and it works:

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

So I suggest you to add { }:

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

Really, I'm not sure, now it's working always without the suggested changes.

Perhaps, it's true that it's about parallel option issue and worked on second run, but we are close.

Community
  • 1
  • 1
albodelu
  • 7,931
  • 7
  • 41
  • 84