Google Analytics - NullPointerException in Test - android

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.

Related

gradlew assembleRelease Fails With java.lang.ClassNotFoundException: com.sun.tools.javac.util.Context

Sidenote - this post is similar (but not identical) to compileReleaseKotlin fails with java.lang.ClassNotFoundException: com.sun.tools.javac.util.Context, but I thought I'd make my own post with more details about my situation in order to get the best feedback possible. Also, I tried all the solutions in that post, and none of them worked.
I am trying to generate an unsigned release APK for my app. To do that, I use the command gradlew assembleRelease.
I get the following error:
Caught an exception trying to connect to Kotlin Daemon
java.lang.ClassNotFoundException: com.sun.tools.javac.util.Context
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at org.jetbrains.kotlin.gradle.tasks.JarSearchingUtilKt.findToolsJ
ar(jarSearchingUtil.kt:79)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment$t
oolsJar$2.invoke(GradleCompilerEnvironment.kt:20)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment$t
oolsJar$2.invoke(GradleCompilerEnvironment.kt:14)
at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:130)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment.g
etToolsJar(GradleCompilerEnvironment.kt)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment.g
etCompilerFullClasspath(GradleCompilerEnvironment.kt:23)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.getDae
monConnection(GradleKotlinCompilerRunner.kt:336)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compil
eWithDaemon(GradleKotlinCompilerRunner.kt:181)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compil
eWithDaemonOrFallback(GradleKotlinCompilerRunner.kt:156)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compil
eWithDaemonOrFallback(GradleKotlinCompilerRunner.kt:53)
at org.jetbrains.kotlin.compilerRunner.KotlinCompilerRunner.runCom
piler(KotlinCompilerRunner.kt:127)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.runJvm
Compiler(GradleKotlinCompilerRunner.kt:108)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$ko
tlin_gradle_plugin(Tasks.kt:378)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$ko
tlin_gradle_plugin(Tasks.kt:253)
at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute
(Tasks.kt:215)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0
(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(
Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.inv
oke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:7
3)
at org.gradle.api.internal.project.taskfactory.IncrementalTaskActi
on.doExecute(IncrementalTaskAction.java:46)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.
execute(StandardTaskAction.java:39)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.
execute(StandardTaskAction.java:26)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecu
ter$1.run(ExecuteActionsTaskExecuter.java:121)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$Runn
ableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$Runn
ableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.exec
ute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(
DefaultBuildOperationExecutor.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecu
ter.executeAction(ExecuteActionsTaskExecuter.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecu
ter.executeActions(ExecuteActionsTaskExecuter.java:92)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecu
ter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreating
TaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecute
r.execute(SkipUpToDateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachin
gStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.
execute(ValidatingTaskExecuter.java:60)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTas
kExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExec
uter.execute(CleanupStaleOutputsExecuter.java:87)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStat
eTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsEx
ecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.
execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskEx
ecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecu
ter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFi
ringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$Runn
ableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$Runn
ableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.exec
ute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(
DefaultBuildOperationExecutor.java:110)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFi
ringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFi
ringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExec
utorWorker.processTask(DefaultTaskPlanExecutor.java:123)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExec
utorWorker.access$200(DefaultTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExec
utorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExec
utorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute
(DefaultTaskExecutionPlan.java:626)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute
WithTask(DefaultTaskExecutionPlan.java:581)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExec
utorWorker.run(DefaultTaskPlanExecutor.java:98)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFai
lures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(Manage
dExecutorImpl.java:46)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unk
nown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Un
known Source)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadR
unnable.run(ThreadFactoryImpl.java:55)
at java.base/java.lang.Thread.run(Unknown Source)
Could not perform incremental compilation: Could not connect to Kotlin com
pile daemon
Could not connect to kotlin daemon. Using fallback strategy.
e: java.lang.ClassNotFoundException: com.sun.tools.javac.util.Context
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at org.jetbrains.kotlin.gradle.tasks.JarSearchingUtilKt.findToolsJ
ar(jarSearchingUtil.kt:79)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment$t
oolsJar$2.invoke(GradleCompilerEnvironment.kt:20)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment$t
oolsJar$2.invoke(GradleCompilerEnvironment.kt:14)
at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:130)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment.g
etToolsJar(GradleCompilerEnvironment.kt)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment.g
etCompilerFullClasspath(GradleCompilerEnvironment.kt:23)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compil
eOutOfProcess(GradleKotlinCompilerRunner.kt:303)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compil
eWithDaemonOrFallback(GradleKotlinCompilerRunner.kt:171)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compil
eWithDaemonOrFallback(GradleKotlinCompilerRunner.kt:53)
at org.jetbrains.kotlin.compilerRunner.KotlinCompilerRunner.runCom
piler(KotlinCompilerRunner.kt:127)
at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.runJvm
Compiler(GradleKotlinCompilerRunner.kt:108)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$ko
tlin_gradle_plugin(Tasks.kt:378)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$ko
tlin_gradle_plugin(Tasks.kt:253)
at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute
(Tasks.kt:215)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0
(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(
Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.inv
oke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:7
3)
at org.gradle.api.internal.project.taskfactory.IncrementalTaskActi
on.doExecute(IncrementalTaskAction.java:46)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.
execute(StandardTaskAction.java:39)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.
execute(StandardTaskAction.java:26)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecu
ter$1.run(ExecuteActionsTaskExecuter.java:121)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$Runn
ableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$Runn
ableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.exec
ute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(
DefaultBuildOperationExecutor.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecu
ter.executeAction(ExecuteActionsTaskExecuter.java:110)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecu
ter.executeActions(ExecuteActionsTaskExecuter.java:92)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecu
ter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreating
TaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecute
r.execute(SkipUpToDateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachin
gStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.
execute(ValidatingTaskExecuter.java:60)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTas
kExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExec
uter.execute(CleanupStaleOutputsExecuter.java:87)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStat
eTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsEx
ecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.
execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskEx
ecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecu
ter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFi
ringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$Runn
ableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$Runn
ableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.exec
ute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(
DefaultBuildOperationExecutor.java:110)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFi
ringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFi
ringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExec
utorWorker.processTask(DefaultTaskPlanExecutor.java:123)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExec
utorWorker.access$200(DefaultTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExec
utorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExec
utorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute
(DefaultTaskExecutionPlan.java:626)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute
WithTask(DefaultTaskExecutionPlan.java:581)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExec
utorWorker.run(DefaultTaskPlanExecutor.java:98)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFai
lures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(Manage
dExecutorImpl.java:46)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unk
nown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Un
known Source)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadR
unnable.run(ThreadFactoryImpl.java:55)
at java.base/java.lang.Thread.run(Unknown Source)
Here's some more information about my current situation:
I'm using Windows 10.
This is the result of gradlew assembleRelease --scan. It contains a lot of detailed information that could be useful for debugging.
https://scans.gradle.com/s/sohrhovsc676e/
In Android Studio, I went to "File -> Project Structure" and changed my JDK location from
"C:\Program Files\Android\Android Studio\jre" (embedded JDK)
to
"C:\Program Files\Java\jdk1.8.0_172" (JDK 8), which I got from here.
This failed to solve the problem.
I have also added "C:\Program Files\Java\jdk1.8.0_172\bin" to my System Path variable.
I also uploaded my project to Github, incase anyone needs to see it.
https://github.com/vedantroy/recyclerview-test
Also, I previously tried replacing implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" with implementation"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version", but that didn't work either.
Edit 1 -
I tried switching my Build Variant to "release" and then building an APK and that seemed to work. However, I'm not sure if that produces the same result as gradlew assembleRelease
In my case, this started happening after a Java update. It turns out the JRE was updated but the JDK was not.
Try: install the new JDK update, uninstall old versions, and reopen any shell/ps/cmd sessions/windows. It may be necessary to kill existing Gradle daemons but it should be smart enough not to reuse them. Try your build again!

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'

Android ChimpChat throws exception

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.

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.

Can't rename application package without an error message on one project

============update=============
I was able to edit all 18 classes in my application manually one at a time and get it published under a new name but this is not really an acceptable long term solution. I would still like to know how to fix this problem. As I said, I am able to change the package name of other applications, just not the one I care about.
Allen
I go to "application tools" then "rename application project" and I can rename a package except for the one I want to rename. In that case, I get an exception:
The box that pops up is called Refactoring
The heading in the box is A fatal error occurred while performing the refactoring.
And the error message is:
"An unexpected exception occurred while creating a change object. See the error log for more details."
Nothing shows up in the error log and I have no idea what to do. I can easily rename other projects so I think I know the process. The application works fine and in fact is released on Google Play. I want to create a second version for testing that times out in 10 days for people to try so it needs a different name. Just changing the name in the strings file is not enough for Google Play to think it is a different project.
Almost any work around that can get this thing on Google Play as a different application would be just fine.
Any help would be appreciated as most of the posts deal with how to change the name when there is no error, which I can do.
Allen
---------------update--------------------
I found the error file an here it is:
java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:421)
at org.eclipse.ui.internal.WorkbenchWindow$13.run(WorkbenchWindow.java:1666)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:1663)
at org.eclipse.ltk.ui.refactoring.RefactoringWizard.createChange(RefactoringWizard.java:663)
at org.eclipse.ltk.ui.refactoring.RefactoringWizard.computeUserInputSuccessorPage(RefactoringWizard.java:502)
at org.eclipse.ltk.ui.refactoring.RefactoringWizard.getStartingPage(RefactoringWizard.java:472)
at org.eclipse.jface.wizard.WizardDialog.showStartingPage(WizardDialog.java:1271)
at org.eclipse.jface.wizard.WizardDialog.createContents(WizardDialog.java:610)
at org.eclipse.jface.window.Window.create(Window.java:431)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1089)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation$1.run(RefactoringWizardOpenOperation.java:178)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:202)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:122)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.RenamePackageAction.initiateAndroidPackageRefactoring(RenamePackageAction.java:168)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.RenamePackageAction.promptNewName(RenamePackageAction.java:151)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.RenamePackageAction.run(RenamePackageAction.java:106)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1022)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:916)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:585)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:540)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
Caused by: java.lang.NullPointerException
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.updateJavaFileImports(ApplicationPackageNameRefactoring.java:149)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring$JavaFileVisitor.visit(ApplicationPackageNameRefactoring.java:426)
at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:126)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:85)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:95)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:52)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:124)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:108)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.createChange(ApplicationPackageNameRefactoring.java:126)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Root exception:
java.lang.NullPointerException
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.updateJavaFileImports(ApplicationPackageNameRefactoring.java:149)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring$JavaFileVisitor.visit(ApplicationPackageNameRefactoring.java:426)
at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:126)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:85)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:95)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:52)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:124)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:108)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.createChange(ApplicationPackageNameRefactoring.java:126)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
The problem with mine is because I have a code file that is totally commented off, when the re factor tool scans through the files under my package it couldn't read it. Check through your codes make sure the .java files are all valid java files.
Reinstalled Eclipse. Nothing else worked.

Categories

Resources