Am getting the following error
E/AndroidRuntime( 3069): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{fun.n.games/fun.n.games.HelloActivity}: java.lang.ClassNotFoundException: Didn't find class "fun.n.games.HelloActivity" on path: DexPathList[[zip file "/data/app/fun.n.games-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
This error shows up when I try to execute my android app that I have installed on my AVD.
My AVD is running as follows
$ emulator -avd Nexus_S_API_22
The code for the HelloActivity is present.
package fun.n.games;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hello_layout);
}
#Override
public void onStart() {
super.onStart();
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText("Hello world!");
}
}
It is being pulled together by the following manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fun.n.games"
android:versionCode="1"
android:versionName="1.0.0" >
<application android:label="#string/app_name" >
<activity
android:name="fun.n.games.HelloActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is being built by a single build.gradle
buildscript {
// use the jcenter repository to download the dependencies
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
}
And I am using gradle from command prompt to build and install
$ gradle installDebug
Apart from the error at the beginning of the post, when I search through the build folder, I don't see the HelloActivity.class that I was expecting there.
How do I get the java class to get added to the apk file?
Replace android:name="fun.n.games.HelloActivity" with android:name=".HelloActivity"
Gradle was indeed not finding the java files to compile. Reason being my java file was in the wrong location.
Incorrect location
/src/main/fun/n/games/HelloActivity.java
Correct location
/src/main/java/fun/n/games/HelloActivity.java
The java folder was missing and hence gradle was not finding the class to compile.
Related
After working on a project for about a month, my project started executing errors.. Whenever I'm trying to run the program via phone, it executes "app stopped working".. I monetize to check "android monitor" to know who causes the error..(FATAL EXCEPTION: main):
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.app.programavima.java.javaprogramavimas.MainActivity" on path: DexPathList[[zip file "/data/app/com.app.programavima.java.javaprogramavimas-1/base.apk", zip file "/data/app/com.app.programavima.java.javaprogramavimas-1/split_lib_slice_7_apk.apk"],nativeLibraryDirectories=[/data/app/com.app.programavima.java.javaprogramavimas-1/lib/arm64, /vendor/lib64, /system/lib64]]
Am I missing these "base.apk", "arm64", "lib64" files? Maybe something else is making my app to executes errors?
Every help would be pleased, I can manage to import some code, because there's a lot of files inside my project
Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true // add this line
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1' // add this library
}
In your manifest update with this code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" > // add this line
...
</application>
</manifest>
While working with firebase UI I am getting Unable to find explicit activity class com.firebase.ui.auth.KickoffActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseApp.initializeApp(this);
setContentView(R.layout.activity_main);
FirebaseApp.initializeApp(this);
mAuth=FirebaseAuth.getInstance();
mAuthListner=new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user=firebaseAuth.getCurrentUser();
if(user!=null){
Toast.makeText(getApplicationContext(),"Sign in success",Toast.LENGTH_SHORT).show();
}
else {
startActivityForResult(AuthUI.getInstance()
.createSignInIntentBuilder()
.setIsSmartLockEnabled(false)
.setProviders(AuthUI.EMAIL_PROVIDER,AuthUI.GOOGLE_PROVIDER).build(),
RC_SIGN_IN);
}
}
};
}
Full error message
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.flamanco.trackme/com.firebase.ui.auth.KickoffActivity}; have you declared this activity in your AndroidManifest.xml? at android.app.Instrumentation.checkStartActivityResult
Added dependencies on app/.gradle file
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'com.firebaseui:firebase-ui-auth:1.1.1'
}
apply plugin: 'com.google.gms.google-services'
also added plugin in build gradle
classpath 'com.google.gms:google-services:3.0.0'
Finally I did added SHA1 fingerprint in my firebase console project.
Do I need to add auth.kickOff activity in manifest file
android.content.ActivityNotFoundException: Unable to find explicit
activity class
{com.example.flamanco.trackme/com.firebase.ui.auth.KickoffActivity};
have you declared this activity in your AndroidManifest.xml? at
android.app.Instrumentation.checkStartActivityResult
You need to declare the activity in the AndroidManifest.xml
Open your manifest file and add the KicoffActivity.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto">
<activity
android:name="KickoffActivity"/>
</manifest>
Also, I am not sure you have initial FirebaseApp twice here..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseApp.initializeApp(this);
setContentView(R.layout.activity_main);
FirebaseApp.initializeApp(this);
}
Usually it should be initialized only once in the application class,
in onCreate() method.
Create a new application class..
public class YourApplicationClass extends Application {
#Override
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
}
}
And add the same in the manifest,
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto">
<application
android:name="YourApplicationClass"
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/MyMaterialTheme.Base">
<activity
android:name="KickoffActivity"/>
</application>
</manifest>
Manually adding the KickoffActivity activity to the manifest is not the right solution. It should be done for you.
If you manually add the KickoffActivity, you will then have to add another activity and another one and so on.
I happened to have:
tools:node="replace">
In my manifest. Which prevents any manifest merging.
Removed it and it worked fine since.
After that you might get some other merging errors like duplicate tags etc..
But the error will be different and will tell you what to do now. I had a case of a tag used twice in my and in a merged manifest so I was told to add:
tools:replace="android:label"
Which fixed that too.
Make sure your have declared your KickoffActivity properly in AndroidManifest.xml
as
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxx.xxx.xxx">
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name=".KickoffActivity">
</activity>
</application>
</manifest>
Especially check the name attribute, if you have activity in package say "test" then
you'll have to change
the name attribute as
<activity android:name=".test.KickoffActivity">
</activity>
If everything fine with AndroidManifest.xml,
I would suggest to update your libraries as mentioned by deividas.
You can check the FirebaseUI release notes here https://github.com/firebase/FirebaseUI-Android/releases
Also update other firebase libraries to
compile 'com.google.firebase:firebase-core:11.0.4'
compile 'com.google.firebase:firebase-auth:11.0.4'
Finally I have completely reinstall android studio to latest version, updated everything including
Google play service
firebase libraries
gradle version
google repositoris
And I started new project from begining and worked with no error.
there are many activities that are added automatically on adding AUTHUI dependencies.
these activity includes kickoffactivity,recoverpasswordactivity,registerEmailActivity,etc
I can verify if by going to path
/project/module/build/intermediates/manifests/full/debug/AndroidManifest.xml.
previously i don't have kickoffactivity in this manifest file, I don't know the reason,but now i have it.I don't think adding it manually on app's manifest file will work.
Add the following in the manifest file:
< activity android :name=" *name of the activity* ">
< /activity>
The above is added by default inside the manifest, but in case if it is not, then do add it.
What I am trying to achieve:
I have created Android Plugin Project (cclib-release.aar) which has a targeted Activity.
I want to invoke this Activity in ionic2 using Cordova Plugin which has cclib-release.aar added as dependency inside Cordova Plugin. aar file added in cordova plugin as per this link
Problem facing:
While invoking Activity, I am getting the following error
java.lang.NoClassDefFoundError: Failed resolution of: Lcompute/cclib/MainActivity;
Caused by: java.lang.ClassNotFoundException: Didn't find class "compute.cclib.MainActivity" on path: DexPathList[[zip file "/data/app/com.ionicframework.fragmentwithionic759798-2/base.apk"],nativeLibraryDirectories=[/data/app/com.ionicframework.fragmentwithionic759798-2/lib/arm, /vendor/lib, /system/lib]]
The issue is similar to SO Link in which the issue was resolved.
But even after following similar step's I am getting the above mentioned error!
My Plugin Structure: (cclib-release.aar is my targeted library with Activity)
My Inject.java goes like this
public class Inject extends CordovaPlugin {
#Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("coolMethod")) {
String message = args.getString(0);
this.coolMethod(message, callbackContext);
return true;
}
return false;
}
private void coolMethod(String message, CallbackContext callbackContext) {
if (message != null && message.length() > 0) {
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
Intent intent = new Intent(cordova.getActivity().getApplicationContext(),
compute.cclib.MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
cordova.getActivity().startActivity(intent);
}
});
callbackContext.success(message);
} else {
callbackContext.error("Expected one non-empty string argument.");
}
}
}
Added this plugin in ionic2 using
cordova plugin add PATH_TO_PLUGIN
As per above mentioned answer by SO, I have modified Ionic2 project's AndroidManifest.xml manually .Path =FragmentWithIonic\platforms\android to refer the Activity.
<activity android:label="#string/activity_name"
android:launchMode="singleTop" android:theme="#android:style/Theme.DeviceDefault.NoActionBar"
android:name="compute.cclib.MainActivity">
</activity>
I am invoking this in Ionic2 using below which works fine in other cases.
this.platform.ready().then(() => {
window.plugins.Inject.coolMethod(message, "short", position);
});
I tried to manually import compute.cclib.MainActivity in Inject.java. But invoking Activity is still giving run time error!
Below is the modified FragmentWithIonic\platforms\android\AndroidManifest.xml
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true"
android:versionCode="1"
android:versionName="0.0.1"
package="com.ionicframework.fragmentwithionic759798"
xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<application android:hardwareAccelerated="true"
android:icon="#mipmap/icon"
android:label="#string/app_name"
android:supportsRtl="true">
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:label="#string/activity_name"
android:launchMode="singleTop"
android:name="MainActivity"
android:theme="#android:style/Theme.DeviceDefault.NoActionBar"
android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/activity_name"
android:launchMode="singleTop"
android:theme="#android:style/Theme.DeviceDefault.NoActionBar"
android:name="compute.cclib.MainActivity">
</activity>
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="24" />
</manifest>
What modifications I need to do to invoke Activity in my plugin?
EDIT 1
After #gmmo suggested, I included reference libraries in my Plugin's gradle File (Inject.gradle)
repositories{
jcenter()
maven { url "https://jitpack.io" }
flatDir{
dirs 'aar'
}
}
dependencies {
compile 'com.android.support:appcompat-v7:25.1.0'
compile(name:'cclib-release', ext:'aar')
}
android {
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
Now I am getting the following error while building my ionic2 project.
A problem occurred configuring root project 'android'.
> You have not accepted the license agreements of the following SDK components:
[Android Support Repository].
Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html
I have already updated with all license agreements in SDK. I am pretty sure this is due to this lines in Inject.gradle
compile 'com.android.support:appcompat-v7:25.1.0'
Plugin might not able to find the corresponding dependencies
You can definitely invoke full activities inside the aar file. My aar file contained several activities. I have not seen the issue you mentioned, but I have seen path issues when the aar gradle file had problems. You may want to revise your gradle file. This is the one my plugin uses:
repositories{
jcenter()
maven { url "https://jitpack.io" }
flatDir{
dirs 'libs'
}
}
dependencies {
compile 'com.android.support:support-v13:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:gridlayout-v7:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.android.gms:play-services-base:8.1.0'
compile 'com.google.android.gms:play-services-location:8.1.0'
compile 'com.google.android.gms:play-services-maps:8.1.0'
compile 'com.google.android.gms:play-services-gcm:8.1.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'org.altbeacon:android-beacon-library:2.+'
compile 'com.cloudinary:cloudinary-android:1.2.2'
compile(name:'mysdk', ext:'aar')
}
android {
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
and this is how I invoke activities from the cordova plugin:
#Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
Logger.v(Constants.Engine.LOGGER_TAG_APP, "Plugin Initialized...");
Context context = cordova.getActivity();
// This works for me
Intent intent = new Intent(context, PermissionsActivity.class);
context.startActivity(intent);
}
and snipped of my plugin .xml
<!-- Initialization -->
<platform name="android">
<config-file target="config.xml" parent="/*">
<feature name="PlatformSDK">
<param name="android-package" value="com.mycompany.PlatformSdk.cordova.PlatformSDKCordovaPlugin" />
<param name="onload" value="true" />
</feature>
</config-file>
<framework src="libs/mysdk.gradle" custom="true" type="gradleReference" />
<resource-file src="libs/mysdk.aar" target="libs/mysdk.aar" />
<source-file src="PlatformSDKCordovaPlugin.java" target-dir="src/com/mycompany/PlatformSDK/cordova" />
</platform>
Okey finally I figure out the issue.
Ionic2 project need to update SDK tools by the following command
android update sdk --no-ui --filter extra
Got this input from cordova-plugin-issues
One more command was mentioned which I am not sure about which was the below one. If someone come across similar issue can try this out as well
android update sdk --no-ui --all --filter
A big Thanks to #gmmo , as he gave me the input to add all
dependencies also along with plugin's Inject.gradle .
As I was in an impression that why would this be required after all these dependencies was already covered in Android Plugin Project.
I'm creating a Gradle task for my Android project that needs to know the path to the compiled .class files. How can I get this path? I've found suggestions (here and here; also see the Gradle docs for SourceSet) that sourceSets.main.output.classDir will give me this path, but when I try to use it, I get the error
Could not find property 'output' on source set main.
This happens even when I create a new, minimal project, with the following build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
apply plugin: 'android'
android {
compileSdkVersion 22
buildToolsVersion "20.0.0"
task printClassesDir << {
println sourceSets.main.output.classesDir
}
}
This minimal project builds fine, but will give that error if I run the task printClassesDir. How can I get the .class file output directory in my task?
I've also tried the suggestion of <build variant>.javaCompile.classpath from this answer to another question. I was able to access this property with
applicationVariants.find{it.name == 'debug'}.javaCompile.classpath
but this file collection is empty.
For reference, here are the other files for my minimal project:
src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="a.b">
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="22" />
<application>
<activity android:name=".Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
src/main/java/a/b/Main.java
package a.b;
import android.app.Activity;
public class Main extends Activity { }
I was able to find this path using the compile<Variant>JavaWithJavac tasks. These are of type JavaCompile, so they have destinationDir properties:
task printDebugClassesDir << {
println compileDebugJavaWithJavac.destinationDir
}
This prints the build/intermediates/classes/debug directory, which contains the compiled class files. The same thing works for release.
I have an android application project that I want to add automated tests in it. For that I would like to use Cucumber for java in Android Studio and execute those tests directly into my IDE (with a Run/Debug configuration).
I am on Windows 7 sp1 64 bits using Android Studio 0.8.9. I've added the plugins Gherkin version 134.1007 and Cucumber for Java version 134.1007. I use the following libraries for Cucumber :
cucumber-android-1.1.8
cucumber-core-1.1.8
cucumber-html-0.2.3
cucumber-java-1.1.8
cucumber-junit-1.1.8
cucumber-jvm-deps-1.0.3
gherkin-2.12.2
robotium-solo-5.2.1
This is my Project structure :
TruckCalibrator/
.idea/
app/
build/
libs/
[libraries listed above in .jar format]
src/
main/
java/
com/
novomnetworks/
formeval/
truckcalibrator/
MainActivity.java
res/
AndroidManifest.xml
test/
assets/
features/
app_start.feature
java/
com/
novomnetworks/
formeval/
truckcalibrator/
test/
CucumberTest.java
build.gradle
build/
gradle/
This is my gradle file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.novomnetworks.formeval.truckcalibrator"
minSdkVersion 16
targetSdkVersion 20
versionCode 1
versionName "1.0"
testInstrumentationRunner "cucumber.api.android.CucumberInstrumentation"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
instrumentTest {
java.srcDirs = ['src/test/java']
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.github.satyan:sugar:1.3'
}
This is my manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.novomnetworks.formeval.truckcalibrator"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<instrumentation
android:name="cucumber.api.android.CucumberInstrumentation"
android:targetPackage="com.novomnetworks.formeval.truckcalibrator.test" />
<application
android:allowBackup="true"
android:icon="#drawable/launcher_icon"
tools:replace="icon"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="com.orm.SugarApp">
<uses-library android:name="android.test.runner" />
<meta-data android:name="DATABASE" android:value="form-eval.db" />
<meta-data android:name="VERSION" android:value="1" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.novomnetworks.formeval.truckcalibrator.database" />
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is my Cucumber step definitions file (CucumberTest.java) :
package com.novomnetworks.formeval.truckcalibrator.test;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import cucumber.api.CucumberOptions;
import cucumber.api.PendingException;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import cucumber.api.junit.Cucumber;
import com.novomnetworks.formeval.truckcalibrator.MainActivity;
import com.novomnetworks.formeval.truckcalibrator.R;
import com.robotium.solo.Solo;
import org.junit.runner.RunWith;
/**
* Created by rroyer on 2014-10-24.
*/
#RunWith(Cucumber.class)
/*#CucumberOptions(monochrome = true,
tags = "#tags",
features = "src/test/assets/features/",
format = { "pretty","html: cucumber-html-reports", "json: cucumber-html-reports/cucumber.json" },
dryRun = false,
glue = "com.novomnetworks.formeval.truckcalibrator.test" )*/
public class CucumberTest extends ActivityInstrumentationTestCase2<MainActivity> {
private static final String TAG = "CucumberTest";
Solo solo;
public CucumberTest() {
super(MainActivity.class);
}
#Before
protected void before() throws Exception {
Log.d(TAG, "setUp");
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
getActivity().resetDB();
}
#After
protected void after() throws Exception {
Log.d(TAG, "tearDown");
solo.finishOpenedActivities();
super.tearDown();
}
#Given("^I started the app$")
public void i_started_the_app() throws Throwable {
solo.waitForActivity(MainActivity.class);
throw new PendingException();
}
#Then("I should see the action bar")
public void I_should_see_the_action_bar() throws Exception {
assertNotNull(getActivity().getMenu());
}
#Given("I am on the clients list")
public void I_am_on_the_clients_list() throws Exception {
solo.waitForFragmentById(R.layout.fragment_clients);
}
#Then("^I should see the clients list header$")
public void I_should_see_the_clients_list_header() throws Exception {
assertTrue(solo.searchText(solo.getString(R.string.clients)));
assertTrue(solo.searchText(solo.getString(R.string.sorted_by)));
assertNotNull(solo.getView(R.id.clients_spinner));
}
#Then("I should see the new client button")
public void I_should_see_the_new_client_button() throws Exception {
assertNotNull(solo.getView(R.id.action_new_client).isShown());
}
#Then("^I should see the clients list$")
public void I_should_see_the_clients_list() throws Exception {
assertNotNull(solo.getView(R.id.clients));
}
}
And this is my feature file :
Feature: Démarrage de l'app
Scenario: La barre de menu devrait s'afficher
Given I started the app
Then I should see the action bar
Scenario: La liste des clients devrait s'afficher
Given I started the app
Then I should see the clients list header
And I should see the new client button
And I should see the clients list
When I run my Cucumber test configuration, (screenshot bellow) The features are found but my step definitions are not. The output says
Undefined step: Given I started the app
Undefined step: Then I should see the action bar
Undefined step: Given I started the app
Undefined step: Then I should see the clients list header
Undefined step: And I should see the new client button
Undefined step: And I should see the clients list
2 Scenarios (2 undefined)
6 Steps (6 undefined)
0m0,000s
You can implement missing steps with the snippets below:
#Given("^I started the app$")
public void i_started_the_app() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
[other similar suggestions...]
I've searched the web for a whole day without finding the correct way to link my step definitions file. Every post I find seems to tell people to mention the test package in the configuration field Glue and this is what I've done, but it's no use. If you look closely to my CucumberTest.java file, you can see that I tried with a #CucumberOptions annotation too but it did not change the result. I also tried with and without the #RunWith(Cucumber.class) annotation.
What am I doing wrong?
You are throwing an exception: throw new PendingException();
in
#Given("^I started the app$")
public void i_started_the_app() throws Throwable {
solo.waitForActivity(MainActivity.class);
throw new PendingException();
}
I came across the same problem and I think I solved it. First, we need to use androidTestCompile configurations on all cucumber related libraries. Note that we need to use #jar qualifier for cucumber-android library to avoid gradle getting the apklib file instead of the jar file. For example :
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
...
androidTestCompile 'info.cukes:cucumber-core:1.2.0'
androidTestCompile 'info.cukes:cucumber-java:1.2.0'
androidTestCompile 'info.cukes:gherkin:2.12.2'
androidTestCompile 'info.cukes:cucumber-html:0.2.3'
androidTestCompile 'info.cukes:cucumber-android:1.2.0#jar'
}
Secondly, we don't need to use cucumber-java plugin for Android Studio. We need to run the test on the emulator/device, and I can't find a way to set that up with cucumber-java plugin. Instead, just use Android Test for your run configurations and set the Specific Instrumentation Runner to cucumber.api.android.CucumberInstrumentation.
And the last thing I noticed is that you don't need to use #RunWith annotation. Just use #CucumberOptions on one of your classes, and it works.
Your tests should be in folder src/androidTest instead of src/test
Also I would separate the CucumberTest.java into one class for Cucumber Runner with the configuration annotations and a separate class extending from ActivityInstrumentationTestCase2 containing your glue code.
Here you have a running example for Android Studio using Cucumber and Espresso instead of Robotium:
https://github.com/neoranga55/CleanGUITestArchitecture