Android JUnitRunner Empty Test Suite: No Test Results - android

I'm having trouble running tests in Android Studio. I've read through a load of posts with the same problem here on Stack Overflow, but to no avail. Just to be clear, I want to test in the emulator and not in the JVM.
Run configuration:
Output:
Running tests
Test running startedTest running failed: No test results
Empty test suite.
Build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "ntnu.stud.markul.crowdshelf"
minSdkVersion 19
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'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
// Unit testing dependencies
androidTestCompile ('com.android.support.test:rules:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test:runner:0.3') {
// Necessary if your app targets Marshmallow (since the test runner
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.12'
}
The test class (located in /src/androidTest/java/com/appname/app/):
#RunWith(AndroidJUnit4.class)
public class NetworkAndDBInstrumentationTest extends ActivityInstrumentationTestCase2<MainActivity> {
private MainActivity mActivity;
public NetworkAndDBInstrumentationTest() {
super(MainActivity.class);
}
#Before
public void setUp() throws Exception {
super.setUp();
// Injecting the Instrumentation instance is required
// for your test to run with AndroidJUnitRunner.
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
mActivity = getActivity();
}
#Test
public void typeOperandsAndPerformAddOperation() {
NetworkController.getCrowd("55f01f29f0a5fad2120bb1db");
System.out.print("ok");
Log.d("1TEST", "1TEST");
}
#After
public void tearDown() throws Exception {
super.tearDown();
}
}

I got it to work using this:
#RunWith(AndroidJUnit4.class)
#LargeTest
public class NetworkAndDBInstrumentationTest {
//use the following annotation and declare an ActivityTestRule for your activity under test
#Rule
public ActivityTestRule<RealmActivity> mActivityRule = new ActivityTestRule(RealmActivity.class);
//use #Before to setup your test fixture
#Before
public void setUp() { }
//annotate all test methods with
#Test
public void testGetCrowd() {
Assert.assertEquals(1, 1);
}
#After
public void tearDown() { }
}
Where RealmActivity is the Activity I want to test. Build.gradle and everything else is as in the question post. Now, a follow-up question: What does it matter that I make the #Rule with RealmActivity? Can't I use other Activities in that test? Can I make a Activity-independent test?

Your configuration looks right. You can try to add this to your build.gradle file:
/*
* Working build.gradle test config. Gradle version 1.3.0
*/
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "test.your.app"
minSdkVersion 15
targetSdkVersion 23
versionCode versionMajor * 100 + versionMinor * 10 + versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
}
configurations.all {
// Currently espresso is dependent on support-annotations:22.2.1
resolutionStrategy.force 'com.android.support:support-annotations:22.2.1'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
disable 'SetJavaScriptEnabled'
disable 'InvalidPackage'
abortOnError false
textReport true
textOutput 'stdout'
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
applicationIdSuffix '.debug'
testCoverageEnabled = true
}
release {
}
}
productFlavors {
dev {
versionName "DEV"
}
}
sourceSets { //this one may not be needed. But wont hurt.
androidTest.setRoot('src/androidTest')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// Android
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:support-v13:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-annotations:23.0.1'
// Google Play Services
compile 'com.google.android.gms:play-services-base:7.8.0'
compile 'com.google.android.gms:play-services-analytics:7.8.0'
compile 'com.google.android.gms:play-services-appindexing:7.8.0'
// Integration Tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2'
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2') {
exclude group:'com.android.support', module:'support-v4'
exclude module: 'recyclerview-v7'
}
// Unit Tests
testCompile 'junit:junit:4.12'
testCompile 'com.google.truth:truth:0.25'
//Mocking
androidTestCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile "com.google.dexmaker:dexmaker:${DEXMAKER_VERSION}"
androidTestCompile "com.google.dexmaker:dexmaker-mockito:${DEXMAKER_VERSION}"
androidTestApt "com.google.dagger:dagger-compiler:${DAGGER_VERSION}"
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test:runner:0.3'
// Leak detection
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
}
You could also try using JUnit 3 style to see if that gets better results. Are you extending ApplicationTestCase? Try and get things working there.

