ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Android Studio:测试:使用java 8或更高版本编译的库依赖项

2019-07-06 08:36:59  阅读:251  来源: 互联网

标签:android android-studio android-gradle cucumber android-espresso


请帮忙.我正在设置我的android studio测试时非常可怕.

我已经下载了计算器示例,从黄瓜github练习cumcumber代码测试. https://github.com/cucumber/cucumber-jvm/tree/master/android(其中一些品牌btw非常扼流自命名)

我试着在Android工作室使用它.该程序运行完美(耶!).然而,测试没有.我有一个非常可怕的消息,每次我运行时都会困扰我.

*To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.
To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html
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
:app:transformClassesWithDexForDebugAndroidTest FAILED
Error:Execution failed for task ':app:transformClassesWithDexForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_74\bin\java.exe'' finished with non-zero exit value 1*

它的目标兼容性和源兼容性我遇到了麻烦(尚未完成剩下的工作)

这是gradle构建:正如您所看到的,我已将兼容性更改为1.7

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "boo.thefoodhunt"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        debug {
            assets.srcDirs = ['src/debug/assets', 'src/androidTest/assets/']
            res.srcDirs = ['src/debug/res', 'src/androidTest/assets/features']
        }
        main { res.srcDirs = ['src/main/res', 'src/androidTest/assets'] }
    }
    dexOptions {
        incremental true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'

    //TESTING
    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
    androidTestCompile 'com.android.support:support-annotations:23.3.0'

    //Espresso
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'

    //Cucumber
    androidTestCompile 'info.cukes:cucumber-android:1.2.4'
    androidTestCompile 'info.cukes:cucumber-picocontainer:1.2.4'
}

无法运行的测试:

 package boo.thefoodhunt;

import android.test.ActivityInstrumentationTestCase2;

import cucumber.api.CucumberOptions;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

@CucumberOptions(features = "features")
public class CalculatorActivitySteps extends ActivityInstrumentationTestCase2<CalculatorActivity> {

    public CalculatorActivitySteps(SomeDependency dependency) {
        super(CalculatorActivity.class);
        assertNotNull(dependency);
    }

    @Given("^I have a CalculatorActivity$")
    public void I_have_a_CalculatorActivity() {
        assertNotNull(getActivity());
    }

    @When("^I press (\\d)$")
    public void I_press_d(final int d) {
        switch (d) {
            case 0:
                onView(withId(R.id.btn_d_0)).perform(click());
                break;
            case 1:
                onView(withId(R.id.btn_d_1)).perform(click());
                break;
            case 2:
                onView(withId(R.id.btn_d_2)).perform(click());
                break;
            case 3:
                onView(withId(R.id.btn_d_3)).perform(click());
                break;
            case 4:
                onView(withId(R.id.btn_d_4)).perform(click());
                break;
            case 5:
                onView(withId(R.id.btn_d_5)).perform(click());
                break;
            case 6:
                onView(withId(R.id.btn_d_6)).perform(click());
                break;
            case 7:
                onView(withId(R.id.btn_d_7)).perform(click());
                break;
            case 8:
                onView(withId(R.id.btn_d_8)).perform(click());
                break;
            case 9:
                onView(withId(R.id.btn_d_9)).perform(click());
                break;
        }
    }

    @When("^I press ([+–x\\/=])$")
    public void I_press_op(final char op) {
        switch (op) {
            case '+':
                onView(withId(R.id.btn_op_add)).perform(click());
                break;
            case '–':
                onView(withId(R.id.btn_op_subtract)).perform(click());
                break;
            case 'x':
                onView(withId(R.id.btn_op_multiply)).perform(click());
                break;
            case '/':
                onView(withId(R.id.btn_op_divide)).perform(click());
                break;
            case '=':
                onView(withId(R.id.btn_op_equals)).perform(click());
                break;
        }
    }

    @Then("^I should see (\\S+) on the display$")
    public void I_should_see_s_on_the_display(final String s) {
        onView(withId(R.id.txt_calc_display)).check(matches(withText(s)));
    }
}

现在我试过这个:

Error when using a jar in my project

还有这个:
Is it possible to use Java 8 for Android development?

还有这个:
Gradle sourceCompatibility has no effect to subprojects

在项目gradle和app gradle中.但我正在考虑它是唯一的测试…这些将无济于事,它与依赖关系有关,因此我很困难.谁能帮忙!提前致谢

解决方法:

您有一个依赖项,不清楚哪个是为Java 8编译的,并且您已在构建中指定了Java 7.

错误消息这是由使用Java 8或更高版本编译的库依赖项引起的.他们是关键吗?

我的方法是将Java版本更改为8.如果不能解决问题,请减少问题.也就是说,从没有依赖项和代码的新项目开始,添加非常小的部分,直到找到导致上述错误的内容.

也就是说,应用Galls Law:

“一个复杂的系统总是被发现从一个简单的系统发展而来.一个从头开始设计的复杂系统永远不会工作,无法修补以使其工作.你必须重新开始使用一个简单的系统. – John加尔(1975,p.71)“

https://en.wikipedia.org/wiki/John_Gall_%28author%29

标签:android,android-studio,android-gradle,cucumber,android-espresso
来源: https://codeday.me/bug/20190706/1395594.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有