gpt4 book ai didi

android - Google Analytics - 测试中的 NullPointerException

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:50:38 25 4
gpt4 key购买 nike

我在 Travis 构建服务器上的 Robolectric 测试中得到以下 NPE,我无法查明原因。我无法在本地重现此问题。

有人知道是什么原因导致 onServiceConnected 被调用吗?这可能会帮助我查明问题所在。据我所知,这是一个 Google Play 服务 - Google Analytics 问题。

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)

据我所知,我没有在任何地方为我的单元测试初始化​​ GA。我有一个通用的“假”分析跟踪器,只要运行测试就会使用它。为了以防万一,我在我的假跟踪器的构造函数中添加了以下行,该跟踪器是在应用程序的 onCreate 中创建的:

GoogleAnalytics.getInstance(context).setAppOptOut(true);

如果这是相关的,它会破坏 Java 1.7.0_u55 的盒子。

编辑:

我今天在失败测试的日志中看到以下内容。我不确定这是崩溃的原因。可能会提供一些见解。

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.

看起来像是 SQLite 和 GA 的问题?

另一个更新:

有关更新,请参阅链接的 github 问题 (https://github.com/robolectric/robolectric/issues/1075)。我暂时恢复到 v3。

最佳答案

Akeem 的解决方案适合我。

这是我用于 Robolectic 3.0 的,它有一些变化:

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");

关于android - Google Analytics - 测试中的 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23528087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com