Maven + android R.java和BuildConfig.java复制类

时间:2014-02-28 10:04:56

标签: android maven maven-3 apklib buildconfig

我在互联网上搜索解决方案并做了所有提到的但没有解决我的问题。

这是我的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

2 个答案:

答案 0 :(得分:0)

删除此行:

<source>gen</source> 

答案 1 :(得分:0)

当有两个构建系统在同一代码库上工作时,通常会发生这种情况,为生成的代码配置了不同的位置(例如,Eclipse,Maven等)。在这种情况下,这些生成的类将在两个不同的位置创建。就我而言,我在<project>\gen<project>\target\generated-sources\r目录下有这些文件。因此,清洁&#34; gen&#34;和&#34;目标&#34;在构建之前有助于解决此重复的类问题。

参考:Android source build: duplicate class