13

我实际上是 Maven 框架的新手。我已经有一个 Maven 项目。我从http://m2eclipse.sonatype.org/sites/m2e将 Maven 插件等安装到了我的 EclipseIDE 中。然后我导入了我的项目并启用了依赖项,但是该项目显示了太多错误。pom.xml 本身显示错误。错误是

Project Build Error:unknown packaging:apk
Project Build Error:unresolvable build extension:plugin" 

等等

我的错误区域是:

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.nbc.cnbc.android</groupId>
<artifactId>android.domain.tests</artifactId>
<version>1.0.0</version>
<packaging>apk</packaging>

<parent>
    <groupId>com.nbc.cnbc.android</groupId>
    <artifactId>android.domain.parent</artifactId>
    <version>1.0.0</version>
    <relativePath>../android.domain.parent/pom.xml</relativePath>
</parent>

<name>android.domain.tests</name>
<url>http://maven.apache.org</url>

可能是因为最后一行中指定的 url 可能不同吗?任何想法为什么会发生这种情况?任何回复都非常感谢。非常感谢提前!!

4

2 回答 2

10

您已经安装了适用于 Java 项目(和 .jar 文件)的“普通”Maven 插件。对于 Android,您需要Maven Android 插件

就个人而言,我认为 Android Maven 对于我在项目中使用的少数依赖项来说太麻烦了,但这是我在尝试时设置它的方式:

  • 将 ANDROID_HOME 变量设置为您的 SDK 根位置,并将 SDKtoolsplatform-tools文件夹添加到您的路径(更多信息请参见此链接

  • 启动 Eclipse 并在您的 Android 项目上启用“依赖管理”。

  • 确保您将Maven Central包含到您的存储库中,并将以下内容添加到您的 pom 中(更多信息请参见此链接此链接)。

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

<build>
   <sourceDirectory>src</sourceDirectory>
   <plugins>
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-compiler-plugin</artifactId>
           <configuration>
               <source>1.6</source>
               <target>1.6</target>
           </configuration>
       </plugin>
       <plugin>
           <groupId>com.jayway.maven.plugins.android.generation2</groupId>
           <artifactId>maven-android-plugin</artifactId>
           <configuration>
               <sdk>
                  <path>${env.ANDROID_HOME}</path>
                   <platform>10</platform>
               </sdk>
               <deleteConflictingFiles>true</deleteConflictingFiles>
           </configuration>
           <extensions>true</extensions>
       </plugin>
   </plugins>
</build>

当然,您可以根据自己的喜好调整 android 版本。

于 2011-06-23T11:42:28.947 回答
1

最后更新:现在工件的名称似乎是android-maven-plugin: http: //mvnrepository.com/artifact/com.jayway.maven.plugins.android.generation2/android-maven-plugin/3.6.0

所以它应该是这样的:

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

    <build>
       <sourceDirectory>src</sourceDirectory>
       <plugins>
           <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-compiler-plugin</artifactId>
               <configuration>
                   <source>1.6</source>
                   <target>1.6</target>
               </configuration>
           </plugin>
           <plugin>
               <groupId>com.jayway.maven.plugins.android.generation2</groupId>
               <artifactId>android-maven-plugin</artifactId>
               <configuration>
                   <sdk>
                      <path>${env.ANDROID_HOME}</path>
                       <platform>10</platform>
                   </sdk>
                   <deleteConflictingFiles>true</deleteConflictingFiles>
               </configuration>
               <extensions>true</extensions>
           </plugin>
       </plugins>
    </build>
于 2013-08-09T15:26:41.353 回答