'Flutter Plugin: crash_dump.cpp: failed to attach to thread 185: Permission denied
I am developing a Flutter Plugin and a simple piano keyboard layout which calls the Flutter plugin when onKeyPressed
and onKeyUp
the piano keys. The piano app can run in an emulator, and can produce the sound. However, from time to time, the app would crash with the error message:
F/crash_dump32(22593): crash_dump.cpp:474] failed to attach to thread 185: Permission denied
and in the emulator, a pop-up warning shows System UI isn't responding
with options: Close the app
or Wait
.
If I chose Wait
, it will resume to work, until the same thread error repeats itself.
In my implementation, I have a class written in Kotlin that will be run in a thread:
class Synth : Runnable {
private lateinit var mThread: Thread
private var mRunning = false
private var mFreq = 440.0
private var mAmp = 0.0
private var mNumKeysDown = 0
fun start() {
mThread = Thread(this)
mRunning = true
mThread.start()
}
fun stop() {
mRunning = false
}
fun keyDown(key: Int): Int {
mFreq = Math.pow(1.0594630f.toDouble(), key.toDouble() - 69.0) * 440.0
mAmp = 1.0
mNumKeysDown += 1
return mNumKeysDown
}
}
and the following pieces are how the Synth
class is called from the Plugin written in Kotlin:
- When the Plugin is initiated from a Flutter client:
class PianoPlugin: FlutterPlugin, MethodCallHandler {
fun setup(plugin: PianoPlugin, binaryMessenger: BinaryMessenger) {
plugin.channel = MethodChannel(channelName)
plugin.channel.setMethodCallHandler(plugin)
plugin.synth = Synth()
plugin.synth.start() // <- Start the thread
}
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if (call.method == "getPlatformVersion") {
result.success(android.os.Build.VERSION.RELEASE)
} else if (call.method == "onKeyDown"){
try {
val arguments: ArrayList<Int> = call.arguments as ArrayList<Int>
val numKeysDown: Int = synth.keyDown(arguments.get(0) as Int) // <- Function call
result.success(numKeysDown)
} catch (ex: Exception) {
result.error("100", ex.message, ex.getStackTrace())
}
}
I wonder if anyone has bumped into similar thread issue can share some insights of the possible causes. Very appreciated!
Solution 1:[1]
i solved it by cold booting the emulator.
Solution 2:[2]
Updating the android version to 12 when creating a new Device(using the virtual device manager) solved my problem.
You can update your android version by following these steps:
- Choose 'Virtual Device Manager
- Click on 'Create Device' on the top
- Choose your hardware
- Select Android version above 11.0 and finish the process
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | aligur |
Solution 2 |