Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dex fails because a BuildConfig class from an aar lib is there twice #326

Closed
Shusshu opened this issue Apr 10, 2014 · 22 comments
Closed

dex fails because a BuildConfig class from an aar lib is there twice #326

Shusshu opened this issue Apr 10, 2014 · 22 comments

Comments

@Shusshu
Copy link
Member

Shusshu commented Apr 10, 2014

What steps will reproduce the problem?

Adding the following lib: https://github.com/jgilfelt/SystemBarTint

<dependency>
    <groupId>com.readystatesoftware.systembartint</groupId>
    <artifactId>systembartint</artifactId>
    <version>1.0.2</version>
    <type>aar</type>
</dependency>

OR the appcompat-v7 lib

<dependency>
  <groupId>com.android.support</groupId>
  <artifactId>appcompat-v7</artifactId>
  <version>19.1.0</version>
  <type>aar</type>
</dependency>

What is the expected output?

Build Success

What do you see instead?

[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Lcom/readystatesoftware/systembartint/BuildConfig;

What version of maven-android-plugin are you using?

3.9.0-rc.1 & current 3.9.0-SNAPSHOT (2014/04/10)

What are the complete output lines of "mvn -version" on your machine?

3.2.1
java 1.7.0_51

Please provide any additional information below.

In this library the BuildConfig is included in the aar (classes.jar)
But for ActionBarSherlock the BuildConfig is not included in the aar (based on comments in the GenerateSourcesMojo).

Should the aar contain the BuildConfig or should android-maven-plugin generate it or should it check if it needs to generate it or not?

Sample project: https://maven-android-plugin.googlecode.com/issues/attachment?aid=4560002000&name=tictactoe.rar&token=koNVAMhc7WzZFlNalJ57WBs2DEc%3A1397132888054

Previous tracker ticket: 456 https://code.google.com/p/maven-android-plugin/issues/detail?id=456

@Shusshu
Copy link
Member Author

Shusshu commented Apr 14, 2014

I see 2 ways to fix the problem.

A. Removing the following code in generateBuildConfig method. (Non backwards compatible)

    // Generate the BuildConfig for any APKLIB and AAR dependencies.
    // Need to generate for AAR, because some old AARs like ActionBarSherlock do not have BuildConfig (or R)
        for ( Artifact artifact : getTransitiveDependencyArtifacts( APKLIB, AAR ) )
        {
            final File manifest = new File( getUnpackedLibFolder( artifact ), "AndroidManifest.xml" );
            final String depPackageName = extractPackageNameFromAndroidManifest( manifest );
            generateBuildConfigForPackage( depPackageName );
        }

And also include the BuildConfig.class in the aar

B. Making the code in generateBuildConfig to generate BuildConfig only if it's not present in the classes.jar (backwards compatible)
And also include the BuildConfig.class in the aar

So the first way isn't backwards compatible but is the proper way to do it.

Shusshu pushed a commit to Shusshu/maven-android-plugin that referenced this issue Apr 14, 2014
Do not generate BuildConfig for aar libs

See simpligility#326

Solution 1
@Shusshu
Copy link
Member Author

Shusshu commented Apr 14, 2014

#328 implement solution 1.

I will look into solution 2 to ensure backwards compatibility

Shusshu pushed a commit to Shusshu/maven-android-plugin that referenced this issue Apr 14, 2014
@Shusshu
Copy link
Member Author

Shusshu commented Apr 24, 2014

Merged -> closing

@Shusshu Shusshu closed this as completed Apr 24, 2014
oleggreen pushed a commit to oleggreen/maven-android-plugin that referenced this issue Apr 26, 2014
Do not generate BuildConfig for aar libs

See simpligility#326

Solution 1
oleggreen pushed a commit to oleggreen/maven-android-plugin that referenced this issue Apr 26, 2014
@gabriel01
Copy link

Hey,

when I compile with version 3.8.2 I get the reported error:

[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Lcom/readystatesoftware/systembartint/BuildConfig;

But when using 3.9.0-rc.2 I'll get the following error in my library project:
Error: No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').

With 3.8.2 all my library projects build successful. Is this a new bug or a misconfiguration on my site?

@Shusshu
Copy link
Member Author

Shusshu commented Jun 11, 2014

It's another problem:

"Error: No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version')."

Look at http://stackoverflow.com/a/19723969/1228221

@gabriel01
Copy link

The manifest entry is set. The app project and all libraries build successfully in Eclipse. The library projects also build successfully with Maven 3.8.2. But the app project fails with 3.8.2.
Using 3.9.0-rc.2 leads to the missing value error. But I haven't changed anything in the manifest?!

@william-ferguson-au
Copy link
Contributor

Post a link to a cut down project that fails.

On Thu, Jun 12, 2014 at 3:49 AM, gabriel01 notifications@github.com wrote:

The manifest entry is set. The app project and all libraries build
successfully in Eclipse. The library projects also build successfully with
Maven 3.8.2. But the app project fails with 3.8.2.
Using 3.9.0-rc.2 leads to the missing value error. But I haven't changed
anything in the manifest?!


Reply to this email directly or view it on GitHub
#326 (comment)
.

@sensorcast
Copy link

I've spent a couple of hours on his now as well.
Maven dependencies:

com.google.android
android
4.3
provided

<dependency>
  <groupId>com.android.support</groupId>
  <artifactId>appcompat-v7</artifactId>
  <version>19.1.0</version>
  <type>apklib</type>
</dependency>
<dependency>
  <groupId>com.android.support</groupId>
  <artifactId>appcompat-v7</artifactId>
  <version>19.1.0</version>
  <type>jar</type>
</dependency>

Plugin def:

com.jayway.maven.plugins.android.generation2
android-maven-plugin
3.9.0-rc.2


${env.ANDROID_HOME}
18


false

true

true

The error:
[INFO] --- android-maven-plugin:3.9.0-rc.2:dex (default-dex) @ sensorcast-android-datalogger ---
[INFO] Convert classes to Dex : /home/jeffp/Workspace/GSW/gsw-main/gsw-main/gsw-datalogger-android/target/classes.dex
[INFO]
[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Landroid/support/v7/appcompat/BuildConfig;
[INFO] at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
[INFO] at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
[INFO] at com.android.dx.command.dexer.Main.processClass(Main.java:685)
[INFO] at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
[INFO] at com.android.dx.command.dexer.Main.access$600(Main.java:78)
[INFO] at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
[INFO] at com.android.dx.command.dexer.Main.processOne(Main.java:596)
[INFO] at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
[INFO] at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
[INFO] at com.android.dx.command.dexer.Main.run(Main.java:230)
[INFO] at com.android.dx.command.dexer.Main.main(Main.java:199)
[INFO] at com.android.dx.command.Main.main(Main.java:103)
[INFO] 1 error; aborting
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.297 s
[INFO] Finished at: 2014-06-11T22:01:59-08:00
[INFO] Final Memory: 29M/858M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.9.0-rc.2:dex (default-dex) on project sensorcast-android-datalogger: MojoExecutionException: ANDROID-040-001: Could not execute: Command = /bin/sh -c cd /home/jeffp/Workspace/GSW/gsw-main/gsw-main/gsw-datalogger-android && /opt/java/jdk1.7.0_11/jre/bin/java -Xmx1024M -jar /opt/android/current-version/build-tools/19.0.3/lib/dx.jar --dex --output=/home/jeffp/Workspace/GSW/gsw-main/gsw-main/gsw-datalogger-android/target/classes.dex /home/jeffp/.m2/repository/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar /home/jeffp/.m2/repository/com/wonkware/ww-core-android/1.0.0-SNAPSHOT/ww-core-android-1.0.0-SNAPSHOT.jar /home/jeffp/.m2/repository/org/sensorcast/sensorcast-android-core/1.0.0-SNAPSHOT/sensorcast-android-core-1.0.0-SNAPSHOT.jar /home/jeffp/.m2/repository/com/android/support/appcompat-v7/19.1.0/appcompat-v7-19.1.0.jar /home/jeffp/.m2/repository/org/simpleframework/simple-xml/2.7.1/simple-xml-2.7.1.jar /home/jeffp/.m2/repository/com/android/support/support-v4/19.1.0/support-v4-19.1.0.jar /home/jeffp/.m2/repository/com/wonkware/ww-core/1.0.0-SNAPSHOT/ww-core-1.0.0-SNAPSHOT.jar /home/jeffp/.m2/repository/org/sensorcast/sensorcast-model/1.0.0-SNAPSHOT/sensorcast-model-1.0.0-SNAPSHOT.jar /home/jeffp/Workspace/GSW/gsw-main/gsw-main/gsw-datalogger-android/target/classes

Good instructions regarding how to use the plugin OR how to craft the right dependency type (.aar, .apklib) and wire it all up are hard to come by.

@william-ferguson-au
Copy link
Contributor

Why are you providing a dependency on the apklib AND the jar? A dep on the apklib should be sufficient. And again, without a link to a project that is failing it becomes just guesswork for us to try and diagnose.

@sensorcast
Copy link

I've cobbled together this much from the web. Like I said the docs are not clear.

If I take out the library then I get all kinds of errors it can't find anything. BUT, your question makes me think the apklib is bundled improperly. There were 2 sets of instructions: deploy the .aar file, google provides in the extras, as is, declaring it an apklib; and the "zip the project" version. I need to go back and verify this. (but I must sleep first.)

The project is not in github yet.

@Shusshu
Copy link
Member Author

Shusshu commented Jun 12, 2014

Try aar instead of apklib. it's better anyway.

    <dependency>
        <groupId>com.android.support</groupId>
        <artifactId>appcompat-v7</artifactId>
        <version>19.1.0</version>
        <type>aar</type>
    </dependency>

@sensorcast
Copy link

Using just the .aar:
[INFO] --- android-maven-plugin:3.9.0-rc.2:dex (default-dex) @ sensorcast-android-datalogger ---
[INFO] Convert classes to Dex : /home/jeffp/Workspace/GSW/gsw-main/gsw-main/gsw-datalogger-android/target/classes.dex
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25.135 s
[INFO] Finished at: 2014-06-12T10:41:09-08:00
[INFO] Final Memory: 22M/481M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.9.0-rc.2:dex (default-dex) on project sensorcast-android-datalogger: MojoExecutionException: ANDROID-040-001: Could not execute: Command = /bin/sh -c cd /home/jeffp/Workspace/GSW/gsw-main/gsw-main/gsw-datalogger-android && /opt/java/jdk1.7.0_11/jre/bin/java -Xmx1024M -jar /opt/android/current-version/build-tools/19.0.3/lib/dx.jar --dex --output=/home/jeffp/Workspace/GSW/gsw-main/gsw-main/gsw-datalogger-android/target/classes.dex /home/jeffp/.m2/repository/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar /home/jeffp/.m2/repository/com/wonkware/ww-core-android/1.0.0-SNAPSHOT/ww-core-android-1.0.0-SNAPSHOT.jar /home/jeffp/Workspace/GSW/gsw-main/gsw-main/gsw-datalogger-android/target/unpacked-libs/cas_appcompat-v7/classes.jar /home/jeffp/.m2/repository/org/sensorcast/sensorcast-android-core/1.0.0-SNAPSHOT/sensorcast-android-core-1.0.0-SNAPSHOT.jar /home/jeffp/.m2/repository/org/simpleframework/simple-xml/2.7.1/simple-xml-2.7.1.jar /home/jeffp/.m2/repository/com/android/support/support-v4/19.1.0/support-v4-19.1.0.jar /home/jeffp/.m2/repository/com/wonkware/ww-core/1.0.0-SNAPSHOT/ww-core-1.0.0-SNAPSHOT.jar /home/jeffp/.m2/repository/org/sensorcast/sensorcast-model/1.0.0-SNAPSHOT/sensorcast-model-1.0.0-SNAPSHOT.jar /home/jeffp/Workspace/GSW/gsw-main/gsw-main/gsw-datalogger-android/target/classes, Result = 1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.9.0-rc.2:dex (default-dex) on project sensorcast-android-datalogger:
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException:
at com.jayway.maven.plugins.android.phase08preparepackage.DexMojo.runDex(DexMojo.java:467)
at com.jayway.maven.plugins.android.phase08preparepackage.DexMojo.execute(DexMojo.java:171)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
Caused by: com.jayway.maven.plugins.android.ExecutionException: ANDROID-040-001: Could not execute: Command = /bin/sh -c cd /home/jeffp/Workspace/GSW/gsw-main/gsw-main/gsw-datalogger-android && /opt/java/jdk1.7.0_11/jre/bin/java -Xmx1024M -jar /opt/android/current-version/build-tools/19.0.3/lib/dx.jar --dex --output=/home/jeffp/Workspace/GSW/gsw-main/gsw-main/gsw-datalogger-android/target/classes.dex /home/jeffp/.m2/repository/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar /home/jeffp/.m2/repository/com/wonkware/ww-core-android/1.0.0-SNAPSHOT/ww-core-android-1.0.0-SNAPSHOT.jar /home/jeffp/Workspace/GSW/gsw-main/gsw-main/gsw-datalogger-android/target/unpacked-libs/cas_appcompat-v7/classes.jar /home/jeffp/.m2/repository/org/sensorcast/sensorcast-android-core/1.0.0-SNAPSHOT/sensorcast-android-core-1.0.0-SNAPSHOT.jar /home/jeffp/.m2/repository/org/simpleframework/simple-xml/2.7.1/simple-xml-2.7.1.jar /home/jeffp/.m2/repository/com/android/support/support-v4/19.1.0/support-v4-19.1.0.jar /home/jeffp/.m2/repository/com/wonkware/ww-core/1.0.0-SNAPSHOT/ww-core-1.0.0-SNAPSHOT.jar /home/jeffp/.m2/repository/org/sensorcast/sensorcast-model/1.0.0-SNAPSHOT/sensorcast-model-1.0.0-SNAPSHOT.jar /home/jeffp/Workspace/GSW/gsw-main/gsw-main/gsw-datalogger-android/target/classes, Result = 1
at com.jayway.maven.plugins.android.CommandExecutor$Factory$DefaultCommandExecutor.executeCommand(CommandExecutor.java:252)
at com.jayway.maven.plugins.android.phase08preparepackage.DexMojo.runDex(DexMojo.java:463)
... 22 more
[ERROR]
[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/MojoExecutionException

@sensorcast
Copy link

Updated android build tools to 19.1.0 and got the same error.

@sensorcast
Copy link

OK, my bad: It suddenly started working. Turns out that it was a transient memory resource problem. On another invocation I went to run maven and got:
mvn -e clean package
Error occurred during initialization of VM
Could not reserve enough space for object heap

@sensorcast
Copy link

I meant to say, it started working with just the .aar dependency. So, now all I'm using is:

com.android.support
appcompat-v7
19.1.0
aar

without the "support-v4" dependency or the "appcompat-v7" .jar dependency.

@sensorcast
Copy link

Apparently. Though it did take a while to sort out the details that the new plugin required a maven update, and the docs are not clear on exactly how to setup the dependencies. You've still got that apklib page off your site https://code.google.com/p/maven-android-plugin/wiki/ApkLib.

@william-ferguson-au
Copy link
Contributor

What Maven update? It will run fine with any version of Maven 3.0+, which is the same as 3.8.2.

I have updated the ApkLib page with a deprecation warning in favour of AAR. It would be good to create a page explaining AR creation/consumption. It's pretty trivial as it's just like any other maven artifact type. Any takers? What about you @sensorcast ?

@sensorcast
Copy link

I was running with Maven 3.0.3 and the plugin spit something out that it was unhappy and needed 3.1 (I think it was 3.1; message is lost at this point). So I installed 3.2.1. (I don't know where you are getting your Maven binaries from but 3.2.1 is listed as the latest: http://maven.apache.org/download.cgi).

As for .aar: I'm not sure I fully understand it myself except to say that I now have a working version/config using Maven 3.2.1, android-maven-plugin 2.9.0-rc-2, Android 19.1.0 build tools, and appcompat-v7 19.1.0 where this was simply rsync'd to our server from the /extras/android/m2repository -- i.e., "sync -av com maven@sensorcast.org:/home/maven/repos/external-free"

@gabriel01
Copy link

Hmm, I replaced the jar/apklib dependency by

com.android.support appcompat-v7 19.1.0 aar Now I get "cannot find symbol : class ActionBarActivity" and "package android.support.v7.app does not exist". But the dependency is definitely. Please find below the pom. Any advice is very appreciated.

<modelVersion>4.0.0</modelVersion>

<groupId>de.velosys.android.lib</groupId>
<artifactId>velosys-common-library</artifactId>
<version>1.0.0</version>
<packaging>apklib</packaging>
<name>Velosys Common Library</name>

<parent>
    <artifactId>master-library</artifactId>
    <groupId>de.velosys.android</groupId>
    <version>1.0.0</version>
    <relativePath>../pom.xml</relativePath>
</parent>



<dependencies>

    <dependency>
        <groupId>android</groupId>
        <artifactId>android</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>de.velosys.android.lib</groupId>
        <artifactId>velosys-compat-library</artifactId>
        <version>1.0.0</version>
        <type>apklib</type>
    </dependency>

    <dependency>
        <groupId>com.google.android.gms</groupId>
        <artifactId>google-play-services</artifactId>
        <version>16.0.0</version>
        <type>apklib</type>
    </dependency>

    <dependency>
        <groupId>com.google.android.gms</groupId>
        <artifactId>google-play-services</artifactId>
        <version>16.0.0</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>com.android.support</groupId>
         <artifactId>appcompat-v7</artifactId>
         <version>19.1.0</version>
         <type>aar</type>
    </dependency>

    <dependency>
        <groupId>net.sourceforge.findbugs</groupId>
        <artifactId>jsr305</artifactId>
        <optional>false</optional>
    </dependency>

    <dependency>
        <groupId>com.google.android.annotations</groupId>
        <artifactId>annotations</artifactId>
        <optional>false</optional>
    </dependency>

    <dependency>
        <groupId>net.sourceforge.findbugs</groupId>
        <artifactId>annotations</artifactId>
        <optional>false</optional>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>google-guava-jdk5</artifactId>
        <optional>false</optional>
    </dependency>

    <dependency>
        <groupId>com.squareup.dagger</groupId>
        <artifactId>dagger</artifactId>
        <optional>false</optional>
    </dependency>

    <dependency>
        <groupId>com.squareup.dagger</groupId>
        <artifactId>dagger-compiler</artifactId>
        <optional>false</optional>
    </dependency>

    <dependency>
        <groupId>com.squareup</groupId>
        <artifactId>javawriter</artifactId>
        <optional>false</optional>
    </dependency>

    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <optional>false</optional>
    </dependency>

    <dependency>
        <groupId>com.google.analytics</groupId>
        <artifactId>google-analytics-services</artifactId>
        <optional>false</optional>
    </dependency>

    <dependency>
        <groupId>com.squareup</groupId>
        <artifactId>otto</artifactId>
        <optional>false</optional>
    </dependency>

</dependencies>


<build>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <sourceDirectory>${project.basedir}/src</sourceDirectory>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
        </plugin>

        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

@greek1979
Copy link
Contributor

I am posting here a duplicate comment to stress the issue I am seeing with latest available 3.9.0-rc.2 plugin version. It seems the code change labelled "Solution 2" by both @Shusshu and @Marchelo never made it into the master branch, as the very same issue brought up and discussed here is still there.

I have an APK project which depends on one AAR library project, which in turn has a dependency on a third-party library shipped as AAR (a well-known Google Play Services v4). Everything compiles and builds well until we get to dex stage of final APK. There, plugin fails because of a Dex tool error - duplicate BuildConfig class found. The BuildConfig for third-party dependency gets packaged into my library AAR, but then it is produced again when building the final APK, as third-party dependency is still there, it is of AAR type, hence it is handled as such (i.e. both R and BuildConfig are dynamically created)..

Could we somehow 1) tell Dex tool to use only one instance of each duplicate class (for example, the first one), or 2) explicitly re-create BuildConfig for each transitive AAR dependency?

Alternatively, may it be possible to simply and brutally filter out existing BuildConfig instances from transitive AAR dependencies when building APK, as they would be re-created anyway by the ApkMojo goal?

@Shusshu
Copy link
Member Author

Shusshu commented Jun 29, 2014

Can you create a new issue with a sample project reproducing the problem? that would help fixing it.

@greek1979
Copy link
Contributor

After spending an hour or so digging through the problem and analyzing whole dependency tree for APK project, two issues were spotted by me. Overall, plugin seems to be doing exactly what it has to, with some minor exceptions I will outline below.

One issue was entirely an in-house edge case, where one of the transitive dependencies was apparently plugged in as both AAR and JAR (legacy of awkward APKLIB support in Eclipse...), with JAR having that nasty already-generated BuildConfig class. As JAR dependencies are not handled in any special way by the plugin - and this is right - the duplicate BuildConfig ended up in APK project.

The other issue is the way plugin checks for presence of BuildConfig in all AAR dependencies. It does a fine job, BUT each time it checks a transitive dependency, its OWN package namespace is used, not the package name of original AAR artifact that is being built.

I have submitted a fairly simply pull request #403 . This does not seem like a big deal, but would be good to apply the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants