Shizuku API Flutter Plugin
A Flutter plugin to interact with the Shizuku API,
allowing your
application to execute shell commands with system or ADB privileges.
English | δΈζ
π¦ Installation
Add the dependency to your project:
flutter pub add shizuku_api_plugin
π Requirements
- Flutter
>=3.44.0and Dart SDK^3.12.0are required. - The Shizuku app must be installed and running on the target device.
βοΈ Configuration
π§ app/build.gradle
Ensure that the minimum SDK version (minSdk) is set to 24 or higher.
π AndroidManifest.xml
Add the Shizuku provider definition inside the <application> tag:
<application>
<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" />
</application>
π Usage
Each snippet below is a complete async function. In a real app, call it from your widget or
service.
1. π Verify Shizuku Service
Before executing any plugin commands, verify that the Shizuku service is running:
import 'package:shizuku_api_plugin/shizuku_api.dart';
Future<void> main() async {
final shizukuApiPlugin = ShizukuApi();
// Check if the Shizuku binder service is active
final isBinderRunning = await shizukuApiPlugin.pingBinder() ?? false;
print(isBinderRunning);
}
2. β Check Permissions
Check if Shizuku permissions have been granted to your application:
import 'package:shizuku_api_plugin/shizuku_api.dart';
Future<void> main() async {
final shizukuApiPlugin = ShizukuApi();
// Returns true if permission is granted, false if denied or not requested yet
final hasPermission = await shizukuApiPlugin.checkPermission();
print(hasPermission);
}
3. π Request Permissions
Request permissions from the user via the Shizuku system dialog:
import 'package:shizuku_api_plugin/shizuku_api.dart';
Future<void> main() async {
final shizukuApiPlugin = ShizukuApi();
// Triggers the Shizuku permission dialog
// Returns true if permission is granted, false if declined
final permissionGranted = await shizukuApiPlugin.requestPermission();
print(permissionGranted);
}
4. β¨οΈ Run Commands
Execute ADB shell commands:
- Note: Execution within a root environment (
su) is untested. - Standard ADB shell commands are supported.
import 'package:shizuku_api_plugin/shizuku_api.dart';
Future<void> main() async {
final shizukuApiPlugin = ShizukuApi();
const command = 'pm uninstall --user 0 com.android.chrome';
// Returns success if the command is executed and the system app is uninstalled
final output = await shizukuApiPlugin.runCommand(command);
print(output);
}
π API Reference
Methods exposed by ShizukuApi (all return a Future, so await is required):
| Method | Returns | Description |
|---|---|---|
pingBinder() |
Future<bool?> |
Whether the Shizuku binder service is active |
checkPermission() |
Future<bool?> |
Whether Shizuku permission has been granted |
requestPermission() |
Future<bool?> |
Shows the Shizuku permission dialog and returns the result |
runCommand(String command) |
Future<String?> |
Executes a command as shell (ADB) and returns its output |
Recommended order:
pingBinder()βcheckPermission()βrequestPermission()(if not granted) βrunCommand().
π‘ Example
A runnable example project is available in the
example/ directory,
demonstrating the full flow:
check service β check permission β request permission β run command.
β FAQ
- Command fails / no output: make sure the Shizuku app is started and running, and that your app has been granted permission.
- No permission dialog: verify that
pingBinder()returnstruefirst; the dialog cannot be shown when Shizuku is not running. - Uncaught
PlatformException: wrap the calls intry/catchand handle the failure gracefully.
For more questions, refer to the Shizuku documentation.
π Support
If shizuku_api_plugin helps you build better UIs, please consider supporting it.
It only takes a few seconds and helps other Flutter developers discover the library.
- β Star on GitHub
- π Like on pub.flutter-io.cn
βοΈ Buy Me a Coffee