I think you need add this line in your dependencies:
androidTestCompile ('org.hamcrest:hamcrest-library:1.3')

Related

Android app crash NoClassDefFoundError on Samsung Lollipop devices

We recently bumped the minSdkVersion of our app from 16 (Jellybean) to 21 (Lollipop). Although we did extensive testing with our app predominantly using debug builds, we are now facing a slew of production crashes at app startup, predominantly on older Samsung devices - (Note3 and S4 are the top crashers) and always on Lollipop.
The error is
Fatal Exception: java.lang.NoClassDefFoundError: com.retailconvergence.ruelala.delegate.GoogleLoginDelegate
at com.retailconvergence.ruelala.delegate.LifecycleDelegateManager.addDelegateOfType(LifecycleDelegateManager.java:48)
at com.retailconvergence.ruelala.extensions.activity.LifecycleDelegateActivity.addDelegateOfType(LifecycleDelegateActivity.java:55)
at com.retailconvergence.ruelala.activity.SplashActivity.setupDelegates(SplashActivity.java:198)
at com.retailconvergence.ruelala.activity.SplashActivity.onCreate(SplashActivity.java:60)
at android.app.Activity.performCreate(Activity.java:6288)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
The SplashActivity is the initial lauching activity of the app. The class not found is a long-established class not something newly introduced. As a side note, as part of this latest release we upgraded to Android Studio 3 and introduced Kotlin code, but I dont think these are related to the issue. We are not using proguard in the build.
I'm aware that there was a significant change for builds when the minSdkVersion is 21 and above, relating to the use of ART instead of Dalvik, so I'm wondering if there is some flaw with Samsung Lollipop devices still looking for a class in the primary dex file now?
The module-level build.gradle:
import java.text.SimpleDateFormat
import java.util.concurrent.TimeUnit
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'
apply plugin: 'spoon'
// Manifest version information
def versionMajor = 4
def versionMinor = 2
def versionPatch = 0
def versionBuild = 0 // bump for dogfood builds, public betas, etc.
ext.versionReleaseDate="OCT-13-2017" // UPDATE THIS WHEN YOU BUMP THE VERSIONS ABOVE FOR A NEW RELEASE MMM-dd-yyy
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url 'http://salesforce-marketingcloud.github.io/JB4A-SDK-Android/repository' }
maven { url "https://maven.google.com" }
maven { url "http://maven.tealiumiq.com/android/releases/" }
}
def getCountOfHoursSinceVersionUpdate() {
def currentDate = new Date()
def format = new SimpleDateFormat("MMM-dd-yyyy")
def buildDate = (Date)format.parse(versionReleaseDate)
return (Integer)((currentDate.getTime() - buildDate.getTime()) / TimeUnit.HOURS.toMillis(1))
}
android {
compileSdkVersion 26
buildToolsVersion '26.0.1'
defaultConfig {
targetSdkVersion 25
/**
* Increment versionCode by commit count
*/
versionCode versionMajor * 100000 + versionMinor * 10000 + versionPatch * 1000 + versionBuild + getCountOfHoursSinceVersionUpdate()
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Enabling multidex support. :(
multiDexEnabled true
def manifestPath = project(':').file('app/src/androidTest/AndroidManifest.xml')
buildConfigField "String", "MANIFEST_PATH", "\"" + manifestPath + "\""
def resPath = project(':').file('app/src/main/res/')
buildConfigField "String", "RES_PATH", "\"" + resPath + "\""
def assetPath = project(':').file('app/src/prod/assets/')
buildConfigField "String", "ASSET_PATH", "\"" + assetPath + "\""
}
dexOptions {
javaMaxHeapSize "8g"
dexInProcess true // the magic line
}
flavorDimensions "debugDimension"
/**
* productFlavors override defaultConfig properties as well as force gradle to look in the new
* folders that we have created to differentiate the build assets and manifests.
* src/dev, src/prod
*/
productFlavors {
dev {
minSdkVersion 21
applicationId "com.retailconvergence.ruelala.dev"
versionName "${versionMajor}.${versionMinor}.0${versionPatch}"
manifestPlaceholders = [optimizelyId: "optly4740131949"]
dimension "debugDimension"
}
prod {
minSdkVersion 21
applicationId "com.retailconvergence.ruelala"
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
manifestPlaceholders = [optimizelyId: "optly4752051515"]
dimension "debugDimension"
}
}
signingConfigs {
prod {
//the key is up a level, don't include in the modules
storeFile file("../RueLaLaKeystore")
storePassword "Boutiques"
keyAlias "rue la la"
keyPassword "Boutiques"
}
}
buildTypes {
release {
signingConfig signingConfigs.prod
ext.betaDistributionReleaseNotesFilePath = 'release_notes.txt'
ext.betaDistributionGroupAliases = 'AndroidTesters'
ext.betaDistributionNotifications = true
}
debug {
versionNameSuffix '-dev'
signingConfig signingConfigs.prod
// to get coverage report, set testCoverageEnabled to true and run gradle task called createDevelopmentDebugAndroidTestCoverageReport
// Note that test coverage doesn't seem to work on Samsung devices, other brand or emulator should work though
testCoverageEnabled = false
ext.betaDistributionReleaseNotesFilePath = 'release_notes.txt'
ext.betaDistributionGroupAliases = 'AndroidTesters'
ext.betaDistributionNotifications = true
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'LICENSE.txt'
exclude 'LICENSE'
exclude 'READ.ME'
exclude 'README'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
configurations {
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//include our modules
compile project(':core')
compile project(':data')
//android
final APP_COMPAT_VERSION = '26.1.0'
compile "com.android.support:appcompat-v7:$APP_COMPAT_VERSION"
compile "com.android.support:recyclerview-v7:$APP_COMPAT_VERSION"
compile "com.android.support:design:$APP_COMPAT_VERSION"
compile "com.android.support:multidex:1.0.0"
compile "com.android.support:cardview-v7:$APP_COMPAT_VERSION"
// google
final PLAY_SERVICES_VERSION = '10.2.4'
compile "com.google.android.gms:play-services-wallet:$PLAY_SERVICES_VERSION"
compile "com.google.android.gms:play-services-location:$PLAY_SERVICES_VERSION"
compile "com.google.android.gms:play-services-gcm:$PLAY_SERVICES_VERSION"
compile "com.google.android.gms:play-services-plus:$PLAY_SERVICES_VERSION"
compile "com.google.android.gms:play-services-identity:$PLAY_SERVICES_VERSION"
compile "com.google.android.gms:play-services-analytics:$PLAY_SERVICES_VERSION"
compile "com.google.android.gms:play-services-auth:$PLAY_SERVICES_VERSION"
compile "com.google.android.gms:play-services-maps:$PLAY_SERVICES_VERSION"
// facebook
compile 'com.facebook.android:facebook-android-sdk:4.8.+'
compile 'com.facebook.stetho:stetho:1.1.0'
//markdown4j
compile 'org.commonjava.googlecode.markdown4j:markdown4j:2.2-cj-1.0'
//crashlytics
compile('com.crashlytics.sdk.android:crashlytics:2.5.2#aar') {
transitive = true;
}
//image zoom
compile 'com.github.chrisbanes.photoview:library:1.2.3'
//square
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.makeramen:roundedimageview:2.2.1'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
// optimizely
compile('com.optimizely:optimizely:1.4.2#aar') {
transitive = true
}
//braintree
compile 'com.braintreepayments.api:braintree:2.6.0'
compile 'com.braintreepayments.api:data-collector:2.+'
// guava
compile 'com.google.guava:guava:19.0'
// sticky headers
compile 'com.github.mtotschnig:StickyListHeaders:2.7.1'
// expandable recyclerview
compile 'eu.davidea:flexible-adapter:5.0.0-rc2'
//recyclerview animations
compile 'jp.wasabeef:recyclerview-animators:2.2.3'
// tooltip
compile 'com.github.michaelye.easydialog:easydialog:1.4'
// tealium
compile 'com.tealium:library:5.3.0'
// circle indicator
compile 'me.relex:circleindicator:1.2.2#aar'
//testing
final HAMCREST_VERSION = '1.3'
def jUnit = "junit:junit:4.12"
// ExactTarget SDK
compile ('com.salesforce.marketingcloud:marketingcloudsdk:5.0.5') {
exclude module: 'android-beacon-library' //remove to use Proximity messaging
exclude module: 'play-services-location' //remove to use Geofence or Proximity messaging
}
androidTestCompile jUnit
// Unit tests dependencies
testCompile jUnit
testCompile "org.hamcrest:hamcrest-core:$HAMCREST_VERSION"
testCompile "org.hamcrest:hamcrest-library:$HAMCREST_VERSION"
testCompile "org.hamcrest:hamcrest-integration:$HAMCREST_VERSION"
testCompile 'org.robolectric:robolectric:3.1'
testCompile 'org.mockito:mockito-core:1.+'
testCompile 'com.google.guava:guava:19.0'
testCompile("com.android.support:support-v4:$APP_COMPAT_VERSION") {
exclude module: 'support-annotations'
}
testCompile('org.powermock:powermock-api-mockito:1.6.4') {
exclude module: 'objenesis'
}
testCompile('org.powermock:powermock-module-junit4:1.6.4') {
exclude module: 'objenesis'
}
testCompile 'io.reactivex:rxandroid:1.0.1'
testCompile 'io.reactivex:rxjava:1.1.0'
// Espresso
androidTestCompile('com.android.support.test:runner:0.5') {
exclude module: 'support-annotations'
}
androidTestCompile('com.android.support.test:rules:0.5') {
exclude module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.2') {
exclude module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-web:2.2.2') {
exclude module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude module: 'support-annotations'
exclude module: 'recyclerview-v7'
exclude module: 'appcompat-v7'
exclude module: 'design'
exclude module: 'support-v4'
}
// allows java 8 compile
compile 'com.annimon:stream:1.1.2'
// For taking screenshots
androidTestCompile 'com.squareup.spoon:spoon-client:1.7.0'
testCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
compile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
apply plugin: 'com.google.gms.google-services'
spoon {
noAnimations = true
grantAllPermissions = true
}
apply plugin: 'devicefarm'
devicefarm {
projectName "Rue Mobile"
devicePool "Smoke Test Pool"
useUnmeteredDevices()
authentication {
accessKey System.getenv("AWS_DEVICE_FARM_ACCESS_KEY")
secretKey System.getenv("AWS_DEVICE_FARM_SECRET_KEY")
}
}
The fix for this was to disable pre-dexing:
dexOptions {
preDexLibraries false
}
in the app build.gradle. Inspiration for this came from this link regarding a Picasso class not found error on Lollipop: see here
Its not entirely clear to me why disabling pre-dexing solves the problem, but I can only theorize that there is some optimization going on with the build process that affects the way classes are ordered in the dex files of the apk that then affects the app installation on these Samsung Lollipop devices. In theory ART should take care of all of that, but clearly there is a dependency between pre-dex optimization and some Lollipop devices.

Testing my Application with Appium

Basically, I am trying to test my application which uses WebView in android studio. I have just started using appium. I went through a few videos and did set dependencies.
This is my gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.ac046137.myappium"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions
{
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
}
//apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile files('libs/commons-logging-1.1.3.jar')
compile files('libs/commons-lang3-3.4.jar')
compile files('libs/httpmime-4.4.1.jar')
compile files('libs/httpclient-4.4.1.jar')
compile files('libs/hamcrest-core-1.3.jar')
compile files('libs/hamcrest-library-1.3.jar')
compile files('libs/commons-collections-3.2.1.jar')
compile files('libs/commons-io-2.4.jar')
compile files('libs/commons-exec-1.3.jar')
compile files('libs/gson-2.3.1.jar')
compile files('libs/apache-mime4j-0.6.jar')
compile files('libs/commons-codec-1.10.jar')
compile files('libs/java-client-3.2.0.jar')
compile files('libs/httpcore-4.4.1.jar')
compile files('libs/guava-18.0.jar')
compile files('libs/commons-validator-1.4.1.jar')
compile files('libs/junit-4.12.jar')
compile files('libs/selenium-java-2.47.1 (1).jar')
compile files('libs/selenium-java-2.47.1-srcs.jar')
}
I have also included all the jar files.
This is my test script.
public class TestMe
{
AppiumDriver driver;
#BeforeClass
public void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("BROWSER_NAME", "");
capabilities.setCapability("VERSION", "4.4.2");
capabilities.setCapability("deviceName","MyTester");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage", "com.example.schoolhealthprogram");
// This package name of your app (you can get it from apk info app)
capabilities.setCapability("appActivity","com.example.schoolhealthprogram.MainActivity"); // This is Launcher activity of your app (you can get it from apk info app)
//Create RemoteWebDriver instance and connect to the Appium server
//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities) {
#Override
public WebElement scrollTo(String s) {
return null;
}
#Override
public WebElement scrollToExact(String s) {
return null;
}
};
}
#AfterClass
public void teardown(){
//close the app
driver.quit();
}
#Test
public void testme() throws Exception {
// Switch to WebView
Set<String> contextNames;
contextNames = driver.getContextHandles();
System.out.println(contextNames.size());
for (String contextName : contextNames)
{
System.out.println(contextName);
if (contextName.contains("WEBVIEW"))
{
driver.context(contextName);
}
}
// check WELCOME text is present
// Assert.assertEquals("School Health Program", driver.findElement(By.id("welcome_text")).getText());
// enter
driver.findElementById("AWC_SchoolNo").sendKeys("123");
driver.findElementById("AWC_SchoolName").sendKeys("St Johns");
// /click on submit button
// driver.findElementById("LoadImage").click();
// driver.findElementByName("Choose File").click();
// driver.findElementByName("LoadImage").click();
}
}
When the test script runs, it doesn't open the application I want it to open. There are no errors in logcat.

Why Otto is not working?

I am currently trying to install Otto into my project. Everything went as expected following the steps here http://square.github.io/otto/ but when I register my activities, I do not receive callbacks.
In my App class I have the singleton
private static Bus bus;
public static Bus getEventBus() {
if(bus == null) {
bus = new Bus(ThreadEnforcer.MAIN);
}
return bus;
}
Then in my BaseActivity class I have this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getContentView());
App.getEventBus().register(BaseActivity.this);
}
This is pseudo code but really these are the only methods I have in these classes. I also have suspicion of my gradle so my gradle file looks as follows
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "wallfly.io.wallfly"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
configurations {
all*.exclude group: 'org.apache.httpcomponents'
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/jackson-all-1.9.9.jar')
compile files('libs/commons-lang3-3.4.jar')
compile files('libs/httpclient-4.5.1.jar')
compile files('libs/httpcore-4.3.1.jar')
compile files('libs/httpmime-4.3.1.jar')
compile 'com.squareup:otto:1.3.8'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services:8.4.0'
}
apply plugin: 'com.google.gms.google-services'
I am using Otto at work and it goes really well. However I cannot get it to work at home. I am lost as it seems no one else has encountered this problem. Any help or resources would be greatly appreciated.

