How to solve android build already added exception

When we build android application , sometimes we got xxx already added exception ,and this is an example to show how to solve it.

1. The exception

When we build the app, and then we got this:

[INFO] Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/commons/logging/Log;
[INFO] Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/commons/logging/LogConfigurationException;
[INFO] Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/commons/logging/LogFactory;
[INFO] Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/commons/logging/LogSource;
[INFO] Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/commons/logging/impl/Jdk14Logger;
[INFO] Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/commons/logging/impl/LogFactoryImpl;
[INFO] Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/commons/logging/impl/NoOpLog;
[INFO] Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/commons/logging/impl/SimpleLog;
[INFO] Uncaught translation error: java.lang.IllegalArgumentException: already added: Lorg/apache/commons/logging/impl/WeakHashtable;

2. The solution

You can just do as follows:

  • Use maven dependency tree to check which depends on the commons-logging, the command:
mvn dependency:tree -Dverbose -Dincludes=commons-logging
  • find the objects that depend on the commons-logging, then add this to pom.xml
<dependency>
    <groupId>com.viewpagerindicator</groupId>
    <artifactId>library</artifactId>
    <version>2.4.1</version>
    <type>apklib</type>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>

As the code shown, I add an exclusion on the artifact that has transitive dependency on the commons-logging. And you must also copy the exclusion code to all the other artifacts that have the same transitive dependencies on the commons-logging.

You can find detail documents about the android here: