Why are my Cucumber definition steps undefined in Android Studio - android

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

Related

AWS Amplify for Android - Cannot resolve symbol 'AmplifyModelProvider'

Good day all,
I am implementing AWS Amplify DataStore for android following the docs, and basically i get this error when i try to initialize the data store plugin on amplify according to this part of the doc:
Cannot resolve symbol 'AmplifyModelProvider'
You can find code from my gradle files and my application class below.
I am not an android expert, but i believe this is because of a missing dependency or i am doing something wrong during initialization or assignation of the ModelProvider. But i cant find any information on internet about this issue or any possible solution.
Thanks in advance for your help.
Steps to reproduce:
Create new android project
Install Amplify CLI, using npm, npm install -g #aws-amplify/cli
Configure amplify, amplify configure
On new android project root folder, run amplify init, amplify init
On new android project root folder, run amplify add auth, amplify add auth, adding authentication
Create android application class
Add android application class to AndroidManifest.xml
Try to add data store plugin to amplify on onCreate method of the application class
I already try the following solutions:
Clean project
Rebuild project
Run Make Project
Close and open again Android Studio
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bakeano.htejobs">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MyApplication.java
package com.bakeano.htejobs;
import android.app.Application;
import android.util.Log;
import com.amazonaws.mobile.client.AWSMobileClient;
import com.amazonaws.mobile.client.Callback;
import com.amazonaws.mobile.client.UserStateDetails;
import com.amplifyframework.api.aws.AWSApiPlugin;
import com.amplifyframework.core.Amplify;
import com.amplifyframework.core.model.ModelProvider;
import com.amplifyframework.datastore.AWSDataStorePlugin;
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// AWSMobileClient initialization
AWSMobileClient.getInstance().initialize(getApplicationContext(), new Callback<UserStateDetails>() {
#Override
public void onResult(UserStateDetails result) {
try {
ModelProvider modelProvider = AmplifyModelProvider.getInstance(); // Error on this line !!!
Amplify.addPlugin(AWSDataStorePlugin.forModels(modelProvider));
Amplify.addPlugin(new AWSApiPlugin());
Amplify.configure(getApplicationContext());
} catch (Exception e) {
Log.e("bakeanoMessage", "Amplify adding plugins Exception: " + e.getMessage(), e);
}
}
#Override
public void onError(Exception e) {
Log.e("bakeanoMessage", "AWSMobileClient init Exception: " + e.getMessage(), e);
}
});
}
}
Module Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.bakeano.htejobs"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// androidx constraint layout
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
// aws amplify framework core
implementation 'com.amplifyframework:core:0.10.0'
// AWSMobileClient
implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.16.11'
// aws amplify for the drop-in ui
implementation 'com.amazonaws:aws-android-sdk-auth-userpools:2.16.11'
implementation 'com.amazonaws:aws-android-sdk-auth-ui:2.16.11'
// aws amplify api
implementation 'com.amplifyframework:aws-api:0.10.0'
// aws amplify data store
implementation 'com.amplifyframework:aws-datastore:0.10.0'
}
Project Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
// amplify tools gradle plugin
classpath 'com.amplifyframework:amplify-tools-gradle-plugin:0.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
// applying the amplify tools plugin
apply plugin: 'com.amplifyframework.amplifytools'
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Solution provided by Jameson Williams:
at projects github issue platform - issue #370
AmplifyModelProvider is an autogenerated file that is created by amplify codegen
amplify codegen models
after manual generation you need to import it:
import com.amplifyframework.datastore.generated.model.AmplifyModelProvider;
Thanks !!

apk file does not contain the java file

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.

Get compiled .class output directory in Android Gradle task

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.

Android Studio Espresso Testing Error: Empty Test Suite

