Introduction
⚠ Still️ in early development. Bugs may arise.
Android CLI is a powerful tool that simplifies and streamlines the Native Android development process.
It provides a single interface for developers to create, build, and release Android applications without the need for cumbersome IDEs like Android Studio.
Github Project can be found here
Installation
Using cargo
From crates.io
$ cargo install android-cli
From git directly (latest changes, may be unstable)
$ cargo install --git https://github.com/SyedAhkam/android-cli.git
Using github releases
Haven't set this up yet. Coming soon.
From source
Ensure you have the latest stable version of Rust installed (with Cargo). Then, clone the repository and run the following command from the root of the repository:
$ cargo install --path .
After installation, you should have access to the
android
binary from your choice of shell.
Create or Link Project
There are mainly two ways to get started -- either create a new project or link to an existing android project.
Create
You may create or initialize a project using
$ android create
And then answer a few prompts:
- Destination path
- Project name
- Package identifier
The template project that this is based upon lives here. Open for contributions.
After creating the project, you can start editing the source and run the project.
$ cd <dest>
$ android run
Link an existing project
If you already have an android project bootstrapped, you will need to link it.
$ android link
You might need to dig into your own source code to figure out the appropriate prompt values. Especially the package identifier and main activity class name.
All this essentially does is create a .android file which is then relied upon by the CLI for future operations.
Build Project
USAGE:
android build [OPTIONS]
OPTIONS:
-h, --help Print help information
-r, --release Should build in release mode
What it does
For now, it just execs ./gradlew assemble[Debug|Release]
.
Examples
Building in Debug mode
$ android build
Building in Release mode
$ android build --release
Install App
USAGE:
android install [OPTIONS]
OPTIONS:
-h, --help Print help information
-r, --release Should install release APK
What it does
Executes adb install
under the hood and simply returns the output.
Examples
Install in Debug mode
$ android install
Install in Release mode
$ android install --release
Launch App
USAGE:
android launch
OPTIONS:
-h, --help Print help information
What it does
It requests ADB to launch the configured main activity of the installed app onto the connected device or emulator, effectively running our app.
Example
$ android launch
Run App
USAGE:
android run [OPTIONS]
OPTIONS:
-h, --help Print help information
-r, --release Should build in release mode
What it does
It is a combination of three commands, android build
, android install
and android launch
giving you an illusion of a single operation being executed.
Examples
Running in Debug mode
$ android run
Running in Release mode
$ android run --release
List Devices
USAGE:
android devices
OPTIONS:
-h, --help Print help information
What it does
Executes adb devices
and returns the output.
Example
$ android devices
android shell
USAGE:
android shell
OPTIONS:
-h, --help Print help information
What it does
It simply asks adb
to attach a shell to your connected android device / emulator by executing adb shell
.
Example
$ android shell
android emulator
Not implemented yet.
Dot Android
It refers to the .android
file in your project root directory.
It is used to store certain configuration settings for the Android CLI. It is created when you either initialize a new project or run android link
.
// DO NOT MODIFY; Generated by Android CLI for internal usage.
(
project_name: "testing",
package_id: "com.example.testing",
gen_at_version: "0.1.0",
main_activity_name: "MainActivity",
)
File format
The file is a RON file (Rusty Object Notation). It is kinda like JSON, but with a heavy rusty influence. You can read more about it here.
Fields
Project name
The name of the project. This is the name you gave when you initialized the project. Usually, it is the name of the directory that contains your project.
Package ID
This is the package identifier or package name of your app. The convention comes from Java apps. It is used to uniquely identify your app on the device and on the Play Store. It is usually in the form of com.example.appname
.
Gen at version
This is the version of the Android CLI that generated this file. It is used to determine if the file is compatible with the current version of the CLI. This is used to prevent breaking changes from breaking your project.
Main activity name
This is the name of the main activity of your app. This is the activity that is launched when your app is opened. It is usually left untouched as MainActivity
.
Usage
It is not recommended to modify this file manually. It is generated and updated by the CLI. In the future, the CLI will be able to perform migrations on your project and update this file for you automatically.
Frequently Asked Questions
1. Isn't there already an android
tool that ships with the android SDK?
Yes, there is an android
bash script that comes with the Android SDK. However, it has been deprecated, and its functionalities have been absorbed into Android Studio, making it the only supported option for Android development. This decision has frustrated developers who prefer to use a CLI to manage their projects.
2. But wait.. Don't I have to install Android Studio to get the SDK?
Not necessarily. If you go to Android Studio download page and scroll down enough you'll see a section named 'Command line tools only'. Just grab that and there's no need for Android Studio.
3. Is a simple wrapper even enough?
Well yes and no, I eventually intend to build an interface on top of the existing commands in the near future to make actions more controllable and user-friendly as a whole. For example: imagine a prompt which lets you choose which device to run your project on, and even offer launching an emulator right there. there's so many possibilities.
Legal
The tool itself is forever free. Distributed under the MIT License.
However, the Android SDK is not free. You must accept the Android SDK License Agreement before using the SDK.
Additionally, the Android CLI is not affiliated with Google or the Android Open Source Project. Android is a trademark of Google Inc.