gpt4 book ai didi

java - Google Vision API 与 android commons-codec 冲突

转载 作者:太空宇宙 更新时间:2023-11-04 09:33:14 26 4
gpt4 key购买 nike

我只是想在我的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'
}

根据我在谷歌上的发现,这个问题是由于 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...

任何帮助都会被分配...

最佳答案

将图像字节转换为图像

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

关于java - Google Vision API 与 android commons-codec 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56826853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com