1

几个月前,我在业余时间开始了一个 Android 项目。为了让朋友轻松协作,我想使用 maven,但我未能构建我的项目。

我的项目使用 ActionBarSherlock 和 Roboguice(以及允许这种协作的 Roboguice Sherlock 库)。经过几个小时试图破解我的pom后,我得到了这个:

<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.github.armelbd</groupId>
<artifactId>my-places</artifactId>
<version>0.1-SNAPSHOT</version>
<name>MyPlaces</name>
<url>https://github.com/armelbd/my-places</url>

<issueManagement>
    <url>https://github.com/armelbd/my-places/issues</url>
    <system>GitHub Issues</system>
</issueManagement>

<licenses>
    <license>
        <name>Apache V2</name>
        <url>http://www.apache.org/licenses/LICENSE-2.0</url>
        <distribution>repo</distribution>
    </license>
</licenses>

<scm>
    <url>https://github.com/armelbd/my-places</url>
    <connection>scm:git:git://github.com/armelbd/my-places.git</connection>
    <developerConnection>scm:git:git@github.com:armelbd/my-places.git</developerConnection>
</scm>

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 

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

    <!-- Dependency injection using Roboguice and Google Guice extensions -->
    <dependency>
        <groupId>org.roboguice</groupId>
        <artifactId>roboguice</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>3.0</version>
        <classifier>no_aop</classifier>
    </dependency>
    <dependency>
        <groupId>com.google.inject.extensions</groupId>
        <artifactId>guice-multibindings</artifactId>
        <version>3.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.inject.extensions</groupId>
        <artifactId>guice-assistedinject</artifactId>
        <version>3.0</version>
    </dependency>

    <!-- Action Bar sherlock -->
    <dependency>
        <groupId>com.actionbarsherlock</groupId>
        <artifactId>library</artifactId>
        <version>4.0.0</version>
        <type>apklib</type>
    </dependency>

    <!-- Let Roboguice and Sherlock work together -->
    <dependency>
        <groupId>com.github.rtyley</groupId>
        <artifactId>roboguice-sherlock</artifactId>
        <version>1.4</version>
    </dependency>
</dependencies>

<build>
    <finalName>${project.artifactId}</finalName>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
       <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5</version>
            <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>
            <version>3.0.0</version>
            <extensions>true</extensions>
            <configuration>
                <sdk>
                    <platform>15</platform>
                </sdk>
            </configuration>
        </plugin>
    </plugins>
</build>

