Android ChimpChat throws exception - android

I am trying to get chimpchat to work for Android. This is my class
import java.util.Map;
import java.util.TreeMap;
import com.android.chimpchat.ChimpChat;
import com.android.chimpchat.adb.AdbBackend;
import com.android.chimpchat.core.IChimpDevice;
import com.android.chimpchat.core.TouchPressType;
public class TapTest {
public static void main(String[] args)
{
Map<String, String> options = new TreeMap<String, String>();
options.put("backend", "adb");
options.put("adbLocation", "D:\\Android\\platform-tools\\adb.exe");
ChimpChat chimpchat = ChimpChat.getInstance(options);
IChimpDevice device = chimpchat.waitForConnection(5000, ".*");
device.touch(100, 100, TouchPressType.DOWN_AND_UP);
chimpchat.shutdown();
}
}
and running this gives me this exception
Exception in thread "main" java.lang.NoClassDefFoundError: com/android/ddmlib/TimeoutException
at com.android.chimpchat.adb.AdbBackend.waitForConnection(AdbBackend.java:122)
at com.android.chimpchat.ChimpChat.waitForConnection(ChimpChat.java:91)
at TapTest.main(TapTest.java:21)
Caused by: java.lang.ClassNotFoundException: com.android.ddmlib.TimeoutException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
I have added Chimpchat.jar,guava.jar, monkeyrunner.jar, sdklib.jar, jython-standalone.jar.

Why don't you use uiautomator instead?
I see the uiautomator as the better tool for inspecting UI elements. It has more powerful methods to identify UI objects and interact with them. You no longer need to place sleep commands in your script. Just wait for a specific element. You can wait for an element to appear or disappear.
You can have watchers which run in case an UI object is not found. This can be helpful when handling pop-ups and error messages.
Here's a link to a tutorial. http://developer.android.com/tools/testing/testing_ui.html

As the error say. You need to add ddmlib.jar too.

Related

