Domanda

I searched for the solution on the internet and did everything which is mentioned but nothing did solve my problem.

Here is my 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>

and here is the error

[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
È stato utile?

Soluzione

Remove this line:

<source>gen</source> 

Altri suggerimenti

This usually happens when there are two build systems working on the same code base, configured with different locations for generated code (for example, Eclipse, Maven, etc.). In such scenarios, these generated classes would get created in two different locations. In my case, I had these files under <project>\gen and <project>\target\generated-sources\r directories. So cleaning both the "gen" and "target" before the build helps resolve this duplicate class issue.

Reference: Android source build: duplicate class

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top