share_my_apk 0.1.0-alpha
share_my_apk: ^0.1.0-alpha copied to clipboard
A powerful command-line tool to build and upload your Flutter APKs directly to various services like Diawi and Gofile.io. This package can also be used as a library.
share_my_apk #
A powerful command-line tool to build and upload your Flutter APKs directly to various services like Diawi and Gofile.io. This package can also be used as a library to integrate the APK building and uploading functionality into your own Dart applications.
Developed by the Mobile Department at Webmob Technologies
Note: This package is currently in alpha version. Please test thoroughly before using in production environments.
Features #
- Build & Upload: Seamlessly build your Flutter application (in release or debug mode) and upload the generated APK.
- Multiple Providers: Supports Diawi and Gofile.io for APK uploads, with automatic switching to Gofile.io for large files (over 70MB) when Diawi is selected.
- Custom File Naming: Generate APK files with custom names, timestamps, and version information.
- Directory Organization: Organize builds by environment (dev, prod, staging) and custom output directories.
- Command-Line Interface: A user-friendly CLI for quick and easy use.
- Extensible Library: Use the underlying services as a library in your own projects.
- Professional Logging: Structured and informative logging using the standard
loggingpackage.
Getting Started #
Installation #
To use share_my_apk as a command-line tool, you can activate it globally:
dart pub global activate share_my_apk
Or, you can add it to your project's dev_dependencies in pubspec.yaml:
dev_dependencies:
share_my_apk: ^0.1.0-alpha # Replace with the latest version
Then, run dart pub get.
Usage #
As a Command-Line Tool #
Once activated, you can use the share_my_apk command in your terminal:
share_my_apk [options]
Options:
| Option | Abbreviation | Description |
|---|---|---|
--token |
-t |
Your API token (required for Diawi, optional for Gofile.io). |
--path |
-p |
Path to your Flutter project. Defaults to the current directory. |
--release |
Build in release mode (default). Use --no-release for debug mode. |
|
--provider |
The upload provider to use ('diawi' or 'gofile'). Defaults to 'diawi'. | |
--name |
-n |
Custom name for the APK file (without extension). |
--environment |
-e |
Environment folder (dev, prod, staging, etc.). |
--output-dir |
-o |
Output directory for the built APK. |
Examples:
# Build and upload a release APK to Diawi from the current project
share_my_apk --token YOUR_SECRET_DIAWI_TOKEN
# Build and upload a debug APK to Gofile.io from a specific project path
share_my_apk --no-release --path /path/to/your/project --provider gofile
# Build with custom name and environment organization
share_my_apk --token YOUR_SECRET_DIAWI_TOKEN --name "MyApp_Beta" --environment "staging"
# Build with custom output directory and file naming
share_my_apk --token YOUR_SECRET_DIAWI_TOKEN --output-dir "/path/to/builds" --name "Release_v1.2.3"
# Build and upload a release APK to Diawi, even if it's larger than 70MB (will switch to gofile.io automatically)
share_my_apk --token YOUR_SECRET_DIAWI_TOKEN --provider diawi
As a Library #
You can also use the core services of this package in your own Dart code.
Example:
import 'package:share_my_apk/share_my_apk.dart';
import 'package:logging/logging.dart';
void main() async {
// Configure logging (optional)
Logger.root.level = Level.ALL; // Set to desired logging level
Logger.root.onRecord.listen((record) {
print('${record.level.name}: ${record.time}: ${record.message}');
});
final logger = Logger('main');
try {
// 1. Initialize the APK builder service
final apkBuilder = ApkBuilderService();
// 2. Build the APK with custom naming and organization
final apkPath = await apkBuilder.build(
release: true,
projectPath: '.',
customName: 'MyApp_Beta',
environment: 'staging',
outputDir: '/path/to/builds',
);
logger.info('APK built successfully: $apkPath');
// 3. Choose the upload provider and upload the APK
// The token is only required for Diawi.
final uploader = UploadServiceFactory.create(
'gofile', // or 'diawi'
token: 'YOUR_DIAWI_TOKEN', // Replace with your token if using Diawi
);
final downloadLink = await uploader.upload(apkPath);
logger.info('Upload successful!');
logger.info('Download Link: $downloadLink');
} on ProcessException catch (e) {
logger.severe('Failed to build APK: ${e.message}');
} catch (e) {
logger.severe('An unexpected error occurred: $e');
}
}
File Naming and Organization #
Custom File Naming #
When you use the --name option, the APK will be named using the format:
- Custom name:
{customName}_{version}_{timestamp}.apk - Default name:
{appName}_{version}_{timestamp}.apk
The timestamp format is: YYYY_MM_DD_HH_MM_SS
Directory Organization #
- Environment folders: Use
--environmentto organize builds by environment (dev, prod, staging, etc.) - Custom output directory: Use
--output-dirto specify where APK files should be saved - Default structure:
{projectPath}/build/apk/{environment}/
Examples of Generated Files #
# Default naming
my_app_1.0.0_2024_01_15_14_30_45.apk
# Custom naming
MyApp_Beta_1.0.0_2024_01_15_14_30_45.apk
# With environment organization
/path/to/builds/staging/MyApp_Beta_1.0.0_2024_01_15_14_30_45.apk
Testing #
This package is currently in alpha version. Please test it thoroughly in your development environment before using in production. We recommend:
- Testing with different Flutter project structures
- Verifying uploads work correctly with both providers
- Testing both release and debug builds
- Checking the automatic provider switching feature
Contributing #
Contributions are welcome! If you find any issues or have suggestions for improvements, please file an issue or submit a pull request on the project's repository.
License #
This project is licensed under the MIT License - see the LICENSE file for details.