[英]AndroidAnnotations - cannot find symbol when using maven (missing imports)
AndroidAnnotations 3.0.1. AndroidAnnotations 3.0.1。
package com.myapp;
import com.myapp.view.MyView_;
// other imports...
@EActivity(R.layout.start)
public class MyActivity extends Activity {
@ViewById
MyView_ myView;
// using myView
}
And my custom view: 和我的自定义视图:
package com.myapp.view;
// imports...
@EView
public class MyView extends TextView {
// ...
}
I have imported my project to Android Studio as Maven project. 我已将我的项目作为Maven项目导入到Android Studio中。 When I build it from Studio, everything works. 当我从Studio构建它时,一切正常。
However, when I try to mvn package
it, I get the following error: 但是,当我尝试对其进行mvn package
时,出现以下错误:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /e:/projects/myapp/target/generated-sources/annotations/com/myapp/MyActivity_.java:[80,22] cannot find symbol
symbol: class MyView_
location: class com.myapp.MyActivity_
When I open the MyActivity_.java
generated file, I can see that there are no import for com.myapp.view.MyView_
class (it is there when I build with Studio). 当我打开MyActivity_.java
生成的文件时,我可以看到com.myapp.view.MyView_
类没有导入(使用Studio进行构建时就存在)。 Why could that happen? 为什么会发生这种情况?
Compiler configuration: 编译器配置:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<annotationProcessors>
<annotationProcessor>org.androidannotations.AndroidAnnotationProcessor</annotationProcessor>
</annotationProcessors>
<compilerArguments>
<AandroidManifestFile>${project.basedir}/src/main/AndroidManifest.xml</AandroidManifestFile>
</compilerArguments>
</configuration>
</plugin>
You shouldn't use generated class on your @ViewById
annotated field. 您不应在@ViewById
注释的字段上使用生成的类。 But you still have to use generated one in your layout file : 但是您仍然必须在布局文件中使用生成的生成文件:
@EActivity(R.layout.start)
public class MyActivity extends Activity {
@ViewById
MyView myView;
}
<LinearLayout ...>
<my.package.MyView_ .../>
</LinearLayout>
Also, could you confirm you have these dependencies in your pom.xml and you're using Java 6 (as explained on the wiki ) ? 另外,您是否可以确认您在pom.xml中具有这些依赖关系,并且正在使用Java 6(如Wiki上所述 )?
<dependencies>
<!-- [...] -->
<dependency>
<groupId>org.androidannotations</groupId>
<artifactId>androidannotations</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.androidannotations</groupId>
<artifactId>androidannotations-api</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.