shizuku_api_plugin 1.0.1
shizuku_api_plugin: ^1.0.1 copied to clipboard
Shizuku API is the API provided by Shizuku and Sui. With Shizuku API, you can call your Java/JNI code with root/shell (ADB) identity.
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.
☕️ Buy Me a Coffee #