API and developer guide for Shizuku and Sui.
The concept is "same API, different implementation", Shizuku and Sui shares the API design. As the application developer, you only need to write the code once to support both Shizuku and Sui.
First of all, please read the README of Shizuku and Sui, so that you will have a basic understanding of how Shizuku and Sui works.
The most important functions provided by Shizuku API is "remote binder call" and "user service".
Remote binder call
Call any Android APIs which uses binder (such as getInstalledPackages
) as the identity of root (or adb).
User service
Similar to Bound services, but the service runs as the identity of root (or adb). JNI is also supported.
Shizuku and Sui requires the user to install something first.
For root-only apps, continue to support the old school "su" or not, you may have to make this choice.
Since Sui is possible to be bundled in Magisk in the future (Riru is already in Magisk), abandon old school "su" is not a bad choice.
For existing applications, there is an API that allows you to create a "sh" as root (or adb), so you can always do what was previously possible.
Simple applications which only use commands like pm
am
Use "Remote binder call".
Complicated applications such as root file managers
Use "User service".
Complicated applications which heavily depend on commands in Linux world
Use "User service" with JNI or continue to use shell.
rikka.shizuku
(replace all moe.shizuku.api.
to rikka.shizuku.
)ShizukuService
class is renamed to Shizuku
Shizuku
class now throw RuntimeException
rather than RemoteException
like other Android APIsShizukuProvider
class to Shizuku
classSui#init()
ShizukuProvider#isShizukuInstalled
since Sui does not have a managerSui#isSui
before using Shizuku only methods in ShizukuProvider
Note, something is not mentioned below, please be sure to read the demo.
Add dependency
repositories {
mavenCentral()
}
def shizuku_version = '11.0.2'
implementation "dev.rikka.shizuku:api:$shizuku_version"
// add this if you want to support Shizuku
implementation "dev.rikka.shizuku:provider:$shizuku_version"
Since all root users using Shizuku will eventually switch to Sui, if your application requires root, it's better not to support Shizuku from the begining.
Add ShizukuProvider
(Shizuku only)
Don't add this if your app only supports Sui.
Add to your AndroidManifest.xml
.
<provider
android:name="rikka.shizuku.ShizukuProvider"
android:authorities="${applicationId}.shizuku"
android:multiprocess="false"
android:enabled="true"
android:exported="true"
android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" />
Use
See demo.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。