无法运行应用程序,gradle 给出错误:没有这样的字段错误 [英] Unable to run the app, gradle gives error : No Such Field error
问题描述
我正在使用 Amazon Face Rekognition API 并在从相机捕获后将图像发送到 aws 时收到此错误
I am using Amazon Face Rekognition API and getting this error at the time of sending image to aws after capturing from camera
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)
java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/framework.jar!classes2.dex)
这是我的gradle文件
This is my gradle file
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 的代码
This is code I am using for sending image to 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()
}
推荐答案
我建议使用 AWS Java SDK V2.在 Android 上工作时,它将允许您使用备用 HTTP 运行时,并避免与 Apache 客户端的一些混乱.
I suggest to use the AWS Java SDK V2. It will allow you to use an alternate HTTP runtime, and avoid some of the mess with the Apache client, when working on Android.
GitHub 问题 #1180V2 存储库解决了这个主题.
GitHub Issue #1180 in the AWS Java SDK V2 repo addresses this topic.
在您的模块级 build.gradle
中,添加依赖项:
In your module-level build.gradle
, add dependencies:
dependencies {
implementation 'software.amazon.awssdk:sqs:2.13.49'
implementation 'software.amazon.awssdk:url-connection-client:2.13.49'
}
现在,初始化 Rekognition 客户端:
Now, initialize the Rekognition client:
val rekognition = RekognitionClient.builder()
.httpClient(UrlConnectionHttpClient.create())
.credentialsProvider(yourCredentials())
.region(Region.US_EAST_1)
.build()
这篇关于无法运行应用程序,gradle 给出错误:没有这样的字段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!