【发布时间】: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