2014-02-28 156 views
1

我在網上搜索瞭解決方案,並做了所有提到的事情,但沒有任何解決我的問題。Maven + android R.java和BuildConfig.java重複類

這裏是我的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.myproject.xcommon</groupId> 
    <artifactId>xcommon</artifactId> 
    <name>xcommon</name> 
    <packaging>apklib</packaging> 
    <version>1.0.0</version> 


    <dependencies> 

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

     <dependency> 
      <groupId>com.google.android</groupId> 
      <artifactId>support-v4</artifactId> 
      <version>r7</version> 
     </dependency> 

     <dependency> 
      <groupId>de.mindpipe.android</groupId> 
      <artifactId>android-logging-log4j</artifactId> 
      <version>1.0.2</version> 
     </dependency> 

     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.16</version> 
     </dependency> 

     <dependency> 
      <groupId>org.apache.httpcomponents</groupId> 
      <artifactId>httpmime</artifactId> 
      <version>4.1.1</version> 
     </dependency> 

     <dependency> 
      <groupId>org.apache.httpcomponents</groupId> 
      <artifactId>httpclient</artifactId> 
      <version>4.1.1</version> 
     </dependency> 

     <dependency> 
      <groupId>com.google.code.gson</groupId> 
      <artifactId>gson</artifactId> 
      <version>2.2.4</version> 
     </dependency> 

    </dependencies> 

    <repositories> 
     <repository> 
      <id>my-internal-site</id> 
      <url>file:///C:\Users\mustafa.guven\.m2\repository</url> 
     </repository> 
    </repositories> 

    <build> 
     <sourceDirectory>src</sourceDirectory> 
     <outputDirectory>target</outputDirectory> 
     <plugins> 
      <plugin> 
       <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
       <artifactId>android-maven-plugin</artifactId> 
       <version>3.8.2</version> 
       <configuration> 
        <sdk> 
         <platform>${android.sdk.platform}</platform> 
         <path>${android.sdk.path}</path> 
        </sdk> 
        <dexOptimize>false</dexOptimize> 
        <dex> 
         <preDex>false</preDex> 
         <preDexLibLocation>/tmp/predexedLibs</preDexLibLocation> 
        </dex> 
        <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile> 
        <assetsDirectory>${project.basedir}/assets</assetsDirectory> 
        <resourceDirectory>${project.basedir}/res</resourceDirectory> 
        <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory> 
        <undeployBeforeDeploy>true</undeployBeforeDeploy> 
       </configuration> 
       <extensions>true</extensions> 
      </plugin> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.1</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>build-helper-maven-plugin</artifactId> 
       <executions> 
        <execution> 
         <phase>generate-sources</phase> 
         <goals><goal>add-source</goal></goals> 
         <configuration> 
          <sources> 
           <source>gen</source> 
           <source>res</source> 
          </sources> 
         </configuration> 
        </execution> 

       </executions> 

      </plugin> 
     </plugins> 
    </build> 
</project> 

,這裏是錯誤

[ERROR] COMPILATION ERROR : 
[INFO] ------------------------------------------------------------- 
[ERROR] /D:/Projects/MavenProject/Android/Libraries/trunk/XCommon/gen/eu/myproject/common/R.java:[6,14] duplicate class: eu.myproject.common.R 
[ERROR] /D:/Projects/MavenProject/Android/Libraries/trunk/XCommon/gen/eu/myproject/common/BuildConfig.java:[6,14] duplicate class: eu.myproject.common.BuildConfig 
[INFO] 2 errors 
[INFO] ------------------------------------------------------------- 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 23.917s 
[INFO] Finished at: Fri Feb 28 11:00:23 EET 2014 
[INFO] Final Memory: 24M/221M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project XCommon: Compilation failure: Compilation failure: 
[ERROR] /D:/Projects/MavenProject/Android/Libraries/trunk/XCommon/gen/eu/myproject/common/R.java:[6,14] duplicate class: eu.myproject.common.R 
[ERROR] /D:/Projects/MavenProject/Android/Libraries/trunk/XCommon/gen/eu/myproject/common/BuildConfig.java:[6,14] duplicate class: eu.myproject.common.BuildConfig 
[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 
D:\Projects\MavenProject\Android\Libraries\trunk\XCommon>mvn clean package 

回答

0

刪除此行:

<source>gen</source> 
0

當有做兩份構建系統這通常發生在相同的代碼庫上,爲生成的代碼配置不同的位置(例如Eclipse,Maven等)。在這種情況下,這些生成的類將在兩個不同的位置創建。在我的情況下,我有這些文件在<project>\gen<project>\target\generated-sources\r目錄下。因此,在構建之前清理「gen」和「target」有助於解決此類重複的類問題。

參考:Android source build: duplicate class

+1

請註明這裏的解決方案的某些部分,不給唯一的鏈接。 – abarisone