Troubleshooting - Dependencies

To avoid clashes resulting from the dependencies included in our libraries, ForeSee has relocated some of the smaller dependencies, but requires you to include some dependencies in your app to support the SDK.

Required dependencies

You will  need to add the following libraries to your project to support the ForeSee SDK:

  • com.google.code.gson:gson v2.2.4
  • org.apache.httpcomponents:httpmime v4.2.2
  • org.roboguice:roboguice v2.0
  • com.android.support:support-v4 v22.2.1

If you use Gradle or Maven, please see the instructions below for adding these dependencies and be sure to check out the conflict avoidance tips that follow.

Adding dependencies using Gradle

To add the dependencies, add the following to your build.gradle:

dependencies {
  compile 'com.google.code.gson:gson:2.2.4'
  compile 'org.apache.httpcomponents:httpmime:4.2.2' 
  compile 'org.roboguice:roboguice:2.0'
  compile 'com.android.support:support-v4:22.2.1'
}

You should also add the following exclusions:

android {
  packagingOptions {
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/LICENSE.txt'
  }
}

Dealing with dependency conflicts when using Gradle

After adding dependencies, you may encounter dependency conflicts. These can be resolved using the following tips:

If you receive Duplicate files copied in APK META-INF/DEPENDENCIES
The files contained in the META-INF folder do not affect app function and can be excluded. Add the following lines to your build.gradle:

android {
  packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
  }
}

You can add multiple exclusions here to deal with as many duplicate files as come up during your build.

If you receive java.util.zip.ZipException: duplicate entry:<CLASS NAME>
This happens when one of the dependencies (indicated by <CLASS NAME>) has already been added elsewhere. You’ll need to identify which library is duplicated by inspecting the package structure of <CLASS NAME> then remove one of the references to that library. This should be as simple as removing one of the lines mentioned above.

Adding dependencies using Maven

Dependencies can be added in Maven using the markup below:

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.2.4</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpmime</artifactId>
    <version>4.2.2</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.roboguice</groupId>
    <artifactId>roboguice</artifactId>
    <version>2.0</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>com.android.support</groupId>
    <artifactId>support-v4</artifactId>
    <version>22.2.1</version>
    <scope>compile</scope>
</dependency>

Dealing with dependency conflicts when using Maven

If you receive java.lang.NoClassDefFoundError: Failed resolution of: <CLASS NAME>
This indicates that a package is missing. You’ll need to identify which package it is from <CLASS NAME> and add in the relevant dependency.

If you receive java.lang.IllegalArgumentException: already added: <CLASS NAME>
This indicates that a library has been added as a dependency in two separate places. To resolve the conflict, you must find out what library is indicated by the package descriptor in <CLASS NAME> and remove it from the dependencies you included from the list above.

It’s also possible in Maven to exclude part of a dependency using the <exclusions> tag, eg:

<dependency>
    <groupId>com.actionbarsherlock</groupId>
        <artifactId>library</artifactId>
        <version>4.2.0</version>
        <type>apklib</type>
        <exclusions>
            <exclusion>
                <groupId>com.google.android</groupId>
                <artifactId>support-v4</artifactId>
        </exclusion>
    </exclusions>
</dependency>        

If you receive java.lang.NoClassDefFoundError: Failed resolution of: <CLASS NAME>
This indicates that a package is missing. You’ll need to identify which package it is from <CLASS NAME> and add in the relevant dependency.

Other articles in this section:

  1. Android N
  2. Debugging
  3. Disabling the SDK
  4. Common Problems
  5. Dependencies (current article)