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
}
还有我的自定义 View :
package com.myapp.view;
// imports...
@EView
public class MyView extends TextView {
// ...
}
我已将我的项目作为 Maven 项目导入到 Android Studio 中。当我从 Studio 构建它时,一切正常。
但是,当我尝试 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_
当我打开 MyActivity_.java
生成的文件时,我可以看到没有导入 com.myapp.view.MyView_
类(当我使用 Studio 构建)。为什么会发生这种情况?
编译器配置:
<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>
This没有帮助。
最佳答案
您不应在 @ViewById
带注释的字段上使用生成的类。但您仍然必须在布局文件中使用生成的文件:
@EActivity(R.layout.start)
public class MyActivity extends Activity {
@ViewById
MyView myView;
}
<LinearLayout ...>
<my.package.MyView_ .../>
</LinearLayout>
另外,您能否确认您的 pom.xml 中有这些依赖项并且您使用的是 Java 6(如 on the 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>
关于java - AndroidAnnotations - 使用 Maven 时找不到符号(缺少导入),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22516161/