Android AWS s3 CognitoCachingCredentialsProvider抛出NoSuchMethodError

时间:2017-06-08 08:08:42

标签: android amazon-s3 androidhttpclient aws-cognito

我正在尝试在aws bucket上传/下载/列出文件。

我在我的片段中编写了以下代码,用于设置凭据,它在行(mActivity.getApplicationContext)处抛出NoSuchMethodErrorException

CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(

               mActivity.getApplicationContext(),   // using in fragments
               "ap-XXXX-X:0XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXb4", // Identity Pool ID
               Regions.AP_XXXX_X // Region
       );

AmazonS3 s3Client = new AmazonS3Client(credentialsProvider) ;

它抛出以下错误:

引起:java.lang.NoSuchMethodError:没有直接方法(Lcom / amazonaws / ClientConfiguration; Lcom / amazonaws / http / HttpClient;)V类Lcom / amazonaws / AmazonWebServiceClient;或其超类('com.amazonaws.AmazonWebServiceClient'的声明出现在/data/app/com.hs.userportal-1/split_lib_dependencies_apk.apk:classes6.dex)

这是我的gradle文件:

apply plugin: 'com.android.application'

android {

    compileSdkVersion 24
    buildToolsVersion '25.0.3'
    useLibrary 'org.apache.http.legacy'
    dexOptions {

        javaMaxHeapSize "4g"
    }
    defaultConfig {

        applicationId "XXX.XX.XXXXX"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 30
        versionName "4.5"
        multiDexEnabled true
    }
    buildTypes {

        release {

            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
                appendVersionName(variant, defaultConfig)
            }
        }
    }
    aaptOptions {

        cruncherEnabled = false
    }

    packagingOptions {

        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/ECLIPSE_.SF'
        exclude 'META-INF/ECLIPSE_.RSA'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/classes.jar'
        exclude '...'
    }

}
def appendVersionName(variant, defaultConfig) {

    variant.outputs.each { output ->
        if (output.zipAlign) {
            def file = output.outputFile
            def fileName = file.name.replace("app-release.apk", "HealthScion- " + defaultConfig.versionName + "v.apk")
            output.outputFile = new File(file.parent, fileName)
        }

        def file = output.packageApplication.outputFile
        def fileName = file.name.replace("app-release.apk", "HealthScion- " + defaultConfig.versionName + "v.apk")
        output.packageApplication.outputFile = new File(file.parent, fileName)
    }
}

dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.amazonaws:aws-android-sdk-core:2.4.4'
    compile 'com.amazonaws:aws-android-sdk-s3:2.4.4'
    compile 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.4.4'
    compile 'com.amazonaws:aws-android-sdk-cognito:2.4.4'
    compile 'com.amazonaws:aws-android-sdk-kms:2.4.4'
    compile 'com.amazonaws:aws-android-sdk-ddb:2.4.4'
    compile 'dev.dworks.libs:astickyheader:0.1.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.facebook.android:facebook-android-sdk:4.15.0'
    compile files('libs/volley.jar')
    compile files('libs/android-viewbadger.jar')
    compile files('libs/itextpdf-5.5.7.jar')
    compile files('libs/xmlworker-5.5.6.jar')
    compile project(':SlidingMenuLibrary')
    compile project(':ViewPagerIndicatorlibrary')
    compile project(':swipelistview')
    compile project(':demo_cloud_tagview')
    compile project(':SegmentedControlLibrary')
    compile project(':Simpl3r')
    compile project(':MPChartLib')
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.google.firebase:firebase-messaging:10.0.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.applozic.communication.uiwidget:audiovideo:1.2'

}
apply plugin: 'com.google.gms.google-services'

我还创建了新项目并使用相同的CognitoCredentialsProvider集成了aws s3代码,它运行良好。

因此,显然问题必须存在于我的gradle文件中。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

我正在使用第三方库“Simpl3r”将文件上传到我的存储桶。因为我前一段时间安装了这个库,所以它使用的aws-sdk-s3版本已经过时了。

对我有用的解决方案:

  1. 打开更简单的gradle文件。

    删除行:编译fileTree(dir:'libs',包含:['* .jar'])

    添加行:编译'com.amazonaws:aws-android-sdk-core:2.4.4'

  2. 在那里更新aws sdk ver,即2.4.4(目前最新)

  3. 在build.gradle(app)中集成aws sdk ver 2.4.4(类似于Simpl3r库版本),在我的app模块中使用这个aws库函数。

  4. Atlast,我的classes.class(在运行时构建)问题的重复条目得到解决。

    提示:尝试制作与app gradle文件类似的子模块版本(gradle文件) 另外,只有在需要使用该特定模块运行任何特定jar文件时,请确保在子模块gradle文件中使用compile fileTree(dir:'libs',include:['* jar'])。