aws / aws-sdk-java-v2

The official AWS SDK for Java - Version 2
Apache License 2.0
2.12k stars 804 forks source link

java.lang.NoSuchFieldError in Android Studio #1180

Closed LittleHans8 closed 5 years ago

LittleHans8 commented 5 years ago

Expected Behavior

No java.lang.NoSuchFieldError should be thrown.

Current Behavior

 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!classes3.dex)
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:146)

Possible Solution

see : using-apache-httpclient-with-android-sdk-23-nosuchmethod

Steps to Reproduce (for bugs)

I want to generate an S3Client and the operation is failed, this is my code:

Region region = Region.US_EAST_1;
AwsSessionCredentials awsCreds = AwsSessionCredentials.create(ACCESS_KEY, SECRET_ACCESS_KEY, "");
S3Client s3 = S3Client.builder()
 .credentialsProvider(StaticCredentialsProvider.create(awsCreds))
 .region(region).build();

Your Environment

zoewangg commented 5 years ago

@LittleHans8 Are you using AWS Java SDK v2 on Andriod? I'm not sure if it would work though.

We have a designated mobile SDK. https://docs.aws.amazon.com/sdk-for-android/index.html

LittleHans8 commented 5 years ago

@zoewangg Yes,I am using AWS Java SDK v2 on Andriod , sdk-for-android is work for me, but it can't custom endpoint.

zoewangg commented 5 years ago

Unfortunately, we won't be able to fix Apache http client for Android use case. Can you try with http url connection client?

        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>url-connection-client</artifactId>
            <version>${awsjavasdk.version}</version>
        </dependency>
S3Client.builder()
.httpClientBuilder(UrlConnectionHttpClient.builder())
.build()
LittleHans8 commented 5 years ago

It works! Thanks, but need add javax.xml.stream:stax-api and com.bea.xml.stream:org.motechproject.com.bea.xml.stream lib to 'build.gradle' file.

Cornflower1991 commented 4 months ago

It works! Thanks, but need add javax.xml.stream:stax-api and com.bea.xml.stream:org.motechproject.com.bea.xml.stream lib to 'build.gradle' file.

`javax.xml.stream:stax-api and com.bea.xml.stream:org.motechproject.com.bea.xml.stream version