Google Vision API与android commons-codec冲突

问题描述 投票:1回答:1

我只是试图在Java的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'
  }

根据我在Google上的发现,此问题是由于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 ...

希望获得任何帮助...

我只是试图在Java的android应用中添加google Vision API。作为一部分,当我尝试将位图转换为图像时,出现如下异常:java.lang ....

java android google-vision common-code
1个回答
0
投票

将图像字节转换为图像

© www.soinside.com 2019 - 2024. All rights reserved.