【问题标题】:Unable to run the app, gradle gives error : No Such Field error无法运行应用程序,gradle 给出错误:没有此类字段错误
【发布时间】:2019-11-26 10:46:14
【问题描述】:

我正在使用 Amazon Face Rekognition API,并在从相机捕获后将图像发送到 aws 时收到此错误

java.lang.NoSuchFieldError: 没有静态字段实例类型 Lorg/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()
        }

【问题讨论】:

    标签: amazon-web-services gradle


    【解决方案1】:

    尝试添加以下依赖项 -

    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1' 在你的 gradle 文件中。

    【讨论】:

    • 我已经尝试过了,但是它给出了异常,例如,在模块 httpclient-android-4.3.5.1.jar (org.apache.httpcomponents:httpclient- android:4.3.5.1) 和 httpcore-4.4.11.jar (org.apache.httpcomponents:httpcore:4.4.11)
    • 试试这个 - compile('org.apache.httpcomponents:httpmime:4.3.6') { exclude module: 'httpclient' } compile 'org.apache.httpcomponents:httpclient-android:4.3.5 '
    【解决方案2】:

    你也需要排除那是因为你得到了重复类的异常

    dependencies { compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1' compile (group: 'org.apache.httpcomponents' , name: 'httpmime' , version: '4.3.5') { exclude module: 'org.apache.httpcomponents:httpclient'} }

    【讨论】:

      【解决方案3】:

      我建议使用 AWS Java SDK V2。在 Android 上工作时,它将允许您使用备用 HTTP 运行时,并避免 Apache 客户端的一些混乱。

      AWS Java SDK V2 存储库中的GitHub Issue #1180 解决了这个主题。

      在你的模块级build.gradle,添加依赖:

      dependencies {
          implementation 'software.amazon.awssdk:sqs:2.13.49'
          implementation 'software.amazon.awssdk:url-connection-client:2.13.49'
      }
      

      现在,初始化 Rekognition 客户端:

      val rekognition = RekognitionClient.builder()
          .httpClient(UrlConnectionHttpClient.create())
          .credentialsProvider(yourCredentials())
          .region(Region.US_EAST_1)
          .build()
      

      【讨论】:

        猜你喜欢
        • 2018-11-19
        • 1970-01-01
        • 1970-01-01
        • 2021-06-04
        • 1970-01-01
        • 2017-06-09
        • 2020-02-12
        • 1970-01-01
        • 2023-03-09
        相关资源
        最近更新 更多