Android AWS RekognitionClient错误

时间:2017-07-25 10:28:54

标签: android amazon-web-services amazon-rekognition

我正在尝试在Android中使用亚马逊网络服务识别,但我遇到了RekognitionClient问题。当我尝试初始化它时,我收到错误:

  

没有类型为Ljava / lang / String的实例字段endpointPrefix;在课堂Lcom / amazonaws / services / rekognition / AmazonRekognitionClient;或其超类('com.amazonaws.services.rekognition.AmazonRekognitionClient'的声明出现在/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);
}

谢谢!

1 个答案:

答案 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')
}

以下是使用Amazon 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());
    }