【问题标题】:Compiling compatibility issue external libraries编译兼容性问题外部库
【发布时间】:2017-02-09 22:06:31
【问题描述】:

我试图将 Selenium WebDriver 用于 Android 应用程序。 (我使用的是最新的AndroidStudio;v2.2)

我关注this guide 所以在我的应用程序库中我复制了 jar 文件(下载的 Selenium WebDriver 的 zip 有一个名为“libs”的文件夹,一个名为“client-combined-3.0.0-beta4-nodeps”的 jar以及一个 DEPENDENCIES 和一个 LICENSE 文件[我刚刚复制了“libs”文件夹中的所有 jar 以及外部的另一个 jar])

这是 build.gradle (module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    defaultConfig {
        applicationId "com.example.utente.downall"
        minSdkVersion 14
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions{
        pickFirst("META-INF/LICENSE")
        pickFirst("META-INF/DEPENDENCIES")
    }
}

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:24.2.1'
    testCompile 'junit:junit:4.12'
    compile files('libs/cglib-nodep-3.2.4.jar')
    compile files('libs/client-combined-3.0.0-beta4-nodeps.jar')
    compile files('libs/commons-codec-1.10.jar')
    compile files('libs/commons-exec-1.3.jar')
    compile files('libs/commons-logging-1.2.jar')
    compile files('libs/gson-2.3.1.jar')
    compile files('libs/guava-19.0.jar')
    compile files('libs/hamcrest-core-1.3.jar')
    compile files('libs/hamcrest-library-1.3.jar')
    compile files('libs/httpclient-4.5.2.jar')
    compile files('libs/httpcore-4.4.4.jar')
    compile files('libs/httpmime-4.5.2.jar')
    compile files('libs/jna-4.1.0.jar')
    compile files('libs/jna-platform-4.1.0.jar')
    compile files('libs/junit-4.12.jar')
    compile files('libs/netty-3.5.7.Final.jar')
    compile files('libs/phantomjsdriver-1.3.0.jar')
}

(项目同步)

执行“运行”时出现此错误:

Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add 
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
Error:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process

所以我去了 build.gradle (Project: DownAll) 并添加了这些目标/源兼容性,所以这是这样的:

我清理了项目,重建了它,重新同步了它,但仍然是同样的错误。 我该怎么办?

如果有帮助,这里是我的环境变量,如果有帮助:

JAVA_HOME

C:\Program Files\Java\jdk1.8.0_102

ANDROID_HOME

C:\Users\Utente\AppData\Local\Android\sdk;C:\Users\Utente\AppData\Local\Android\sdk\tools;C:\Users\Utente\AppData\Local\Android\sdk\平台工具

(AppData 文件夹已隐藏)

编辑:

向上

【问题讨论】:

  • 您是否尝试添加它建议的两个语句? targetCompatibility = '1.7' sourceCompatibility = '1.7'
  • @BR89 正如你在第二张截图中看到的那样,是的,我做到了(我已经在 build.gradle 项目中做到了)
  • 抱歉,我没看到。 -- 使用 JDK 1.8..我很好奇如果你尝试使用 1.7 或更低版本会发生什么
  • @BR89 好吧,我试过了,它给出了同样的错误:也许我做错了,但是库子模块没有用 Java 1.7 编译

标签: java android selenium-webdriver compiler-errors compatibility


【解决方案1】:

我刚刚遇到了完全相同的错误,并发现是com.google.guava:guava:21.0 导致了问题;应用程序在降级到 20.0 后立即开始运行。

所以,我猜你的一些罐子可能不兼容。

尝试一一降级/删除依赖项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 2016-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多