3

Using Android Studio and creating a java library module as part of a sub project I get an error on the following java statement:

javaFile.writeTo(System.out);

and it complains of can not resolve symbol 'writeTo' and unknown class 'System.out'.

Here's the gist of the source code class

import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeSpec;

import javax.lang.model.element.Modifier;

public class MyClass {

...

JavaFile javaFile = JavaFile.builder("com.foobar.helloworld", helloWorld)
        .build();


javaFile.writeTo(System.out);
}
Peter Birdsall
  • 2,299
  • 4
  • 21
  • 45
  • 1
    Where can I find the code or documentation of JavaFile? I think that the writeTo command only accepts a writer and not System.out. I suppose you have correctly included all the necessary things in gradle? – tim687 Jan 26 '16 at 07:10
  • Not quite sure, mostly a Android Developer, so a compile '...' could be missing or something weird like a java_home not being pointed to. Tks. – Peter Birdsall Jan 26 '16 at 14:10

1 Answers1

3

A bit hard to say without knowing exactly what your exception was, but I had something similar pop up when I was testing out a sub-module annotation processor. When linking the processor to my main module, I was getting a java.lang.NoClassDefFoundError: com/squareup/javapoet/MethodSpec. I was using android-apt to get the annotation processor working, so in my build.config my dependencies had the apt configuration definition:

dependencies {
    ...

    apt 'com.squareup:javapoet:1.7.0' // <- Note that since my Processor used javapoet, I had to include Javapoet in the main module's apt dependency as well as my processor jar
    apt files('../processor/build/libs/processor.jar')
}

Once i included the above noted dependency, then all worked fine. Not sure if this applies to your situation without more details, but this got me back on track.

JCricket
  • 1,238
  • 2
  • 16
  • 34