8

I have been trying to integrate the Amazon SNS client with an android project.

I am including the library using the following dependency commands

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.amazonaws:aws-java-sdk-sns:1.10.+'
    compile 'com.google.android.gms:play-services:7.5.0'
}

Thus it automatically includes the above library (and its dependencies : aws_java_sdk_core and aws_java_sdk_sqs). All 3 libraries have a version 1.10.2.

The problem is that the AWS core has two modules

  1. commons-logging (commons-logging:commons-logging:1.1.3)
  2. httpclient (org.apache.httpcomponents:httpclient:4.3.6)

As android has the same packages internally, it excludes these modules to avoid any conflict. The result is that when the aws code tries to access some classes from these modules. Tt is expecting a different version of it, does not find the expected method, and crashes the application.

Is there any way to override android's exclude? (Or is there a better way to handle this situation?)

EDIT: Added gradle log :

WARNING: Dependency commons-logging:commons-logging:1.1.3 is ignored for debug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.6 is ignored for debug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency commons-logging:commons-logging:1.1.3 is ignored for release as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.6 is ignored for release as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
Sainath Krishnan
  • 2,089
  • 7
  • 28
  • 43

2 Answers2

1

Since you are working on an Android project, please consider use AWS SDK for Android. It's optimized for Android platform. It has smaller libraries, fewer dependencies, and other optimizations. It should solve the conflicting problem. Check out the developer guide.

It's just as simple as updating the dependency to compile 'com.amazonaws:aws-android-sdk-sns:2.2.+'. It's usage should be compatible with that of Java SDK.

Yangfan
  • 1,866
  • 1
  • 11
  • 13
  • Apologies for the delay, we tried this by including the core, which did not solve the issue. Using the SDK itself is out of the question, as the App in question is nearly complete already! – Sainath Krishnan Jul 13 '15 at 09:53
  • Not sure why using the AWS SDK for Android has been ruled out. It's just as simple as updating the dependency to compile 'com.amazonaws:aws-android-sdk-sns:2.2.+'. It's usage should be compatible with that of Java SDK. – Yangfan Jul 13 '15 at 14:45
0

Did you try to exclude dependencies that are conflicting ? Since they are available in both of the libraries, you can choose to ignore one, and that should work fine.

dependencies {

        ...
        compile ('com.amazonaws:aws-java-sdk-sns:1.10.2') {
            exclude group: 'commons-logging', module: 'commons-logging'
        }
        compile ('com.amazonaws:aws-java-sdk-sns:1.10.2') {
            exclude group: 'org.apache.httpcomponents', module: 'httpclient'
        }
        ....
}

(I have used indicative names for groups and modules to exclude, you may try out exact names, thought it should work)

Very useful link that shows how to exclude using, Artifact name, module and both module & artifact.

Check this reference answer as well

Community
  • 1
  • 1
Darpan
  • 5,623
  • 3
  • 48
  • 80
  • This won't work. AWS SDK for Java has a hard dependency of Apache HttpClient 4.3 or later which isn't available on Android. You may get it compiled, but you will see ClassNotFoundException when you run the app. – Yangfan Jul 21 '15 at 18:51
  • I've already proposed the solution. It's better to use AWS SDK for Android http://aws.amazon.com/mobile/sdk/. It irons out dependency issues. Just not sure why the original author wants to stick to the Java version. – Yangfan Jul 22 '15 at 22:30