please help. I am having a really horrible time with setting up my testing for android studio.
I have downloaded the calculator example to practice cumcumber code testing from the cucumber github. https://github.com/cucumber/cucumber-jvm/tree/master/android (some of these brands btw are very strangley named)
I tried to use it with Android studio. The program runs perfect (yay!). The test however does not. I have a really horrible message that just haunts me every time i run it.
*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*
Its the target compatibility and source compatibility i am having trouble with (have not got to the rest yet)
Here's the gradle build: as you can see i have changed the compatibility to 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'
}
The test that is failing to run:
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)));
}
}
Now ive tried this:
Error when using a jar in my project
and this: Is it possible to use Java 8 for Android development?
and this: Gradle sourceCompatibility has no effect to subprojects
in both the project gradle and the app gradle. But i'm am thinking as its only coming with testing...these will not help and its something to do with the dependencies and for that i am pretty stuck. Can anyone help! thanks in advance
You have a dependency, unclear which, that is compiled for Java 8 and you have specified Java 7 in your build.
The error message
This is caused by library dependencies that have been compiled using Java 8 or above.
is they key here.My approach would be to change the Java version to 8. If that didn't do the trick, reduce the problem. That is, start with a new project without dependencies, and code, and add very small parts until I found what caused to error above.
That is, apply Galls Law:
"A complex system that works is invariably found to have evolved from a simple system that worked. A complex system designed from scratch never works and cannot be patched up to make it work. You have to start over with a working simple system. – John Gall (1975, p.71)"
https://en.wikipedia.org/wiki/John_Gall_%28author%29
Ok for any one that is having the same problem. I sussed it! (I think!) its lead on to other problems with the program but at least i have the test running and its communicating with the device and reading through the tests without having paddy. The tests however are coming up with a brand new problem (for another question, another day) New problem if anyone is interested:
im guessing that its something to do with not all the buttons not in view (not my design! FYI) so we adjust this tomorrow.
Now on to the solution(ish)
https://github.com/cucumber/cucumber-jvm/issues/893: comment from programmerdave on 18 Nov 2015 helped with the gradle setup.
This brought a whole new bug!
But managed to fix this quite quickly. thanks to these guys https://code.google.com/p/android/issues/detail?id=194980
Anyway apparently two different issues that created havoc (a day and half).
Heres the gradle for the Calkulator demo (link in question) - it all feels a bit messy and if anyone has a nice cleaner solution please let me know
So all in all it seems to be that jvm-deps......well who knew