2017-07-25 28 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()); 
    }