Does binding class will generate automatically?

I am developing a app with google databinding library. But i found every time i add a new layout xml and the correspond binding class won't generate. And i have to hit the build button on android studio, then the binding class will generate.
Here is the dependencies i use
app build.grade:
apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.jakewharton.hugo'
apply plugin: 'com.fernandocejas.frodo'
android {
signingConfigs {
}
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.xinpinget.gamecube"
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
productFlavors {
production {
signingConfig signingConfigs.config
}
internal {
}
}
// dexOptions {
// incremental true
// }
}
retrolambda {
jdk "/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home"
oldJdk System.getenv("JAVA_HOME")
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':insta-filter-release')
compile project(':library-debug')
compile('com.facebook.fresco:fresco:0.7.0') {
exclude module: 'support-v4'
}
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
// apt ('com.squareup.dagger:dagger-compiler:1.2.2') {
// }
compile('com.android.support:design:23.0.1') {
exclude module: 'support-v4'
exclude module: 'appcompat-v7'
}
compile('io.reactivex:rxandroid:1.0.1') {
exclude module: 'rxjava'
}
compile('io.reactivex:rxjava-debug:1.0.2') {
exclude module: 'rxjava'
}
compile('com.squareup.retrofit:adapter-rxjava:2.0.0-beta2') {
exclude module: 'rxjava'
}
internalCompile 'com.squareup.retrofit:retrofit-mock:2.0.0-beta1'
internalCompile 'com.squareup.retrofit:adapter-rxjava-mock:2.0.0-beta1'
compile('com.squareup.retrofit:converter-gson:2.0.0-beta2') {
exclude module: 'retrofit'
}
compile('com.umeng:fb:5.4.0') {
/**
* If not exclude message module, gradle will throw a error when building.
*/
exclude module: 'message'
exclude module: 'support-v4'
}
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.squareup:otto:1.3.8'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'io.reactivex:rxjava:1.0.14'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile project(':ShareSDK_oneKeyShare')
compile project(':sMSSDK')
compile 'com.android.support:cardview-v7:23.1.0'
}
I solved the problem.
It's caused by android-apt.
https://bitbucket.org/hvisser/android-apt/issues/38/android-apt-breaks-brand-new-data-binding