I keep running into the following error when trying to execute my tests in Android Studio: Test running failed: Unable to find instrumentation info for: ComponentInfo{.test/android.support.test.runner.AndroidJUnitRunner}
My test class is in the androidTest/java directory and has a constructor. My build.gradle is correct too. Any help is appreciated.
Test Class
#RunWith(AndroidJUnit4.class)
#LargeTest
public class AndroidUITests extends ActivityInstrumentationTestCase2<UserActivity>{
private UserActivity userActivity;
public AndroidUITests() {
super(UserActivity.class);
}
#Before
public void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
userActivity = getActivity();
}
#Test
public void testPhoneIconIsDisplayed() {
// When the phone_icon view is available,
// check that it is displayed.
onView(ViewMatchers.withId(R.id.groupCreate)).perform(click())
.check(matches(withText("Enter a name")));
}
}
app/build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
dependencies {
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
}
While the question is already answered, figured it was worth posting for future visitors.
Make sure you check the logcat logs to ensure something isn't causing issues (crash) before the test is even run. I had bad code in my #BeforeClass block which resulted in the "Empty Test Suite" message in Android Studio despite having properly set the test runner.
You have to update the test "Edit Configuration" and include the AndroidJUnitRunner as the instrumentation runner.
I found the solution in this video:
https://youtu.be/TGU0B4qRlHY?t=9m36s
Updated
Adding what #loeschg suggest:
Make sure you check the logcat logs to ensure something isn't causing issues (crash) before the test is even run. Bad code in the #BeforeClass block could resulted in the "Empty Test Suite" message in Android Studio despite having properly set the test runner.
If you get such error message:
Class not found: "com.example.product.package.name.SomeSpecificTest" Empty test suite.
You need to make sure if your Espresso test is added under Android Instrumented Tests section in Run/Debug Configurations.
It seems like Android Studio 3.1.3 is sometimes adding it incorrectly to Android JUnit section instead.
Make sure it looks something like this:
Also, worth mentioning that I've noticed, that this issue occurs for me while a non Debug build variant is selected.
I'm fairly certain android.support.test.runner.AndroidJUnitRunner is provided by the runner library.
Install the Android Support Repository (which you've already done)
Add runner to your dependencies
it should look like this
dependencies {
...
androidTestCompile 'com.android.support.test:runner:0.2'
}
If anyone still bother with this in 2018, here is working setup:
build.gradle (required):
<...snip...>
android {
defaultConfig {
<...snip...>
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// ^^^ here it is (first)!
}
<...snip...>
dependencies {
<...snip...>
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
// ^^^ all three required ^^^ (second)
}
And in instrumented tests (required too):
import androidx.test.espresso.Espresso.onData
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.*
import androidx.test.espresso.matcher.RootMatchers.*
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.hamcrest.Matchers.*
import org.junit.Test
import org.junit.runner.RunWith
#RunWith(AndroidJUnit4::class)
#LargeTest
class ApplicationTest {
#Test
fun thruStillThrullyThrue() {
// do interaction with some UI
onView(withId(R.id.myButtonOnMyActivity)).perform(click())
// assert expected result
onView(withId(R.id.myTextViewOnMyActivity)).check(matches(isDisplayed()))
}
}
// (third)
My issue was that the field 'testInstrumentationRunner' is specified in the build.gradle (app). Change that to the androidx if you are using it (androidx.test.runner.AndroidJUnitRunner)
Hope it helps someone, cheers!

RoboGuice 3.0 NoClassDefFoundError: AnnotationDatabaseImpl

For some reason the RoboBlender does not generate the annotation database.
My build.gradle has the following dependencies:
dependencies {
provided 'org.roboguice:roboblender:3.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.roboguice:roboguice:3.0'
}
This is not a final solution, but it can help you. I don't know why, but RoboGuice 3.0 and 3.0.1 throws this exception. What you have to do is disable annotations for databases in your MainActivity as follows:
static {
RoboGuice.setUseAnnotationDatabases(false);
}
I hope this help
Ok, so it seems that since I didn't have any injection in the main class MainActivity it didn't trigger the annotation processing of the inner AsyncTask. Therefore no annotation database was created.
Moreover, it seems that injection in anonymous inner classes is not supported. So the AsyncTask needs to be a proper class (it can still be inside the MainActivity).
I haven't figured out yet how to tell RoboGuice to inspect the inner classes even though the outer one does not have injections.
What does the rest of your project structure look like?
Specifically, have you read the RoboBlender wiki
Later versions of Android Studio will, by default, generate a project that falls into the Configuring RoboBlender for a large application using libraries-category.
Fix below does the following:
Rearrange dependencies in build.gradle
Supplies pointer to GuiceModule in project
Rudimentary module for your project
diff --git a/app/build.gradle b/app/build.gradle
index 1e69cec..8450fff 100644
--- a/app/build.gradle
+++ b/app/build.gradle
## -34,9 +34,9 ## android {
}
dependencies {
- provided 'org.roboguice:roboblender:3.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.roboguice:roboguice:3.0'
+ provided 'org.roboguice:roboblender:3.0'
}
project.tasks.withType(JavaCompile) { task ->
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 017d11e..dba9e49 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
## -8,6 +8,7 ##
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="roboguice.annotations.packages" android:value="org.jush.roboguice3test"/>
+ <meta-data android:name="roboguice.modules" android:value="org.jush.roboguice3test.GuiceModule"/>
<activity
android:name="org.jush.roboguice3test.MainActivity"
android:label="#string/app_name" >
package org.jush.roboguice3test;
import android.app.Application;
import com.google.inject.AbstractModule;
public class GuiceModule extends AbstractModule {
private Application application;
public GuiceModule(Application application) {
this.application = application;
}
#Override
protected void configure() {
}
}
What did you have to do that it did trigger the annotation processing? My main activity has injections. The maina activity inherits from an abstract activity which has as well injections. That abstract activity inherits from RoboActivity.
When i set the roboguice.annotations.packages to roboguice the NoClassFound exception isn't thrown anymore, but i get a NullPointer Exception for the first inject-Object that I wanna use.
I use eclipse to start the app.
When I disable RoboBlender (RoboGuice.setUseAnnotationDatabases(false);) injection works.
The AnnotationDatabaseImpl is generated at compile time
An explanation is available here
Injected objects became null after upgrading to Roboguice 3

Categories

Resources