[英]How to resolve unknown class and can not resolve symbol in Android Studio java library module
Using Android Studio and creating a java library module as part of a sub project I get an error on the following java statement: 使用Android Studio并创建一个java库模块作为子项目的一部分,我在以下java语句中收到错误:
javaFile.writeTo(System.out);
and it complains of can not resolve symbol 'writeTo' and unknown class 'System.out'. 它抱怨无法解析符号'writeTo'和未知类'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);
}
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
. 将处理器链接到我的主模块时,我得到了一个
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: 我使用android-apt来使注释处理器工作,所以在我的
build.config
我的依赖项有apt配置定义:
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.
不确定这是否适用于您的情况而没有更多细节,但这让我重回正轨。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.