使用Android Annotations进行maven构建期间出现“错误:意外错误”

时间:2012-11-02 16:58:34

标签: android maven android-annotations

我使用maven建立项目与android anotations(v.2.6)有问题,eclipse一切正常。这是一些项目和错误的详细信息:

从pom构建配置代码段:

<plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.3.2</version>
                <inherited>true</inherited>
                <configuration>
                    <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
                    <assetsDirectory>${project.basedir}/assets</assetsDirectory>
                    <resourceDirectory>${project.basedir}/res</resourceDirectory>
                    <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
                    <sdk>
                        <platform>16</platform>
                    </sdk>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
                <extensions>true</extensions>
            </plugin>

,这是在父项目上执行mvn clean install后的输出:

[INFO] --- maven-compiler-plugin:2.5:compile (default-compile) @ native-container framework ---
[INFO] Compiling 102 source files to   /Users/vitaliyzasadnyy/Development/repository/androidcontainer/native-container-   android/native-container-framework/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] error: Unexpected error. Please report an issue on AndroidAnnotations, with the following content: java.lang.NullPointerException
[ERROR]     at com.googlecode.androidannotations.internal.codemodel.JCodeModel.ref(JCodeModel.java:372)
at com.googlecode.androidannotations.processing.EBeansHolder.refClass(EBeansHolder.java:160)
at com.googlecode.androidannotations.processing.EBeansHolder$Classes.<init>(EBeansHolder.java:50)
at com.googlecode.androidannotations.processing.EBeansHolder.<init>(EBeansHolder.java:136)
at com.googlecode.androidannotations.processing.ModelProcessor.process(ModelProcessor.java:40)
at com.googlecode.androidannotations.AndroidAnnotationProcessor.processAnnotations(AndroidAnnotationProcessor.java:472)
at com.googlecode.androidannotations.AndroidAnnotationProcessor.processThrowing(AndroidAnnotationProcessor.java:343)
at com.googlecode.androidannotations.AndroidAnnotationProcessor.process(AndroidAnnotationProcessor.java:318)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:627)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:556)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:701)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:987)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
at com.sun.tools.javac.main.Main.compile(Main.java:353)
at com.sun.tools.javac.main.Main.compile(Main.java:279)
at com.sun.tools.javac.main.Main.compile(Main.java:270)
at com.sun.tools.javac.Main.compile(Main.java:87)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess0(JavacCompiler.java:559)
at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:534)
at org.codehaus.plexus.compiler.javac.JavacCompiler.compile(JavacCompiler.java:168)
at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:678)
at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) /Users/vitaliyzasadnyy/Development/repository/androidcontainer/native-container-android/native-container-framework/src/main/java/com/nravo/framework/activity/MainScreenActivity.java:[44,-1] Unexpected error. Please report an issue on AndroidAnnotations, with the following content: java.lang.NullPointerException
at com.googlecode.androidannotations.internal.codemodel.JCodeModel.ref(JCodeModel.java:372)
at com.googlecode.androidannotations.processing.EBeansHolder.refClass(EBeansHolder.java:160)

有人遇到过这个问题吗?

3 个答案:

答案 0 :(得分:1)

正如我在issue you created中提到的,这是Maven / CodeModel错误,其中Thread.currentThread().getContextClassLoader()返回null,原因我不知道。我即将发布AndroidAnnotations 2.7,这个问题不应再出现了。

答案 1 :(得分:0)

随着Piwai的建议我通过转向Android注释的快照构建解决了这个问题。要切换到快照,请在pom.xml中替换当前的AA依赖项:

<dependency>
    <groupId>com.googlecode.androidannotations</groupId>
    <artifactId>androidannotations</artifactId>
    <version>2.7-SNAPSHOT</version>
</dependency>

<dependency>
    <groupId>com.googlecode.androidannotations</groupId>
    <artifactId>androidannotations-api</artifactId>
    <version>2.7-SNAPSHOT</version>
</dependency>

您还需要添加快照存储库:

<repositories>
    <repository>
        <id>snapshots-repository</id>
        <name>Sonatype oss snapshot repo</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>

注意:来自AA v.2.7发行说明:

  

API jar现在是一个单独的工件,androidannotations-api。我们不再使用api分类器了。

答案 2 :(得分:-1)

我遇到了这个。一种解决方案是将其添加到pom.xml

    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>annotations</artifactId>
        <version>4.1.1.4</version>
    </dependency>