但我得到这些错误:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building MyPlaces 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ my-places ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/bourgona/Project/my-   places/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5:compile (default-compile) @ my-places ---
[INFO] Compiling 18 source files to /Users/bourgona/Project/my-places/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/bourgona/Project/my-  places/src/net/esial/myplaces/views/AddressBarFragment.java:[3,25] cannot find symbol
symbol  : class R
location: package net.esial.myplaces
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[8,33] package  com.actionbarsherlock.view does not exist
[ERROR] /Users/bourgona/Project/my-  places/src/net/esial/myplaces/views/AddressBarFragment.java:[9,33] package com.actionbarsherlock.view does not exist
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[22,7] cannot access   com.actionbarsherlock.app.SherlockFragment
class file for com.actionbarsherlock.app.SherlockFragment not found
public class AddressBarFragment extends RoboSherlockFragment {
[ERROR] /Users/bourgona/Project/my-  places/src/net/esial/myplaces/views/AddressBarFragment.java:[65,33] cannot find symbol
symbol  : class Menu
location: class net.esial.myplaces.views.AddressBarFragment
[ERROR] /Users/bourgona/Project/my-  places/src/net/esial/myplaces/views/AddressBarFragment.java:[65,44] cannot find symbol
symbol  : class MenuInflater
location: class net.esial.myplaces.views.AddressBarFragment
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/controllers/AddressAutoCompleteAdapter.java:[10,25] cannot find   symbol
symbol  : class R
location: package net.esial.myplaces
[ERROR] /Users/bourgona/Project/my-  places/src/net/esial/myplaces/views/PlacesActivity.java:[3,33] package   com.actionbarsherlock.view does not exist
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[4,33] package  com.actionbarsherlock.view does not exist
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/PlacesActivity.java:[8,25] cannot find symbol
symbol  : class R
location: package net.esial.myplaces
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[13,7] cannot access  com.actionbarsherlock.app.SherlockFragmentActivity
class file for com.actionbarsherlock.app.SherlockFragmentActivity not found
public class PlacesActivity extends RoboSherlockFragmentActivity {
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[32,39] cannot find symbol
symbol  : class Menu
location: class net.esial.myplaces.views.PlacesActivity
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[32,2] cannot find symbol
symbol  : variable super
location: class net.esial.myplaces.views.AddressBarFragment
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[36,57] package R does not exist
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[36,10] cannot find symbol
symbol  : method getLayoutInflater(android.os.Bundle)
location: class net.esial.myplaces.views.AddressBarFragment
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[53,2] cannot find symbol
symbol  : variable this
location: class net.esial.myplaces.views.AddressBarFragment
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[30,1] method does not override or  implement a method from a supertype
[ERROR] /Users/bourgona/Project/my-  places/src/net/esial/myplaces/views/AddressBarFragment.java:[56,1] method does not override or  implement a method from a supertype
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[67,23] package R does not exist
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[64,1] method does not override or  implement a method from a supertype
[ERROR] /Users/bourgona/Project/my-  places/src/net/esial/myplaces/controllers/AddressAutoCompleteAdapter.java:[40,13] package R   does not exist
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/controllers/AddressAutoCompleteAdapter.java:[129,54] package R  does not exist
[ERROR] /Users/bourgona/Project/my-  places/src/net/esial/myplaces/views/PlacesActivity.java:[21,8] cannot find symbol
symbol  : variable super
location: class net.esial.myplaces.views.PlacesActivity
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/PlacesActivity.java:[22,24] package R does not exist
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/PlacesActivity.java:[25,42] cannot find symbol
symbol  : method getSupportFragmentManager()
location: class net.esial.myplaces.views.PlacesActivity
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[27,27] cannot find symbol
symbol  : method add(net.esial.myplaces.views.AddressBarFragment,java.lang.String)
location: class android.support.v4.app.FragmentTransaction
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[18,4] method does not override or  implement a method from a supertype
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[34,8] cannot find symbol
symbol  : class MenuInflater
location: class net.esial.myplaces.views.PlacesActivity
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[34,32] cannot find symbol
symbol  : method getSupportMenuInflater()
location: class net.esial.myplaces.views.PlacesActivity
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[35,26] package R does not exist
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[31,4] method does not override or   implement a method from a supertype
[INFO] 31 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.914s
[INFO] Finished at: Sun Jun 03 19:54:15 PDT 2012
[INFO] Final Memory: 12M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5:compile  (default-compile) on project my-places: Compilation failure: Compilation failure:
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[3,25] cannot find symbol
[ERROR] symbol  : class R
[ERROR] location: package net.esial.myplaces
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[8,33] package com.actionbarsherlock.view does not exist
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[9,33] package  com.actionbarsherlock.view does not exist
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[22,7] cannot access  com.actionbarsherlock.app.SherlockFragment
[ERROR] class file for com.actionbarsherlock.app.SherlockFragment not found
[ERROR] public class AddressBarFragment extends RoboSherlockFragment {
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[65,33] cannot find symbol
[ERROR] symbol  : class Menu
[ERROR] location: class net.esial.myplaces.views.AddressBarFragment
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/AddressBarFragment.java:[65,44] cannot find symbol
[ERROR] symbol  : class MenuInflater
[ERROR] location: class net.esial.myplaces.views.AddressBarFragment
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/controllers/AddressAutoCompleteAdapter.java:[10,25] cannot find  symbol
[ERROR] symbol  : class R
[ERROR] location: package net.esial.myplaces
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[3,33] package  com.actionbarsherlock.view does not exist
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[4,33] package  com.actionbarsherlock.view does not exist
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[8,25] cannot find symbol
[ERROR] symbol  : class R
[ERROR] location: package net.esial.myplaces
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[13,7] cannot access com.actionbarsherlock.app.SherlockFragmentActivity
[ERROR] class file for com.actionbarsherlock.app.SherlockFragmentActivity not found
[ERROR] public class PlacesActivity extends RoboSherlockFragmentActivity {
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/PlacesActivity.java:[32,39] cannot find symbol
[ERROR] symbol  : class Menu
[ERROR] location: class net.esial.myplaces.views.PlacesActivity
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/AddressBarFragment.java:[32,2] cannot find symbol
[ERROR] symbol  : variable super
[ERROR] location: class net.esial.myplaces.views.AddressBarFragment
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/AddressBarFragment.java:[36,57] package R does not exist
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/AddressBarFragment.java:[36,10] cannot find symbol
[ERROR] symbol  : method getLayoutInflater(android.os.Bundle)
[ERROR] location: class net.esial.myplaces.views.AddressBarFragment
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/AddressBarFragment.java:[53,2] cannot find symbol
[ERROR] symbol  : variable this
[ERROR] location: class net.esial.myplaces.views.AddressBarFragment
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/AddressBarFragment.java:[30,1] method does not override or  implement a method from a supertype
[ERROR] /Users/bourgona/Project/my-  places/src/net/esial/myplaces/views/AddressBarFragment.java:[56,1] method does not override or  implement a method from a supertype
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[67,23] package R does not exist
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/AddressBarFragment.java:[64,1] method does not override or  implement a method from a supertype
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/controllers/AddressAutoCompleteAdapter.java:[40,13] package R does not exist
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/controllers/AddressAutoCompleteAdapter.java:[129,54] package R does not exist
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[21,8] cannot find symbol
[ERROR] symbol  : variable super
[ERROR] location: class net.esial.myplaces.views.PlacesActivity
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/PlacesActivity.java:[22,24] package R does not exist
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/PlacesActivity.java:[25,42] cannot find symbol
[ERROR] symbol  : method getSupportFragmentManager()
[ERROR] location: class net.esial.myplaces.views.PlacesActivity
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/PlacesActivity.java:[27,27] cannot find symbol
[ERROR] symbol  : method add(net.esial.myplaces.views.AddressBarFragment,java.lang.String)
[ERROR] location: class android.support.v4.app.FragmentTransaction
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/PlacesActivity.java:[18,4] method does not override or implement a method from a supertype
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/PlacesActivity.java:[34,8] cannot find symbol
[ERROR] symbol  : class MenuInflater
[ERROR] location: class net.esial.myplaces.views.PlacesActivity
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/PlacesActivity.java:[34,32] cannot find symbol
[ERROR] symbol  : method getSupportMenuInflater()
[ERROR] location: class net.esial.myplaces.views.PlacesActivity
[ERROR] /Users/bourgona/Project/my- places/src/net/esial/myplaces/views/PlacesActivity.java:[35,26] package R does not exist
[ERROR] /Users/bourgona/Project/my-places/src/net/esial/myplaces/views/PlacesActivity.java:[31,4] method does not override or implement a method from a supertype
[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.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the  following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

我的配置有什么问题?

更新

添加后<packaging>apk</packaging>我收到此错误:

[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Lcom/google/inject/AbstractModule;
[INFO]  at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[INFO]  at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[INFO]  at com.android.dx.command.dexer.Main.processClass(Main.java:486)
[INFO]  at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
[INFO]  at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[INFO]  at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[INFO]  at com.android.dx.command.dexer.Main.processOne(Main.java:418)
[INFO]  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[INFO]  at com.android.dx.command.dexer.Main.run(Main.java:206)
[INFO]  at com.android.dx.command.dexer.Main.main(Main.java:174)
[INFO]  at com.android.dx.command.Main.main(Main.java:95)
[INFO] 1 error; aborting
4

1 回答 1

3

在 yorkw 的帮助下,我终于可以用 maven 编译我的项目了。该already added: Lcom/google/inject/AbstractModule错误是由于对 guice-no_aop 的多重依赖造成的。

首先 roboguice 2.0 依赖于 guice-no_aop 所以我删除了这部分:

<dependency>
    <groupId>com.google.inject</groupId>
    <artifactId>guice</artifactId>
    <version>3.0</version>
    <classifier>no_aop</classifier>
</dependency> 

此外 guice-multibindings 和 guice-assistedinject 也依赖于 guice-no_aop 但不完全相同的版本。在这个问题上讨论了一个类似的问题,所以我将它添加到 guice-multibindings 和 guice-assistedinject 依赖项中:

<exclusions>
    <exclusion>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
    </exclusion>
</exclusions>

作为记录,我的最后一个 pom 是:

<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.github.armelbd</groupId>
<artifactId>my-places</artifactId>
<version>0.1-SNAPSHOT</version>
<name>MyPlaces</name>
<packaging>apk</packaging>
<url>https://github.com/armelbd/my-places</url>

<issueManagement>
    <url>https://github.com/armelbd/my-places/issues</url>
    <system>GitHub Issues</system>
</issueManagement>

<licenses>
    <license>
        <name>Apache V2</name>
        <url>http://www.apache.org/licenses/LICENSE-2.0</url>
        <distribution>repo</distribution>
    </license>
</licenses>

<scm>
    <url>https://github.com/armelbd/my-places</url>
    <connection>scm:git:git://github.com/armelbd/my-places.git</connection>
    <developerConnection>scm:git:git@github.com:armelbd/my-places.git</developerConnection>
</scm>

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 

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

    <!-- Dependency injection using Roboguice and Google Guice extensions -->
    <dependency>
        <groupId>org.roboguice</groupId>
        <artifactId>roboguice</artifactId>
        <version>2.0</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.google.inject.extensions</groupId>
        <artifactId>guice-multibindings</artifactId>
        <version>3.0</version>
        <exclusions>
            <exclusion>
                <groupId>com.google.inject</groupId>
                <artifactId>guice</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.google.inject.extensions</groupId>
        <artifactId>guice-assistedinject</artifactId>
        <version>3.0</version>
        <exclusions>
            <exclusion>
                <groupId>com.google.inject</groupId>
                <artifactId>guice</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- Action Bar sherlock -->
    <dependency>
        <groupId>com.actionbarsherlock</groupId>
        <artifactId>library</artifactId>
        <version>4.0.0</version>
        <type>apklib</type>
    </dependency>

    <!-- Let Roboguice and Sherlock work together -->
    <dependency>
        <groupId>com.github.rtyley</groupId>
        <artifactId>roboguice-sherlock</artifactId>
        <version>1.4</version>
    </dependency>
</dependencies>

<build>
    <finalName>${project.artifactId}</finalName>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
       <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5</version>
            <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>
            <version>3.0.0</version>
            <extensions>true</extensions>
            <configuration>
                <sdk>
                    <platform>15</platform>
                </sdk>
            </configuration>
        </plugin>
    </plugins>
</build>

于 2012-06-04T06:35:00.940 回答