我认为IntelliJ在生成R.java文件时存在一些问题,导致AndroidAnnotations出现问题,因为它无法解析布局的资源ID。
这是我的活动:
package com.airlocksoftware.canvastest;
import android.app.Activity;
import android.os.Bundle;
import com.googlecode.androidannotations.annotations.EActivity;
@EActivity(R.layout.main)
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
奇怪的是,即使我注释掉注释并执行setContentView(R.layout.main)
,即使从未导入R.java,它也能正常工作。
顺便说一下,布局只是一个简单的“Hello World”。没有什么奇怪的事情发生在那里。
无论我做什么,我都无法获得AndroidAnnotations来生成CanvasActivity_.java
。我的pom.xml看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.airlocksoftware.canvastest</groupId>
<artifactId>CanvasTest</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<android.version>4.2.2_r2</android.version>
<android.platform>17</android.platform>
<androidannotations.version>2.7.1</androidannotations.version>
<java.version>1.6</java.version>
</properties>
<repositories>
<repository>
<id>local-repo</id>
<url>file:///${env.HOME}/.m2/repository</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>${android.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.googlecode.androidannotations</groupId>
<artifactId>androidannotations</artifactId>
<version>${androidannotations.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.googlecode.androidannotations</groupId>
<artifactId>androidannotations-api</artifactId>
<version>${androidannotations.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<sdk>
<platform>${android.platform}</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
注释处理set up like shown in this screenshot.
基本上我将处理器路径设置为指向本地maven仓库中的jar文件,为described here.
项目来源设置为like shown in this screenshot.
无论我如何制作/重建项目,gen / aa中都没有出现任何内容(因此我无法引用CanvasActivity_.java)我从项目根目录运行了mvn clean install,这与此stacktrace失败。< / p>
INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.363s
[INFO] Finished at: Sat May 18 15:53:06 MDT 2013
[INFO] Final Memory: 11M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project CanvasProto: Compilation failure: Compilation failure:
[ERROR] /Users/matthewbbishop/Clients/proto/CanvasProto/src/main/java/com/airlocksoftware/CanvasProto/CanvasActivity.java:[6,38] cannot find symbol
[ERROR] symbol : class R
[ERROR] location: package com.airlocksoftware.CanvasProto
[ERROR] /Users/matthewbbishop/Clients//proto/CanvasProto/src/main/java/com/airlocksoftware/CanvasProto/CanvasActivity.java:[11,12] package R does not exist
[ERROR] /Users/matthewbbishop/Clients/proto/CanvasProto/src/main/java/com/airlocksoftware/CanvasProto/CanvasActivity.java:[14,15] package R does not exist
[ERROR] error: Unexpected error. Please report an issue on AndroidAnnotations, with the following content: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
[ERROR] at com.googlecode.androidannotations.helper.AnnotationHelper.extractAnnotationParameter(AnnotationHelper.java:293)
[ERROR] at com.googlecode.androidannotations.helper.AnnotationHelper.extractAnnotationResIdValueParameter(AnnotationHelper.java:269)
[ERROR] at com.googlecode.androidannotations.helper.IdValidatorHelper.resIdsExist(IdValidatorHelper.java:45)
[ERROR] at com.googlecode.androidannotations.validation.EActivityValidator.validate(EActivityValidator.java:55)
[ERROR] at com.googlecode.androidannotations.validation.ModelValidator.validate(ModelValidator.java:56)
[ERROR] at com.googlecode.androidannotations.AndroidAnnotationProcessor.validateAnnotations(AndroidAnnotationProcessor.java:414)
[ERROR] at com.googlecode.androidannotations.AndroidAnnotationProcessor.processThrowing(AndroidAnnotationProcessor.java:364)
[ERROR] at com.googlecode.androidannotations.AndroidAnnotationProcessor.process(AndroidAnnotationProcessor.java:341)
[ERROR] at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:627)
[ERROR] at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:556)
[ERROR] at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:701)
[ERROR] at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:987)
[ERROR] at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
[ERROR] at com.sun.tools.javac.main.Main.compile(Main.java:353)
[ERROR] at com.sun.tools.javac.main.Main.compile(Main.java:279)
[ERROR] at com.sun.tools.javac.main.Main.compile(Main.java:270)
[ERROR] at com.sun.tools.javac.Main.compile(Main.java:87)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:597)
[ERROR] at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess0(JavacCompiler.java:551)
[ERROR] at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:526)
[ERROR] at org.codehaus.plexus.compiler.javac.JavacCompiler.compile(JavacCompiler.java:167)
[ERROR] at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:678)
[ERROR] at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:597)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
[ERROR] Caused by: java.lang.reflect.InvocationTargetException
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:597)
[ERROR] at com.googlecode.androidannotations.helper.AnnotationHelper.extractAnnotationParameter(AnnotationHelper.java:287)
[ERROR] ... 46 more
[ERROR] Caused by: java.lang.annotation.AnnotationTypeMismatchException: Incorrectly typed data found for annotation element public abstract int com.googlecode.androidannotations.annotations.EActivity.value() (Found data of type int)
[ERROR] at com.sun.tools.javac.model.AnnotationProxyMaker$ValueVisitor$1.generateException(AnnotationProxyMaker.java:243)
[ERROR] at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:56)
[ERROR] at $Proxy16.value(Unknown Source)
[ERROR] ... 51 more
老实说,我现在不知所措。如果有人知道该怎么做,那将是惊人的。谢谢!
编辑:这是IntelliJ生成的存根R.java。
/*___Generated_by_IDEA___*/
package com.airlocksoftware.canvastest;
/* This stub is for using by IDE only. It is NOT the R class actually packed into APK */
public final class R {
}
答案 0 :(得分:1)
因为您的pom.xml
缺少以下内容:
<packaging>apk</packaging>
如果不这样,R.java
文件将不会生成。
将其添加到pom.xml
的顶部,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.airlocksoftware.canvastest</groupId>
<artifactId>CanvasTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>apk</packaging>
/* ... */
/* rest are fine */
/* ... */
答案 1 :(得分:0)
这很奇怪。你maven配置似乎很棒。它至少应该通过Maven编译好...... 我不认为这是因为错误应该是不同的,但你是否更新到最后一个Android SDK 22?