aapt_dart
A pure Dart library for interacting with AAPT (Android Asset Packaging Tool) to extract information from APK files.
Features
-
APK Information Extraction: Extract comprehensive metadata from APK files
- Package name, version code, and version name
- Application label and icon
- SDK versions (minimum and target)
- Permissions and features
- Activities and services
- Launchable activity detection
- Native libraries
- Supported locales and screen densities
- Debuggable flag detection
-
Custom Logging: Implement your own logger or use the default console logger
-
Exception Handling: Comprehensive error handling with specific exception types
Getting Started
Prerequisites
You need to have AAPT (Android Asset Packaging Tool) installed on your system. AAPT is part of the Android SDK Build Tools.
Installation Options:
-
Android Studio: AAPT is included in Android Studio's SDK Build Tools
- Typical location:
~/Library/Android/sdk/build-tools/<version>/aapt(macOS) - Windows:
%LOCALAPPDATA%\Android\sdk\build-tools\<version>\aapt.exe - Linux:
~/Android/Sdk/build-tools/<version>/aapt
- Typical location:
-
Command Line Tools: Download Android SDK Command Line Tools from developer.android.com
Installation
Add this to your package's pubspec.yaml file:
dependencies:
aapt_dart: ^1.0.0
Then run:
dart pub get
Usage
Basic Example
import 'package:aapt_dart/aapt_dart.dart';
void main() async {
// Create AAPT client with the path to your AAPT executable
final aapt = AaptClient(
aaptExecutablePath: '/path/to/aapt',
);
// Extract APK information
final apkInfo = await aapt.getApkInfo('/path/to/your/app.apk');
// Display information
print('Package: ${apkInfo.packageName}');
print('Version: ${apkInfo.versionName} (${apkInfo.versionCode})');
print('Label: ${apkInfo.applicationLabel}');
print('Min SDK: ${apkInfo.sdkVersion}');
print('Target SDK: ${apkInfo.targetSdkVersion}');
// Display permissions
print('\nPermissions:');
for (final permission in apkInfo.permissions) {
print(' - $permission');
}
}
Custom Logger
Implement your own logger for custom logging behavior:
class CustomLogger implements AaptLogger {
@override
void debug(String message) {
// Your custom debug logging
}
@override
void info(String message) {
// Your custom info logging
}
@override
void error(String message, {StackTrace? stackTrace}) {
// Your custom error logging
}
}
void main() async {
final aapt = AaptClient(
aaptExecutablePath: '/path/to/aapt',
logger: CustomLogger(),
);
final apkInfo = await aapt.getApkInfo('/path/to/app.apk');
}
Error Handling
The library provides specific exception types for different error scenarios:
try {
final aapt = AaptClient(
aaptExecutablePath: '/path/to/aapt',
);
final apkInfo = await aapt.getApkInfo('/path/to/app.apk');
} on AaptNotFoundException catch (e) {
print('AAPT not found at: ${e.aaptPath}');
} on ApkNotFoundException catch (e) {
print('APK not found at: ${e.apkPath}');
} on ApkParsingException catch (e) {
print('Failed to parse APK: ${e.message}');
} on AaptException catch (e) {
print('AAPT error: ${e.message}');
}
Getting AAPT Version
final aapt = AaptClient(
aaptExecutablePath: '/path/to/aapt',
);
final version = await aapt.getVersion();
print('AAPT Version: $version');
API Reference
AaptClient
The main client for interacting with AAPT.
Constructor
AaptClient({
required String aaptExecutablePath,
AaptLogger? logger,
})
Methods
Future<ApkInfo> getApkInfo(String apkPath)- Extract information from an APK fileFuture<String> getVersion()- Get the AAPT version
ApkInfo
Model class containing comprehensive APK information.
Properties
String packageName- The package nameint versionCode- The version codeString versionName- The version nameString? applicationLabel- The app labelint? sdkVersion- Minimum SDK versionint? targetSdkVersion- Target SDK versionList<String> permissions- List of permissionsList<String> usesFeatures- List of featuresList<String> activities- List of activitiesList<String> services- List of servicesString? launchableActivity- Main launchable activityString? applicationIcon- App icon pathbool isDebuggable- Whether the app is debuggableList<String> nativeLibraries- List of native librariesList<String> locales- Supported localesList<String> densities- Supported screen densities
Exceptions
AaptException- Base exception for all AAPT errorsAaptNotFoundException- AAPT executable not foundApkNotFoundException- APK file not foundApkParsingException- Failed to parse APK information
Examples
For more comprehensive examples, check the example directory.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
If you encounter any issues or have questions, please file an issue on GitHub.
Libraries
- aapt_dart
- A Dart library for interacting with AAPT (Android Asset Packaging Tool).