Unable to cast the main Activity to Location Listener i.e. com.google.android.gms.location.LocationListener [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
as i am done with my coding and tired to check whats going on with the app on emulator and stuck with an error called java.lang.ClassCastException i.e
UserLocation cannot be cast to com.google.android.gms.location.LocationListener
My LOG CAT AS FOLLOWS
SO guys please help me to solve this problem :D
java.lang.ClassCastException:
com.example.surajnath.taproute.UserLocation cannot be cast to
com.google.android.gms.location.LocationListener
at
com.example.surajnath.taproute.UserLocation.startLocationUpdate(UserLocation.java:255)
at
com.example.surajnath.taproute.UserLocation.onConnected(UserLocation.java:292)
at com.google.android.gms.common.internal.zzae.zzk(Unknown Source)
at com.google.android.gms.common.api.internal.zzbd.zzj(Unknown Source)
at com.google.android.gms.common.api.internal.zzar.zzaht(Unknown
Source)
at com.google.android.gms.common.api.internal.zzar.onConnected(Unknown
Source)
at com.google.android.gms.common.api.internal.zzbl.onConnected(Unknown
Source)
at com.google.android.gms.common.api.internal.zzw.onConnected(Unknown
Source)
at com.google.android.gm=s.common.intern
al.zz+ac.onC++de here`onn+ected(Unknown Source)
at com.google.android.gm=s.common.internal.zzn.zzakg(Unknown Source)
at com.google.android.gm=s.common.internal.zze.zzv(Unknown Source)
at com.google.android.gm=s.common.internal.zzi.zzakh(Unknown Source)
at
com.google.android.g+ms.common.internal.z+z+h.h+an+d+l+e+M+e+s+s+age(Unknown
Source)
at android.o+s.Handler.dispatch+Message(Handler.java:102)
at android.o+s.L+ooper.loop(Loo+per.java:154)
at android.app.Activity+Thread.main(Activity+Thread.java:6682)
at java.la+n+g.reflect.Method.invoke(Native Method)
at
Now link to my code is below
https://pastebin.com/3h3CnHWb
I think you are using the wrong import in UserLocation
following
import android.location.LocationListener;
should be
import com.google.android.gms.location.LocationListener;
you need this in your gradle dependencies
implementation 'com.google.android.gms:play-services-location:11.6.0'

Can I work on Selenium and Android in same workspace?

For a project I am writing Selenium test cases for automation. On the other hand for other project I am designing a page in Android.
I have created some part of page in Android and now need to finish Selenium test cases. But as soon as I run one big error came. Then I thought that I have to change my workspace and kept Selenium test cases in another work space even then error is coming (different error).
Below is the error after changing workspace:
org.testng.TestNGException: Cannot find class in classpath: inventory
at org.testng.xml.XmlClass.loadClass(XmlClass.java:81) at
org.testng.xml.XmlClass.init(XmlClass.java:73) at
org.testng.xml.XmlClass.<init>(XmlClass.java:59) at
org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:543)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown
Source) at
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown
Source) at
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(Unknown
Source) at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
Source) at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
Source) at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
Source) at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source) at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source) at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source) at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
Source) at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
Source) at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
Source) at
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown
Source) at javax.xml.parsers.SAXParser.parse(Unknown Source) at
org.testng.xml.XMLParser.parse(XMLParser.java:39) at
org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17) at
org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10) at
org.testng.xml.Parser.parse(Parser.java:168) at
org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:311) at
org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88) at
org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204) at
org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Yes. You can create both projects in same work space.

Android - Proguard error with static String

I'm running ProGuard for my release build and trying to optimize it as much as possible. The only custom rules I've added so far are Serialization and Facebook ones. I'm running my release build now and I'm getting a stack trace and what it maps back to is really throwing me off. Here's my stack trace:
java.lang.NullPointerException
E/AndroidRuntime(10842): at com.myapp.android.myapp.dh.a(Unknown Source)
E/AndroidRuntime(10842): at android.support.v4.app.Fragment.b(Unknown Source)
E/AndroidRuntime(10842): at android.support.v4.app.w.a(Unknown Source)
E/AndroidRuntime(10842): at android.support.v4.app.p.onCreatePanelMenu(Unknown Source)
E/AndroidRuntime(10842): at android.support.v7.a.g.a(Unknown Source)
E/AndroidRuntime(10842): at android.support.v7.a.m.a(Unknown Source)
E/AndroidRuntime(10842): at android.support.v7.a.g.onCreatePanelMenu(Unknown Source)
In mapping, com.myapp.android.myapp.dh.a is:
com.myapp.android.myapp.LocalFragment -> com.myapp.android.myapp.dh:
java.lang.String USER_ACCOUNT -> a
In my actual code it's this:
public static String USER_ACCOUNT = "com.myapp.android.myapp.LocalFragment.user_account";
Now this constant is used in multiple places throughout this Fragment, but it should never be null. Anyone seen a problem like this before? Does Proguard do weird stuff with statics?
Edit: This error is thrown and the app crashes basically as soon as I take the action that would load this Fragment.
EDIT AGAIN
After a bit more investigation, I was wrong about what a was. a was that Static member, but a is also a method. It's the onCreate method. I'm also seeing this error in logcat before the NPE is thrown in onCreate:
W/SupportMenuInflater(10842): Cannot instantiate class: android.support.v7.widget.SearchView
W/SupportMenuInflater(10842): java.lang.NoSuchMethodException: <init> [class android.content.Context]
W/SupportMenuInflater(10842): at java.lang.Class.getConstructorOrMethod(Class.java:472)
W/SupportMenuInflater(10842): at java.lang.Class.getConstructor(Class.java:446)
W/SupportMenuInflater(10842): at android.support.v7.internal.view.e.a(Unknown Source)
W/SupportMenuInflater(10842): at android.support.v7.internal.view.e.a(Unknown Source)
W/SupportMenuInflater(10842): at android.support.v7.internal.view.c.a(Unknown Source)
W/SupportMenuInflater(10842): at android.support.v7.internal.view.c.inflate(Unknown Source)
W/SupportMenuInflater(10842): at com.myapp.android.myapp.dh.a(Unknown Source)
You have a problem with proguard obfuscating the support libraries, or specifically, the SearchView component that you probably try to initiate in your fragment. To avoid this, you need to add few exclusions to proguard configuration file (proguard.cfg).
-keep class android.support.v7.widget.** { *; }
-keep interface android.support.v7.widget.** { *; }
This will keep all classes and interfaces inside the widget package of the support library from being obfuscated.

Google Analytics - NullPointerException in Test

I'm getting the following NPE in a Robolectric test on a Travis build-server, and I'm having trouble pinpointing why. I'm unable to reproduce this issue locally.
Anybody know what causes onServiceConnected to be called? That might help me pinpoint the issue. From what I can tell this is a Google Play Services - Google Analytics issue.
java.lang.NullPointerException
at com.google.android.gms.analytics.c$a.onServiceConnected(Unknown Source)
at com.google.android.gms.analytics.c$a.onServiceConnected(Unknown Source)
at org.robolectric.shadows.ShadowApplication$2.run(ShadowApplication.java:257)
at org.robolectric.util.Scheduler$PostedRunnable.run(Scheduler.java:162)
at org.robolectric.util.Scheduler.runOneTask(Scheduler.java:107)
at org.robolectric.util.Scheduler.advanceTo(Scheduler.java:92)
at org.robolectric.util.Scheduler.advanceToLastPostedRunnable(Scheduler.java:68)
at org.robolectric.util.Scheduler.unPause(Scheduler.java:25)
at org.robolectric.shadows.ShadowLooper.unPause(ShadowLooper.java:228)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:267)
at org.robolectric.util.ActivityController.create(ActivityController.java:144)
at org.robolectric.util.ActivityController.create(ActivityController.java:154)
at com.company.search.activities.loginjoin.LoginActivityTest.setup(LoginActivityTest.java:20)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:250)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:86)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:50)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:105)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
To my knowledge, I'm not initializing GA anywhere for my unit tests. I have a general "fake" analytics tracker that gets used whenever tests are run. Just in case, I've added the following line in the constructor of my fake tracker which gets created in onCreate of the application:
GoogleAnalytics.getInstance(context).setAppOptOut(true);
In case this is of relevance, it's breaking on a box with Java 1.7.0_u55.
EDIT:
I saw the following in the logs of a failed test today. I'm not sure it was the cause of the crash though. Might give some insight.
E/GAV3: Thread[GAThread,5,main]: Error on GAThread: java.lang.NullPointerException
at org.robolectric.shadows.ShadowLooper.getMainLooper(ShadowLooper.java:66)
at android.os.Looper.getMainLooper(Looper.java)
at android.database.sqlite.SQLiteDatabase.isMainThread(SQLiteDatabase.java:391)
at android.database.sqlite.SQLiteDatabase.getThreadDefaultConnectionFlags(SQLiteDatabase.java:381)
at android.database.sqlite.SQLiteProgram.__constructor__(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:41)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:992)
at android.database.DatabaseUtils.longForQuery(DatabaseUtils.java:799)
at android.database.sqlite.SQLiteDatabase.getVersion(SQLiteDatabase.java:862)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:242)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at com.google.android.gms.analytics.ac$a.getWritableDatabase(Unknown Source)
at com.google.android.gms.analytics.ac$a.getWritableDatabase(Unknown Source)
at com.google.android.gms.analytics.ac.G(Unknown Source)
at com.google.android.gms.analytics.ac.G(Unknown Source)
at com.google.android.gms.analytics.ac.i(Unknown Source)
at com.google.android.gms.analytics.ac.i(Unknown Source)
at com.google.android.gms.analytics.s.bk(Unknown Source)
at com.google.android.gms.analytics.s.bk(Unknown Source)
at com.google.android.gms.analytics.s.bJ(Unknown Source)
at com.google.android.gms.analytics.s.bJ(Unknown Source)
at com.google.android.gms.analytics.s.a(Unknown Source)
at com.google.android.gms.analytics.s$2.run(Unknown Source)
at com.google.android.gms.analytics.s$2.run(Unknown Source)
at com.google.android.gms.analytics.t.run(Unknown Source)
at com.google.android.gms.analytics.t.run(Unknown Source)
E/GAV3: Thread[GAThread,5,main]: Google Analytics is shutting down.
Looks like a problem with SQLite and GA?
Another Update:
For updates, see the linked github issue (https://github.com/robolectric/robolectric/issues/1075). I'm reverting back to v3 for the time being.
The solution of Akeem works for me.
This is what I use for Robolectic 3.0, which has some changes:
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.shadows.ShadowApplication;
ShadowApplication shadowApplication = Shadows.shadowOf(RuntimeEnvironment.application);
shadowApplication.declareActionUnbindable("com.google.android.gms.analytics.service.START");
The fix is to add the following lines in ALL of your test suites (because you don't know which test case would be run first)
ShadowApplication shadowApplication = Robolectric.shadowOf(Robolectric.application);
shadowApplication.declareActionUnbindable("com.google.android.gms.analytics.service.START");
Alternatively you can create a custom shadow class for your application that doesn't bind services:
import android.app.Application;
import android.content.Intent;
import android.content.ServiceConnection;
import android.util.Log;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadows.ShadowApplication;
#Implements(Application.class)
public class MyShadowApplication extends ShadowApplication {
#Implementation
public boolean bindService(Intent intent, final ServiceConnection serviceConnection, int i) {
Log.d("Robolectric", intent.getAction());
return false;
}
}
And run all your test cases with the shadow class
#Config(emulateSdk = 18, shadows = {MyShadowApplication.class})
This is what I figured out (and solved in my case) :
Somewhere (probably when initializing Google Analytics), there is a call to start a service.
I thought that this call was to start one of my app's services, so I added
Robolectric.getShadowApplication().setComponentNameAndServiceForBindService(
new ComponentName(Robolectric.application, MyService.class),
new StalkerService() {
#Override
public Context getApplicationContext() {
return Robolectric.application;
}
}.onBind(null)
);
in my TestApplication code, before calling super.onCreate.
Gladly, it solved my problem - no more NPE, and all tests pass.
But, then I noticed that this is very weird solution, since I'm providing Robolectric the binder for my Service and not GA service... But it works, and I'm not sure why.
So, I'm going to leave it here for you to test if it fixes your issues too.

android.support.v4 causing force close on some devices

I have one application listed in playstore, for which some user have reported force close issue. I went to developer console to see the details and that showed the following message. I have used android support library in the application. The class extends FragmentActivity and the other imports i have used are
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
Stacktrace
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.support.v4.a.h.done(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)
Caused by: java.lang.NullPointerException
at my.package.name.k.n(Unknown Source)
at my.package.name.k.d(Unknown Source)
at android.support.v4.a.a.e(Unknown Source)
at android.support.v4.a.b.a(Unknown Source)
at android.support.v4.a.b.a(Unknown Source)
at android.support.v4.a.g.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
... 4 more
For applications that include obfuscated code, stack traces contain obfuscated symbol
names. If the application was obfuscated using ProGuard, you can unobfuscate the stack
trace using the "retrace" tool, included in the Android SDK Tools r8 and later. For
more information, see the ProGuard document.

Categories

Resources