2017-07-25 108 views
0

我想在Android中使用亚马逊Web服务识别,但是我遇到了RekognitionClient问题。当我尝试初始化它,我得到的错误:Android AWS RekognitionClient错误

No instance field endpointPrefix of type Ljava/lang/String; in class Lcom/amazonaws/services/rekognition/AmazonRekognitionClient; or its superclasses (declaration of 'com.amazonaws.services.rekognition.AmazonRekognitionClient' appears in /data/app/com.amazonaws.husebnerbot-2/base.apk)

我已经尝试了一切,但我无法找到我的错误。你可以帮我吗?

private void initializeRekognitionSDK() { 
    Log.d(TAG, "Rekognition Client"); 

    CognitoCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
      getApplicationContext(), 
      appContext.getResources().getString(R.string.identity_id_test), 
      Regions.fromName("us-east-1") 
    ); 

    amazonRekognitionClient = new AmazonRekognitionClient(credentialsProvider); 
} 

谢谢!

+0

什么AWS的Android版本的最终代码其工作是识别图像库您使用的是SDK吗?你可以使用公共的AmazonRekognitionClient(AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration clientConfiguration)'构造函数并查看行为是否改变? –

+0

你好,谢谢你的回答。我正在使用sdk版本2.4.5。 你有一个构造函数的例子吗? 'ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProtocol(Protocol.HTTP); amazonRekognitionClient = new AmazonRekognitionClient(credentialsProvider,clientConfiguration);' 像这样? –

+0

尝试了它在最后一个评论中,它仍然给我同样的错误。 –

回答

0

当我工作的亚马逊图像重新识别时,我面临同样的问题,我已经解决了添加库,坦率地说,不明白如何添加新库解决了这个问题。这是我加入

compile group: 'com.amazonaws', name: 'aws-android-sdk-ddb-mapper', version: '2.6.13'

依赖

dependencies { 
    implementation 'com.android.support:appcompat-v7:26.1.0' 
    implementation 'com.android.support.constraint:constraint-layout:1.0.2' 
    compile group: 'com.amazonaws', name: 'aws-android-sdk-ddb-mapper', version: '2.6.13' 
    implementation 'com.amazonaws:aws-android-sdk-core:2.2.+' 
    implementation files('JarFilePath/AmazonRekognition/lib/aws-android-sdk-rekognition-2.6.9.jar') 
} 

下面是使用亚马逊Rekognition

ByteBuffer imageBytes = null; 
    try { 
     try (InputStream inputStream = new FileInputStream(new File(filePath))) { 
      imageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream)); 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(MainActivity.this, 
      "YOUR IDENTITY POOL ID", 
      Regions.EU_WEST_1); 
    ClientConfiguration clientConfiguration = new ClientConfiguration(); 
    clientConfiguration.setProtocol(Protocol.HTTPS); 

    AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(credentialsProvider, clientConfiguration); 
    rekognitionClient.setEndpoint("https://rekognition.us-east-1.amazonaws.com"); 
    rekognitionClient.setSignerRegionOverride("us-east-1"); 

    DetectLabelsRequest request = new DetectLabelsRequest() 
      .withImage(new Image() 
        .withBytes(imageBytes)) 
      .withMaxLabels(10) 
      .withMinConfidence(77F); 


    DetectLabelsResult result = rekognitionClient.detectLabels(request); 
    List<Label> labels = result.getLabels(); 
    System.out.println("REUSKT " + result.toString()); 

    System.out.println("Detected labels for " + photo); 
    for (Label label : labels) { 
     System.out.println(label.getName() + ": " + label.getConfidence().toString()); 
    }