Native crash in Activity after starting/stopping a service

  android, android-service, c++, java, kotlin

Had a very sporadic native crash that was very difficult to reproduce (the stack trace in no way indicates it would be related to an unrelated service being started/stopped). Eventually managed to narrow it down and have made a very small reproduction class:

package com.example.nativecrash

import android.app.Service
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.IBinder
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity

class TestService : Service() {
    override fun onBind(intent: Intent?): IBinder? = null
}

class MainActivity : AppCompatActivity() {

    private val handler = Handler(Looper.getMainLooper())
    private val recreate = Runnable { recreate() }

    override fun onCreate(savedInstanceState: Bundle?) {
        setTheme(R.style.Theme_MaterialComponents_NoActionBar)
        super.onCreate(savedInstanceState)
    }

    override fun onResume() {
        super.onResume()
        handler.postDelayed(recreate, 500)
    }

    override fun onStart() {
        super.onStart()
        startService(Intent(this, TestService::class.java))
        handler.postDelayed({ stopService(Intent(this, TestService::class.java)) }, 400)
    }

    override fun onPause() {
        handler.removeCallbacks(recreate)
        super.onPause()
    }
}

Running that activity on an Android 11 device will reproduce the crash. I found it to occur much more frequently hit running on the emulator (reliably less than a minute until it occurs) than on an actual device but it still happens on both.

Stack trace:

2020-09-25 19:33:29.086 21156-21156/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2020-09-25 19:33:29.086 21156-21156/? A/DEBUG: Build fingerprint: 'google/sdk_gphone_x86_64/generic_x86_64_arm64:10/RPP4.200409.015/6455311:user/release-keys'
2020-09-25 19:33:29.086 21156-21156/? A/DEBUG: Revision: '0'
2020-09-25 19:33:29.086 21156-21156/? A/DEBUG: ABI: 'x86_64'
2020-09-25 19:33:29.087 21156-21156/? A/DEBUG: Timestamp: 2020-09-25 19:33:29+0930
2020-09-25 19:33:29.087 21156-21156/? A/DEBUG: pid: 21124, tid: 21124, name: ple.nativecrash  >>> com.example.nativecrash <<<
2020-09-25 19:33:29.087 21156-21156/? A/DEBUG: uid: 10150
2020-09-25 19:33:29.087 21156-21156/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10
2020-09-25 19:33:29.087 21156-21156/? A/DEBUG: Cause: null pointer dereference
2020-09-25 19:33:29.087 21156-21156/? A/DEBUG:     rax 0000000000000000  rbx 0000000000000006  rcx 0000000000000000  rdx 000000000000003f
2020-09-25 19:33:29.087 21156-21156/? A/DEBUG:     r8  0000000000000041  r9  00007f589b5cc2f9  r10 00007fff3fb96f50  r11 00007f5adc3a3f88
2020-09-25 19:33:29.087 21156-21156/? A/DEBUG:     r12 00007fff3fb96eb0  r13 00007f589b5ccdd0  r14 00007f589b5cc2f0  r15 00007f589b5cc2f0
2020-09-25 19:33:29.087 21156-21156/? A/DEBUG:     rdi 00007f588b5ee52f  rsi 00007f588b5ee52f
2020-09-25 19:33:29.087 21156-21156/? A/DEBUG:     rbp 0000000000000020  rsp 00007fff3fb96e60  rip 00007f5ae0484926
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG: backtrace:
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #00 pc 0000000000044926  /system/lib64/libandroidfw.so (android::Theme::SetTo(android::Theme const&)+758) (BuildId: e8c40d5379694fa117849c5f0fba7014)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #01 pc 00000000001333ca  /system/lib64/libandroid_runtime.so (android::NativeThemeCopy(_JNIEnv*, _jclass*, long, long, long, long)+106) (BuildId: bbfd6cd225dce70beef86960dce8af22)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #02 pc 00000000002179f5  /system/framework/x86_64/boot-framework.oat (art_jni_trampoline+245) (BuildId: 7fc56639bfc361a01712408a01b6fb02a496391e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #03 pc 0000000000179116  /apex/com.android.art/lib64/libart.so (art_quick_invoke_static_stub+806) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #04 pc 000000000020cb75  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+277) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #05 pc 00000000003ac005  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+357) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #06 pc 00000000003a1af6  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<true, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+934) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #07 pc 00000000007969a8  /apex/com.android.art/lib64/libart.so (MterpInvokeStaticRange+520) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #08 pc 0000000000163519  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_static_range+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #09 pc 000000000036fcb8  /system/framework/framework.jar (android.content.res.AssetManager.setThemeTo+28)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #10 pc 0000000000793a29  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtualRange+1513) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #11 pc 0000000000163399  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual_range+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #12 pc 0000000000376aa4  /system/framework/framework.jar (android.content.res.ResourcesImpl$ThemeImpl.setTo+28)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #13 pc 000000000078f594  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+2020) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #14 pc 0000000000163099  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #15 pc 000000000037651c  /system/framework/framework.jar (android.content.res.Resources$Theme.setTo+8)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #16 pc 000000000078f594  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+2020) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #17 pc 0000000000163099  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #18 pc 000000000010f00a  [anon:dalvik-classes.dex extracted in memory from /data/app/~~jA9NSsNmX861v49XTIGS0w==/com.example.nativecrash-f6ZiVgHuiz_wbVwr_-D2zw==/base.apk] (androidx.appcompat.view.ContextThemeWrapper.initializeTheme+62)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #19 pc 0000000000396c1f  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.13178773210012645589)+351) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #20 pc 000000000039fb68  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #21 pc 00000000003a06a9  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+1209) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #22 pc 0000000000791fc6  /apex/com.android.art/lib64/libart.so (MterpInvokeDirect+710) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #23 pc 0000000000163199  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_direct+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #24 pc 000000000010ee7e  [anon:dalvik-classes.dex extracted in memory from /data/app/~~jA9NSsNmX861v49XTIGS0w==/com.example.nativecrash-f6ZiVgHuiz_wbVwr_-D2zw==/base.apk] (androidx.appcompat.view.ContextThemeWrapper.getTheme+26)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #25 pc 0000000000396c1f  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.13178773210012645589)+351) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #26 pc 000000000039fb68  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #27 pc 00000000003a06a9  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+1209) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #28 pc 000000000078f1c8  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+1048) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #29 pc 0000000000163099  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #30 pc 00000000001fa612  /system/framework/framework.jar (offset 0x1256000) (android.view.ContextThemeWrapper.initializeTheme+46)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #31 pc 0000000000792364  /apex/com.android.art/lib64/libart.so (MterpInvokeDirect+1636) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #32 pc 0000000000163199  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_direct+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #33 pc 00000000001fa688  /system/framework/framework.jar (offset 0x1256000) (android.view.ContextThemeWrapper.setTheme+12)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #34 pc 00000000007905d4  /apex/com.android.art/lib64/libart.so (MterpInvokeSuper+2932) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #35 pc 0000000000163119  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_super+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #36 pc 00000000001ab3e4  /system/framework/framework.jar (android.app.Activity.setTheme)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #37 pc 00000000007905d4  /apex/com.android.art/lib64/libart.so (MterpInvokeSuper+2932) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #38 pc 0000000000163119  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_super+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #39 pc 00000000001019d8  [anon:dalvik-classes.dex extracted in memory from /data/app/~~jA9NSsNmX861v49XTIGS0w==/com.example.nativecrash-f6ZiVgHuiz_wbVwr_-D2zw==/base.apk] (androidx.appcompat.app.AppCompatActivity.setTheme)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #40 pc 0000000000396c1f  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.13178773210012645589)+351) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #41 pc 000000000039fb68  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #42 pc 00000000003a06a9  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+1209) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #43 pc 000000000078f1c8  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+1048) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #44 pc 0000000000163099  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #45 pc 0000000000199268  /system/framework/framework.jar (android.app.ActivityThread.performLaunchActivity+740)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #46 pc 0000000000792364  /apex/com.android.art/lib64/libart.so (MterpInvokeDirect+1636) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #47 pc 0000000000163199  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_direct+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #48 pc 0000000000198ef2  /system/framework/framework.jar (android.app.ActivityThread.handleLaunchActivity+94)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #49 pc 000000000078f594  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+2020) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #50 pc 0000000000163099  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #51 pc 00000000001a08c2  /system/framework/framework.jar (android.app.ActivityThread.handleRelaunchActivityInner+154)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #52 pc 00000000007962fb  /apex/com.android.art/lib64/libart.so (MterpInvokeDirectRange+1307) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #53 pc 0000000000163499  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_direct_range+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.217 21156-21156/? A/DEBUG:       #54 pc 00000000001a078c  /system/framework/framework.jar (android.app.ActivityThread.handleRelaunchActivity+408)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #55 pc 000000000078f594  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+2020) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #56 pc 0000000000163099  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #57 pc 000000000028ab14  /system/framework/framework.jar (android.app.servertransaction.ActivityRelaunchItem.execute+28)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #58 pc 000000000078f594  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+2020) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #59 pc 0000000000163099  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #60 pc 000000000028e9ca  /system/framework/framework.jar (android.app.servertransaction.TransactionExecutor.executeCallbacks+154)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #61 pc 000000000078f594  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+2020) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #62 pc 0000000000163099  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #63 pc 000000000028e906  /system/framework/framework.jar (android.app.servertransaction.TransactionExecutor.execute+146)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #64 pc 000000000078f594  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+2020) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #65 pc 0000000000163099  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #66 pc 00000000001c103a  /system/framework/framework.jar (android.app.ClientTransactionHandler.executeTransaction+14)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #67 pc 000000000078f594  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+2020) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #68 pc 0000000000163099  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #69 pc 00000000001a096c  /system/framework/framework.jar (android.app.ActivityThread.handleRelaunchActivityLocally+144)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #70 pc 0000000000396c1f  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.13178773210012645589)+351) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #71 pc 000000000039fb68  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #72 pc 00000000003a06a9  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+1209) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #73 pc 0000000000791fc6  /apex/com.android.art/lib64/libart.so (MterpInvokeDirect+710) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #74 pc 0000000000163199  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_direct+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #75 pc 000000000019bc00  /system/framework/framework.jar (android.app.ActivityThread.access$3300)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #76 pc 0000000000396c1f  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.13178773210012645589)+351) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #77 pc 000000000039fb68  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+200) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #78 pc 00000000003a06a9  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+1209) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #79 pc 0000000000792b38  /apex/com.android.art/lib64/libart.so (MterpInvokeStatic+696) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #80 pc 0000000000163219  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_static+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #81 pc 0000000000198212  /system/framework/framework.jar (android.app.ActivityThread$H.handleMessage+66)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #82 pc 000000000078f594  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+2020) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #83 pc 0000000000163099  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #84 pc 000000000036acbe  /system/framework/framework.jar (offset 0x927000) (android.os.Handler.dispatchMessage+38)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #85 pc 000000000078f594  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+2020) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #86 pc 0000000000163099  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #87 pc 0000000000391a5e  /system/framework/framework.jar (offset 0x927000) (android.os.Looper.loop+482)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #88 pc 0000000000792ee7  /apex/com.android.art/lib64/libart.so (MterpInvokeStatic+1639) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #89 pc 0000000000163219  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_static+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #90 pc 00000000001a1f3e  /system/framework/framework.jar (android.app.ActivityThread.main+202)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #91 pc 0000000000396c1f  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.13178773210012645589)+351) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #92 pc 000000000077a9c0  /apex/com.android.art/lib64/libart.so (artQuickToInterpreterBridge+1072) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #93 pc 000000000018434c  /apex/com.android.art/lib64/libart.so (art_quick_to_interpreter_bridge+140) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #94 pc 0000000000179116  /apex/com.android.art/lib64/libart.so (art_quick_invoke_static_stub+806) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #95 pc 000000000020cb75  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+277) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #96 pc 000000000062febe  /apex/com.android.art/lib64/libart.so (art::InvokeMethod(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned long)+5678) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #97 pc 000000000058df18  /apex/com.android.art/lib64/libart.so (art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*)+56) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #98 pc 000000000009afae  /apex/com.android.art/javalib/x86_64/boot.oat (art_jni_trampoline+222) (BuildId: 0e283f9cac599f57d802a9843d949820fe1a2807)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #99 pc 0000000000178db4  /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+756) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #100 pc 000000000020cb56  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+246) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #101 pc 00000000003ac005  /apex/com.android.art/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+357) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #102 pc 00000000003a06c1  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+1233) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #103 pc 000000000078f1c8  /apex/com.android.art/lib64/libart.so (MterpInvokeVirtual+1048) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #104 pc 0000000000163099  /apex/com.android.art/lib64/libart.so (mterp_op_invoke_virtual+25) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #105 pc 000000000044cf4a  /system/framework/framework.jar (offset 0x1256000) (com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run+22)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #106 pc 0000000000396c1f  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.13178773210012645589)+351) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #107 pc 000000000077a9c0  /apex/com.android.art/lib64/libart.so (artQuickToInterpreterBridge+1072) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #108 pc 000000000018434c  /apex/com.android.art/lib64/libart.so (art_quick_to_interpreter_bridge+140) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #109 pc 000000000095b7f7  /system/framework/x86_64/boot-framework.oat (com.android.internal.os.ZygoteInit.main+2039) (BuildId: 7fc56639bfc361a01712408a01b6fb02a496391e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #110 pc 0000000000179116  /apex/com.android.art/lib64/libart.so (art_quick_invoke_static_stub+806) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #111 pc 000000000020cb75  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+277) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #112 pc 000000000062d5b7  /apex/com.android.art/lib64/libart.so (art::JValue art::InvokeWithVarArgs<art::ArtMethod*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, art::ArtMethod*, __va_list_tag*)+487) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #113 pc 00000000004e2c69  /apex/com.android.art/lib64/libart.so (art::JNI<true>::CallStaticVoidMethodV(_JNIEnv*, _jclass*, _jmethodID*, __va_list_tag*)+665) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #114 pc 000000000041a390  /apex/com.android.art/lib64/libart.so (art::(anonymous namespace)::CheckJNI::CallMethodV(char const*, _JNIEnv*, _jobject*, _jclass*, _jmethodID*, __va_list_tag*, art::Primitive::Type, art::InvokeType)+2864) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #115 pc 00000000004090ae  /apex/com.android.art/lib64/libart.so (art::(anonymous namespace)::CheckJNI::CallStaticVoidMethodV(_JNIEnv*, _jclass*, _jmethodID*, __va_list_tag*)+30) (BuildId: ac7d906af99fd99289c2ce2a1072cf3e)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #116 pc 00000000000afe68  /system/lib64/libandroid_runtime.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)+168) (BuildId: bbfd6cd225dce70beef86960dce8af22)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #117 pc 00000000000b8401  /system/lib64/libandroid_runtime.so (android::AndroidRuntime::start(char const*, android::Vector<android::String8> const&, bool)+881) (BuildId: bbfd6cd225dce70beef86960dce8af22)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #118 pc 0000000000004190  /system/bin/app_process64 (main+1648) (BuildId: d6b2621fa9c788320535274f35331797)
2020-09-25 19:33:29.218 21156-21156/? A/DEBUG:       #119 pc 0000000000050965  /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+117) (BuildId: 0cb1ee2e4692086bd16b0cdb7620eb97)

Use case is I have an overlay service that runs while the app is foregrounded, and also an option for the user to change theme (which results in Activity.recreate() being called). The crash seems to be some sort of race condition with the service start/stop and the activity recreate but I don’t see why that should matter.

So I guess my question is twofold:

1: What does starting/stopping a service have to do with an activity eventually crashing deep in native code trying to set the theme.

2: What can possibly be done to avoid this.

Source: Windows Questions C++

LEAVE A COMMENT