Yandex 翻译 API 安卓

Posted

技术标签:

【中文标题】Yandex 翻译 API 安卓【英文标题】:Yandex Translate Api android 【发布时间】:2017-04-03 19:04:12 【问题描述】:

我添加了库 enter link description here 但在启动后 应用程序我遇到了这样的错误 Error:Error convert bytecode to dex: 原因:不支持的类文件版本 52.0 对不起我的英语。请帮帮我

这是我的 build.gradle 文件

apply plugin: 'com.android.application'


android 
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig 
    applicationId "com.example.macbookairmd760.zaebalas"
    minSdkVersion 23
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    javaCompileOptions
        annotationProcessorOptions
            includeCompileClasspath true
        
    


buildscript 
    tasks.withType(JavaCompile) 

    



packagingOptions 
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'


configurations.all 
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'

repositories 
    maven 
        url "https://jitpack.io"
    

buildTypes 
    release 
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    


dexOptions 
    incremental false



dependencies 

compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
    exclude group: 'com.android.support', module: 'support-annotations'
)
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.github.vbauer:yandex-translate-api:1.2.5'

这是一个错误:

Information:Gradle tasks [:app:assembleDebug]
Warning:The `android.dexOptions.incremental` property is deprecated and it has no effect on the build process.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.2 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency commons-logging:commons-logging:1.2 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.2 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160212 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.2 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency commons-logging:commons-logging:1.2 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.2 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20160212 is ignored for debug as it may be conflicting with the internal version provided by Android.
Error:Error converting bytecode to dex:
Cause: unsupported class file version 52.0
Error:java.lang.RuntimeException: com.android.dx.cf.iface.ParseException: unsupported class file version 52.0
Error:  at com.android.ide.common.internal.WaitableExecutor.waitForTasksWithQuickFail(WaitableExecutor.java:176)
Error:  at com.android.builder.dexing.DexArchiveBuilder.processOutputs(DexArchiveBuilder.java:95)
Error:  at com.android.builder.dexing.DexArchiveBuilder.convert(DexArchiveBuilder.java:78)
Error:  at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransformCallable.lambda$cacheMissAction$0(DexArchiveBuilderTransformCallable.java:233)
Error:  at com.android.builder.utils.FileCache.lambda$createFile$1(FileCache.java:262)
Error:  at com.android.builder.utils.FileCache.lambda$null$5(FileCache.java:423)
Error:  at com.android.builder.utils.FileCache.doInterProcessLocked(FileCache.java:668)
Error:  at com.android.builder.utils.FileCache.doLocked(FileCache.java:620)
Error:  at com.android.builder.utils.FileCache.lambda$queryCacheEntry$6(FileCache.java:402)
Error:  at com.android.builder.utils.FileCache.doInterProcessLocked(FileCache.java:668)
Error:  at com.android.builder.utils.FileCache.doLocked(FileCache.java:620)
Error:  at com.android.builder.utils.FileCache.queryCacheEntry(FileCache.java:378)
Error:  at com.android.builder.utils.FileCache.createFile(FileCache.java:275)
Error:  at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransformCallable.getFromCacheAndCreateIfMissing(DexArchiveBuilderTransformCallable.java:184)
Error:  at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransformCallable.call(DexArchiveBuilderTransformCallable.java:146)
Error:  at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransformCallable.call(DexArchiveBuilderTransformCallable.java:53)
Error:  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
Error:  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
Error:  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
Error:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
Error:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
Error:  at java.lang.Thread.run(Thread.java:745)
Error:Caused by: com.android.dx.cf.iface.ParseException: unsupported class file version 52.0
Error:  at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:485)
Error:  at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
Error:  at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
Error:  at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
Error:  at com.android.builder.dexing.DexArchiveBuilderCallable.parseClass(DexArchiveBuilderCallable.java:80)
Error:  at com.android.builder.dexing.DexArchiveBuilderCallable.call(DexArchiveBuilderCallable.java:66)
Error:  at com.android.builder.dexing.DexArchiveBuilderCallable.call(DexArchiveBuilderCallable.java:40)
Error:  ... 6 more
Error:Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.builder.utils.FileCache$FileCreatorException: com.android.builder.dexing.DexArchiveBuilder$DexBuilderException: Unable to convert input to dex archive.
Information:BUILD FAILED
Information:Total time: 3.325 secs
Information:34 errors
Information:9 warnings
Information:See complete output in console

【问题讨论】:

【参考方案1】:

com.github.vbauer:yandex-translate-api:1.2.5 库使用 Java 8,Android 仅支持 Java 7。

很遗憾,你不能在你的项目中使用这个库。

【讨论】:

感谢您的回答!但没有任何变体可以添加这个库??:( 你可以使用retrofit2 square.github.io/retrofit库,轻松创建自己的rest-api服务@bekha

以上是关于Yandex 翻译 API 安卓的主要内容,如果未能解决你的问题,请参考以下文章

Yandex Api 在 Eclipse 中无法正确翻译

Yandex API 翻译器不适用于 Android 应用程序

Yandex Translator Api 使用到 vb.net

从 Yandex 翻译中获取结果

将 Yandex 翻译器添加到 Fragment 会导致“应用程序崩溃”

Firefox也可以像Chrome网页翻译了