Android Studio with Robolectric: my class test is not found

This is my gradle file:
apply plugin: 'android'
apply plugin: 'android-test'
android {
// Check on it to know witch Android API level is necessary:
// http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
androidTest {
setRoot('src/test')
}
}
// Patch: http://stackoverflow.com/questions/20673888/duplicate-files-copied-android-studio-0-4-0
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
}
androidTest {
include '**/*Test.class'
exclude '**/espresso/**/*.class'
}
dependencies {
// Android SDK Extra librairies
compile 'com.android.support:support-v4:19.0.+'
compile 'com.android.support:appcompat-v7:19.0.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
// Android testing
// http://robolectric.org/
androidTestCompile 'junit:junit:4.+'
androidTestCompile 'org.robolectric:robolectric:2.+'
androidTestCompile 'com.squareup:fest-android:1.0.+'
// had to deploy to sonatype to get AAR to work
//compile 'com.novoda:actionbarsherlock:4.3.2-SNAPSHOT'
}
This my root gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
//classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
//classpath 'com.novoda.gradle:robolectric-plugin:0.0.1-SNAPSHOT'
classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.10.+'
}
}
allprojects {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
}
I just write an easy class to test to validate my infrastructure test, but I have this error:
Class not found: "com.example.myapp.activity.BaseActivityTest"
My test class is:
package com.example.myapp.activity;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.*;
#RunWith(RobolectricTestRunner.class)
public class BaseActivityTest {
#Test
public void testTrueIsTrue() throws Exception {
assertEquals(true, true);
}
}
My folder architecture is:
myapp
src
main
java
com.example.myapp ...
test
java
com.example.myapp ...
I don't understand why this error appears.
Ok guys, I found a solution:
This is my gradle file:
apply plugin: 'android'
apply plugin: 'robolectric'
android {
// Check on it to know witch Android API level is necessary:
// http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
androidTest {
setRoot('src/test')
}
}
}
// prevent the "superClassName is empty" error for classes not annotated as tests
tasks.withType(Test) {
scanForTestClasses = false
include "**/*Test.class" // whatever Ant pattern matches your test class files
}
dependencies {
// Android SDK Extra librairies
compile 'com.android.support:support-v4:19.0.+'
compile 'com.android.support:appcompat-v7:19.0.+'
compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
// Android testing
//androidTestCompile configurations.androidTestCompile.dependencies
// http://robolectric.org/
androidTestCompile 'org.robolectric:robolectric:2.+'
androidTestCompile 'junit:junit:4.+'
}
And I modified my VM argument (Configuration edition) like this post: http://blog.futurice.com/android_unit_testing_in_ides_and_ci_environments

Categories

Resources