Application Packaging
ElenixOS uses an application packaging tool to package the source code, resources, and configuration files of an application or watch face into a unified installation package (.eapk file). This document will detail the application packaging format, resource organization, and output specifications.
Application Packaging Concept
Application packaging is the process of combining all components of an application (scripts, resources, configuration) into an installable package file. In ElenixOS, the packaged product is a .eapk file, similar to installation package formats on other platforms.
Functions of Packaging
- Unified distribution: Package all components of the application into a single file for easy distribution and installation
- Resource management: Manage application resource files to ensure correct loading of resources
- Version control: Include application version information for easy version management
- Permission management: Include application permission information to ensure applications can only access authorized resources
Input Directory Structure
The application packaging tool uses a specific directory structure as input to ensure the consistency and reliability of the packaging process.
Standard Directory Structure
app/
├── manifest.json # Application configuration file
├── main.js # Application main script
├── icon.bin # Application icon
├── assets/ # Resource directory
│ ├── images/ # Image resources
│ ├── fonts/ # Font resources
│ └── sounds/ # Audio resources
└── lib/ # Dependency libraries
Directory Description
- manifest.json: Application configuration file, containing application ID, name, version, type, etc.
- main.js: Application main script file, containing application interface and logic
- icon.bin: Application icon file, used to display in the application list
- assets/: Application resource directory, containing images, fonts, audio, etc.
- lib/: Application dependency library directory, containing third-party libraries and modules
Packaging Product Format
ElenixOS's application packaging product is a .eapk file, which is a compressed file containing all components of the application.
.eapk File Structure
app.eapk/
├── manifest.json # Application configuration file
├── main.js # Application main script
├── icon.bin # Application icon
├── assets/ # Resource directory
└── lib/ # Dependency libraries
Packaging Tool
ElenixOS uses the Python script scripts/eos_pkg_builder.py for application packaging:
python3 scripts/eos_pkg_builder.py --input app/ --output app.eapk
Resource Merging Rules
During the packaging process, resource files are merged and processed according to certain rules:
Resource File Processing
- Image resources: Support PNG, JPG and other formats, will be compressed
- Font resources: Support TTF, OTF and other formats, will be optimized
- Audio resources: Support WAV, MP3 and other formats, will be compressed
Dependency Library Processing
- JavaScript modules: Will be merged and optimized
- Native libraries: Will be properly processed to ensure they are available on the target platform
Configuration File Processing
- manifest.json: Will be verified and processed to ensure correct format
- Other configuration files: Will be copied to the packaged product
Release and Deployment Methods
Release Process
- Develop application: Develop application source code and resources
- Package application: Use packaging tools to generate .eapk files
- Test application: Test the application on test devices
- Release application: Release the application to the application store or other distribution channels
Deployment Methods
- Local installation: Copy the .eapk file to the device through the file system, then use the application management API to install
- Remote installation: Download the .eapk file to the device through the network, then use the application management API to install
- OTA update: Update the application through OTA (Over-The-Air) method
Deployment Commands
# Local installation
eas_app_install("/path/to/app.eapk");
# Remote installation (example)
download_file("https://example.com/app.eapk", "/tmp/app.eapk");
eas_app_install("/tmp/app.eapk");
Packaging Tool Usage
Packaging Tool Parameters
| Parameter | Description | Example |
|---|---|---|
--input | Input directory path | --input app/ |
--output | Output file path | --output app.eapk |
--compress | Compression level (0-9) | --compress 9 |
--verbose | Detailed output | --verbose |
Running Examples
# Basic packaging
python3 scripts/eos_pkg_builder.py --input app/ --output app.eapk
# Packaging with compression
python3 scripts/eos_pkg_builder.py --input app/ --output app.eapk --compress 9
# Detailed output
python3 scripts/eos_pkg_builder.py --input app/ --output app.eapk --verbose
Application Configuration File
manifest.json Format
{
"id": "com.example.app",
"name": "Example Application",
"version": "1.0.0",
"type": "application",
"author": "Example Developer",
"description": "This is an example application",
"icon": "icon.bin",
"main": "main.js",
"permissions": [
"battery",
"sensor"
],
"resources": {
"images": [
"assets/images/logo.png"
],
"fonts": [
"assets/fonts/font.ttf"
]
}
}
Configuration Field Description
- id: Application's unique identifier, format:
com.example.app - name: Application's display name
- version: Application's version number, format:
x.y.z - type: Application type,
applicationorwatchface - author: Application's developer
- description: Application's description
- icon: Application's icon file
- main: Application's main script file
- permissions: Permissions required by the application
- resources: Application's resource files
Best Practices
- Directory structure: Follow the standard directory structure to ensure the packaging tool can correctly identify and process files
- Resource management: Organize resource files reasonably to avoid oversized resource files
- Configuration files: Ensure the manifest.json file is in correct format and contains all necessary fields
- Version control: Use semantic version numbers for easy version management and updates
- Permission management: Only apply for necessary permissions for the application, avoid excessive permission requests
Common Issues and Solutions
Packaging Failure
Issue: Packaging tool execution fails
Solutions:
- Check if the input directory structure is correct
- Check if the manifest.json file format is correct
- Check if resource files exist
Installation Failure
Issue: Application installation fails
Solutions:
- Check if the .eapk file is damaged
- Check if the application's permissions are correct
- Check if the device has enough storage space
Runtime Errors
Issue: Application runtime errors
Solutions:
- Check if the application's scripts have syntax errors
- Check if the application's resource files are correctly loaded
- Check if the application's permissions are granted
Summary
Application packaging is an important part of ElenixOS application development, which combines all components of the application into an installable package file. By understanding the application packaging format, resource organization, and output specifications, developers can better manage and distribute applications.
ElenixOS's application packaging tool provides a simple and efficient way to package applications, ensuring that applications can be correctly installed and run on different devices. By following best practices, developers can create high-quality application packages and provide users with a good application experience.