【问题标题】:Android AWS s3 CognitoCachingCredentialsProvider throws NoSuchMethodErrorAndroid AWS s3 CognitoCachingCredentialsProvider 抛出 NoSuchMethodError
【发布时间】:2017-11-09 20:07:05
【问题描述】:

我正在尝试在 aws 存储桶中上传/下载/列出文件。

我在片段中编写了以下代码来设置凭据,它在 (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: No direct method (Lcom/amazonaws/ClientConfiguration;Lcom/amazonaws/http/HttpClient;)V in class 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'

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

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

任何帮助将不胜感激。

【问题讨论】:

    标签: android amazon-s3 androidhttpclient aws-cognito


    【解决方案1】:

    我正在使用第 3 方库“Simpl3r”将文件上传到我的存储桶。由于我前段时间安静地插入了这个库,所以它使用的 aws-sdk-s3 版本已经过时了。

    适合我的解决方案:

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

      删除的行:compile fileTree(dir: 'libs', include: ['*.jar'])

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

    2. 在那边更新 aws sdk 版本,即 2.4.4(目前最新)

    3. 在 build.gradle(app) 中集成了 aws sdk 版本 2.4.4(与 Simpl3r 库版本类似),以便在我的应用程序模块中使用此 aws 库函数。

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

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

    【讨论】:

      猜你喜欢
      • 2018-09-23
      • 1970-01-01
      • 2020-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-30
      • 1970-01-01
      相关资源
      最近更新 更多