簡體   English   中英

Google Vision API 與 android commons-codec 沖突

[英]Google Vision API conflict with android commons-codec

我只是想在我的 android 應用程序中添加 google Vision API。 作為一部分,當我嘗試將位圖轉換為圖像時,出現如下異常...

    java.lang.NoSuchMethodError: No static method encodeBase64URLSafeString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
    at com.google.api.client.util.Base64.encodeBase64URLSafeString(Base64.java:79)
    at com.google.api.services.vision.v1.model.Image.encodeContent(Image.java:98)

我的gradle文件如下...

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
buildToolsVersion "29.0.0"
defaultConfig {
    applicationId "com.camreader1"
    minSdkVersion 24
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'

}
}

dependencies {



implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation ('com.android.support:appcompat-v7:28.0.0')
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'commons-io:commons-io:2.5'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.rmtheis:tess-two:7.0.0'





implementation ('com.google.android.gms:play-services-base:17.0.0')

implementation ('com.google.android.gms:play-services-auth:17.0.0')

implementation 'com.google.apis:google-api-services-vision:v1-rev400-1.25.0'
implementation ('com.google.api-client:google-api-client-android:1.26.0') {
    exclude module: 'httpclient'
}
implementation ('com.google.http-client:google-http-client-gson:1.26.0') {
    exclude module: 'httpclient'
}

  implementation group: 'commons-codec', name: 'commons-codec', version: '1.12'
  }

根據我在谷歌上的發現這個問題是由於 android-support 指向一個舊的通用版本,其中確實不存在“encodeContent”方法。

我將位圖轉換為圖像的代碼......

 public Image getBase64EncodedJpeg(Bitmap bitmap) {
    com.google.api.services.vision.v1.model.Image image = new com.google.api.services.vision.v1.model.Image();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, byteArrayOutputStream);
    byte[] imageBytes = byteArrayOutputStream.toByteArray();
    image.encodeContent(imageBytes);
    return image;
}

任何人都可以幫助我解決這個問題......任何建議都對我有用..

1) 在我的項目中更新/添加/添加運行時依賴的公共版本。 --- 如果可能的話,在我的選擇中更可取....

2) 以其他方式從位圖轉換為 Base64EncodedJpeg ...

任何幫助是apricated...

將圖像字節轉換為圖像

String imageBase64 = Base64.encodeToString(imageBytes, Base64.DEFAULT);
base64EncodedImage.setContent(imageBase64);
annotateImageRequest1.setImage(base64EncodedImage);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM