Shizuku-API icon indicating copy to clipboard operation
Shizuku-API copied to clipboard

Cannot access 'newProcess': it is private in 'Shizuku'

Open AlexeiCrystal opened this issue 7 months ago • 3 comments

AlexeiCrystal avatar Jun 02 '25 06:06 AlexeiCrystal

private fun runShellCommandWithShizuku(command: Array<String>): Pair<String, String> {
    return try {
        val clazz = Class.forName("rikka.shizuku.Shizuku")
        val method = clazz.getDeclaredMethod("newProcess", Array<String>::class.java, Array<String>::class.java, String::class.java)
        method.isAccessible = true

        val remoteProcess = method.invoke(null, command, null, null) as rikka.shizuku.ShizukuRemoteProcess
        val output = remoteProcess.inputStream.bufferedReader().use { it.readText() }
        val error = remoteProcess.errorStream.bufferedReader().use { it.readText() }

        remoteProcess.destroy()
        Pair(output.trim(), error.trim())
    } catch (exception: Exception) {
        Pair("", "Exception: ${exception.message}")
    }
}

I don't know why this is private, probably for security reasons. However, I find it pointless to go crazy with AIDL, binder, etc. to run a very simple command that you could run with adb. I expect an end user, when installing Shizuku, to understand the risks of incorrect use.

This is a workaround and gives you access to the private function. You shouldn't use it in production; it's not guaranteed to work.

Marko97IT avatar Jul 28 '25 17:07 Marko97IT

Or use api version 12.2.0.

AlexeiCrystal avatar Jul 29 '25 05:07 AlexeiCrystal

+1

RohitKushvaha01 avatar Oct 09 '25 04:10 RohitKushvaha01