Maven找不到外部jar的注释

时间:2013-04-10 19:33:52

标签: android maven maven-3 android-build android-maven-plugin

我正在将一个简单的Android应用程序转换为Maven,而且我遇到了第三方jar(ActiveAndroid),其中包含我在我的代码中使用的注释类。我已经确认jar确实包含了注释类文件,当我将它包含在libs目录中时,jar工作正常,并使用Eclipse进行编译。

这是我的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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.danh32</groupId>
    <artifactId>testapp</artifactId>
    <version>1.0</version>
    <packaging>apk</packaging>
    <name>testapp</name>

    <properties>
        <platform.version> 4.1.1.4</platform.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>${platform.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.actionbarsherlock</groupId>
            <artifactId>actionbarsherlock</artifactId>
            <version>4.2.0</version>
            <type>apklib</type>
        </dependency>

        <dependency>
            <groupId>com.activeandroid</groupId>
            <artifactId>activeandroid</artifactId>
            <version>LATEST</version>
        </dependency>
    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>

            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.5.0</version>
                <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>
                <extensions>true</extensions>
            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

这是我的编译错误:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.339s
[INFO] Finished at: Wed Apr 10 14:18:51 CDT 2013
[INFO] Final Memory: 17M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project testapp: Compilation failure: Compilation failure:
[ERROR] /Users/danh32/code/android/workspace-android/TestApp/src/com/danh32/testapp/db/DSLocation.java:[9,43] cannot find symbol
[ERROR] symbol  : class ConflictAction
[ERROR] location: @interface com.activeandroid.annotation.Column
[ERROR] /Users/danh32/code/android/workspace-android/TestApp/src/com/danh32/testapp/db/DSLocation.java:[15,32] cannot find symbol
[ERROR] symbol  : method unique()
[ERROR] location: @interface com.activeandroid.annotation.Column
[ERROR] /Users/danh32/code/android/workspace-android/TestApp/src/com/danh32/testapp/db/DSLocation.java:[15,47] cannot find symbol
[ERROR] symbol  : method onUniqueConflict()
[ERROR] location: @interface com.activeandroid.annotation.Column
[ERROR] /Users/danh32/code/android/workspace-android/TestApp/src/com/danh32/testapp/db/DSLocation.java:[15,66] cannot find symbol
[ERROR] symbol  : variable ConflictAction
[ERROR] location: class com.danh32.testapp.db.DSLocation
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

我刚开始使用Maven并在Eclipse之外编译Android应用程序,所以我确信我错过了一些简单的东西。任何朝着正确方向的推动都非常感激!

谢谢!

3 个答案:

答案 0 :(得分:1)

看起来Maven Central Repo中没有活动的android工件(参见this search)。您可以在自己的本地存储库中安装该jar(使用mvn install-file,但这只能在您的本地计算机上运行。或者您可以将该工件部署到您控制并在POM中引用它的存储库。

答案 1 :(得分:1)

你正在使用LATEST。你有可能拥有该工件的多个版本,而Maven正在从Eclipse获得另一个版本吗?

答案 2 :(得分:0)

您是否考虑过课程版本问题?只是推测,但可能是jar使用1.6 JDK(目标1.6)构建你的POM已经指定源和目标为1.5,考虑到你也使用1.5 JDK,编译器可能根本无法读取jar文件中的类用1.6编译