I think there's some problem with IntelliJ when it generates the R.java file, which leads to a problem in AndroidAnnotations because it can't resolve the resource id for my layout.
Here's my activity:
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);
}
}
What's weird is that even if I comment out the annotation, and do setContentView(R.layout.main)
, it works fine even though R.java is never imported.
By the way, the layout is just a simple "Hello World". Nothing weird going on there.
No matter what I do, I can't get AndroidAnnotations to generate CanvasActivity_.java
. My pom.xml looks like this:
<?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>
The annotation processing set up like shown in this screenshot.
Basically I setup the processor path to point to the jar files in my local maven repo, as described here.
The projects sources are set up like shown in this screenshot.
No matter how I make / rebuild the project, nothing ever shows up in gen/aa (and thus I can't reference CanvasActivity_.java) I ran mvn clean install from the project root, which fails with this stacktrace.
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
Honestly I'm at a loss now. If anyone has an idea of what to do, that would be amazing. Thanks!
EDIT: here's the stub R.java generated by IntelliJ.
/*___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 {
}
Its because your pom.xml
is missing the following:
<packaging>apk</packaging>
Without this the R.java
file will not get generated.
Add it to the top of your pom.xml
as follows:
<?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 */
/* ... */
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With