我正在使用Amazon Face Rekognition API,并在从相机捕获后将图像发送到AWS时出现此错误
java.lang.NoSuchFieldError:没有类型的静态字段INSTANCELorg / apache / http / conn / ssl / AllowAllHostnameVerifier;在班上Lorg / apache / http / conn / ssl / AllowAllHostnameVerifier;或其超类(的声明“ org.apache.http.conn.ssl.AllowAllHostnameVerifier”出现在/system/framework/framework.jar!classes2.dex)
这是我的gradle文件
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.sitetrack"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
bundle {
language {
enableSplit = false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//Retrofit
implementation "com.squareup.retrofit2:retrofit:2.6.1"
implementation "com.squareup.retrofit2:converter-gson:2.6.1"
//Glide
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
//Design
implementation 'com.google.android.material:material:1.0.0'
//Sugar
implementation 'com.github.satyan:sugar:1.5'
//Dimensions
implementation 'com.intuit.sdp:sdp-android:1.0.6'
//Library
implementation project(':loaderLibrary')
//Multidex
implementation 'com.android.support:multidex:1.0.3'
//GoogleServices
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
//Custom Camera
implementation "androidx.camera:camera-core:$camerax_version"
implementation "androidx.camera:camera-camera2:$camerax_version"
//AWS
implementation group: 'com.amazonaws', name: 'aws-java-sdk-rekognition', version: '1.11.681'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
这是我用于将图像发送到AWS的代码
val rekognitionClient: AmazonRekognition = AmazonRekognitionClientBuilder.defaultClient()
val objectMapper = ObjectMapper()
// Get an image object from S3 bucket.
val image: Image = Image()
.withS3Object(
S3Object()
.withBucket("bucket")
.withName(name)
)
// Search collection for faces similar to the largest face in the image.
val searchFacesByImageRequest = SearchFacesByImageRequest()
.withCollectionId("face-collection-staging")
.withImage(image)
.withFaceMatchThreshold(70f)
.withMaxFaces(2)
val searchFacesByImageResult =
rekognitionClient.searchFacesByImage(searchFacesByImageRequest)
System.out.println("Face matching faceId"+faceId)
val faceImageMatches =
searchFacesByImageResult.faceMatches
for (face in faceImageMatches) {
println(
objectMapper.writerWithDefaultPrettyPrinter()
.writeValueAsString(face)
)
println()
}
尝试添加以下依赖项-
您还需要排除这是因为您正在获得重复类的异常