在Maven中构建Android项目:Package *不存在

时间:2010-11-16 20:10:18

标签: android maven pom.xml

我正在使用这个Maven脚本构建我的应用程序。但后来我收到了一大堆错误(见帖子末尾)。就好像找不到 android.jar 一样。我检查了 android.jar 的路径,没关系。

<?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>my.group.id</groupId>
    <artifactId>myproject1.0</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>MyProject</name>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.google.android</groupId>
                <artifactId>android</artifactId>
                <version>2.1.2</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>maven-android-plugin</artifactId>
                <version>2.6.0</version>
                <configuration>
                    <sdk>
                        <platform>4</platform>
                    </sdk>
                    <emulator>
                        <avd>16</avd>
                    </emulator>
                    <deleteConflictingFiles>true</deleteConflictingFiles>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                </configuration>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3</version>
            </plugin>
        </plugins>
    </build>
</project>

错误:

C:\projectX>mvn install -e
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject
[INFO]    task-segment: [install]
[INFO] ------------------------------------------------------------------------
[INFO] [android:generate-sources {execution: default-generate-sources}]
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] Copying local resource files to combined resource directory.
[INFO] C:\dev\android-sdk-windows\platforms\android-4/tools/aapt [package, -m, -J, \
       C:\projectX\target\generated-sources\r, -M, C:\projectX\AndroidManifest.xml, -S, \
       C:\projectX\target\generated-sources\combined-resources\res,-A, C:\projectX\assets, -I, \
       C:\dev\android-sdk-windows\platforms\android-4\android.jar]

[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure

C:\projectX\src\com\projectx\MyClass.java:[13,22] package org.apache.http does not exist
C:\projectX\src\com\projectx\MyClass.java:[23,29] package org.apache.http.entity does not exist
C:\projectX\src\com\projectx\MyClass.java:[28,29] package org.apache.http.params does not exist
C:\projectX\src\com\projectx\MyClass.java:[30,22] package android.content does not exist
C:\projectX\src\com\projectx\MyClass.java:[31,19] package android.util does not exist
C:\projectX\src\com\projectx\MyClass.java:[50,9] cannot find symbol
symbol  : class DefaultHttpClient
location: class com.projectx.MyClass

C:\projectX\src\com\projectx\MyService.java:[10,24] package android.telephony does not exist
C:\projectX\src\com\projectx\MyService.java:[13,18] package android.app does not exist
C:\projectX\src\com\projectx\MyService.java:[19,22] package android.content does not exist
C:\projectX\src\com\projectx\MyService.java:[23,40] package android.content.SharedPreferences does not exist
C:\projectX\src\com\projectx\MyService.java:[25,18] package android.net does not exist
C:\projectX\src\com\projectx\MyService.java:[28,17] package android.os does not exist
C:\projectX\src\com\projectx\MyService.java:[29,25] package android.preference does not exist
C:\projectX\src\com\projectx\MyService.java:[30,19] package android.util does not exist
C:\projectX\src\com\projectx\MyService.java:[31,19] package android.view does not exist
C:\projectX\src\com\projectx\MyService.java:[34,21] package android.widget does not exist
C:\projectX\src\com\projectx\MyService.java:[54,36] cannot find symbol
symbol: class Service
public class MyService extends Service {

C:\projectX\src\com\projectx\MyClass.java:[103,34] cannot find symbol
symbol  : class Context
location: class com.projectx.MyClass

C:\projectX\src\com\projectx\MyClass.java:[209,46] cannot find symbol
symbol  : class Context
location: class com.projectx.MyClass

C:\projectX\src\com\projectx\MyClass.java:[229,37] cannot find symbol
symbol  : class Context
location: class com.projectx.MyClass

C:\projectX\src\com\projectx\MyService.java:[75,16] cannot find symbol
symbol  : class PendingIntent
location: class com.projectx.MyService

...truncated...

[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.BuildFailureException: Compilation failure

3 个答案:

答案 0 :(得分:1)

问题只是<dependencyManagement>标签不应该在那里。

答案 1 :(得分:0)

这一行:C:\ dev \ android-sdk-windows \ platforms \ android-4 / tools / aapt

你确定那是对的吗?这可能是android.jar没被拿起的原因..

答案 2 :(得分:0)

我无法重现您的错误。但是对我来说,使用android.jar for 2.1.2(平台7)并指定平台4(Android 1.6)似乎很奇怪。如果你想让你的应用程序在1.6上运行,你应该使用1.6中的android.jar。因为这是在运行时可用的。

        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>1.6_r2</version>
            <scope>provided</scope>
        </dependency>

如果你想使用平台8(Froyo)附带的AndroidManifest.xml的功能,比如installLocation,你不应该使用平台4而是8。

       <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>maven-android-plugin</artifactId>
            <configuration>
                <sdk>
                    <path>${env.ANDROID_HOME}</path>
                    <platform>8</platform>
                </sdk>
                <deleteConflictingFiles>true</deleteConflictingFiles>
            </configuration>
            <extensions>true</extensions>
        </plugin>

如果您使用Maven&gt;版本2.0.9(IIRC)您不必再指定插件的版本。然后自动使用最新版本。