简体   繁体   English

Google Vision API 与 android commons-codec 冲突

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

I was just trying to add google Vision API in my android app in java.我只是想在我的 android 应用程序中添加 google Vision API。 As a part that, When I am trying convert a bitmap into image , I am getting one exception as follows...作为一部分,当我尝试将位图转换为图像时,出现如下异常...

    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)

My gradle file is as follows …我的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'
  }

As per my findings on google This issue is due to android-support pointing to a old common version where indeed "encodeContent" method is not there.根据我在谷歌上的发现这个问题是由于 android-support 指向一个旧的通用版本,其中确实不存在“encodeContent”方法。

My code to covert bitmap to image …我将位图转换为图像的代码......

 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;
}

Any one can help me to resolve this issue... any suggestion will work for me..任何人都可以帮助我解决这个问题......任何建议都对我有用..

1) Update/add/adding runtime dependency the common version in my project. 1) 在我的项目中更新/添加/添加运行时依赖的公共版本。 --- Preferable in my option , if possible.... --- 如果可能的话,在我的选择中更可取....

2) Convert into Base64EncodedJpeg from a bitmap in some other way... 2) 以其他方式从位图转换为 Base64EncodedJpeg ...

Any help is apricated...任何帮助是apricated...

To convert image bytes into Image将图像字节转换为图像

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