Android Development Command Line full introduction

Source: Internet
Author: User

As a fan of the command line, I've been trying to write this topic for some time now. In addition to being cool, the use of the command line can improve our development efficiency because it is obviously much quicker to use the keyboard to enter several characters and click tab when compared to a series of menu options by clicking the mouse.

The purpose of this article is to share with you the use of the command line in my Android development practice.

ITerm2

Since we will be working on the command line, it is obviously good to install a tool that is better than the system default command line, so download ITerm21!

ITerm2 brings the command line into the modern era, providing many of the features you've always wanted. It includes window splits, custom color schemes, clipboard history, fine-grained hotkey controls, and a range of 2 convenient preferences that you will gradually discover.

Oh-my-zsh

When you start the command-line app, it runs a Shell app called Bash. Bash is by far the most popular Shell application in the vast majority of Unix-based operating systems. In fact, however, there are also the alternatives to Bash, which make command execution faster and more friendly to developers.

By default, Oh-my-zsh comes with Git plugin 3, which provides a lot of aliases4 as well as many useful functions 5.

Command line Auto Prompt

ZSH-AUTOSUGGESTIONS6, similar to Fish7, provides a quick auto-prompt function for zsh, which is based on previous input history and automatically prompts for commands as you type.

Reverse Intelligent Search

You can use the Control+r shortcut key to perform a reverse intelligent search in the command history, starting with the command you entered, and the zsh will be automatically complete based on the previously entered command. You can then use the Enter key to execute the corresponding command, either by left ARROW or right-click to edit the command, or by continuing to press the Control+r shortcut key to select a different history command.

Dryrun

When you see a very cool library of functions on Github, how will you test it on your phone?

    1. Click the download zip button
    2. Unzip the downloaded zip package
    3. Open Android Studio
    4. Import the project you just downloaded and unzipped into Android Studio
    5. Sync Gradle
    6. Operation Engineering
    7. Choose which device the project will run on
    8. Test the library of functions that are running.
    9. Delete Engineering catalogs and packages that are no longer needed zip

Or you can use DRYRUN8:

dryrun REMOTE_GIT_URL
    • 1
    • 1

Offline build

--offlineTags enable gradle to always use dependent modules from the cache, even if they need to be re-checked for updates. When running in offline mode, Gradle does not attempt to perform dependency resolution on the network, and if the specified dependency is not in the local cache, the build will fail.

The commands executed at the fastest speed develop debug are as follows:

./gradlew assembleDevelopDebug --offline
    • 1
    • 1

The command to perform unit tests at the fastest speed is as follows:

./gradlew test --offline
    • 1
    • 1

In Android Studio, we can configure Gradle to run in offline mode with the following options:

Settings -> Build, Execution, Deployment -> Build tools -> Gradle

Alfi

As an Android developer, you should use Android Studio + Gralde mode for development. A very good feature of using Android Studio is its dependency management, the ability to automatically download dependent library artifacts from a specified repository, and make it possible for your project to use this artifacts. Typically, you just need to add a line of code to the project's Build.gradle file to include the specified dependent library, which is very simple, isn't it?

So do you know which line of code the dependent libraries you want to add correspond to? To achieve a quick look at how to configure this line of code, I developed a tool called Alfi, which is simple to use:

    1. Inputalfi 要依赖的函数库名
    2. Copy the resulting library configuration information (that's the line of code we said above)
    3. Copy configuration information to Build.gradle

For example alfi picasso , we will get the following result:

Understand the abbreviation for gradle tasks

If you execute the command at the command line ./gradlew tasks , you will see a list of available gradle tasks, but it will not list the abbreviations for these commands, and the following are some examples you can use:

    • IDD is the abbreviation of Installdevelopmentdebug
    • ADD is an abbreviation for Assembledevelopmentdebug
    • CC is the abbreviation of Connectedcheck
    • etc.

Using abbreviations, we can execute commands like this:

:App:iDD
    • 1
    • 1

You can see that we've got a shorter command.

Android Rocket Launcher

Android Rocket Launcher9 is a gradle plugin that is used to give Android Modules all the variants to install and start the tasks of the APK, so no need to run and work hard ./gradlew installDebug to find just installed in the phone Application and start it.

To introduce this feature into your project, simply build.gradle add two lines of key code to the file as follows:

‘android-rocket-launcher‘buildscript {    repositories {        jcenter()    }    dependencies {        classpath ‘com.cesarferreira:android-rocket-launcher:0.2.3‘    }}
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

Even if you launch the app from the command line, you can still bind the current process and the debugger to 10, without restarting the app in debug mode.

Output unit test results directly to the console

A clever way to see the results log of the Android unit test output in the console is to build.gradle add the following code to the file:

android {  ...  testOptions.unitTests.all {    testLogging {      events ‘passed‘, ‘skipped‘, ‘failed‘, ‘standardOut‘, ‘standardError‘ outputs.upToDateWhen { false } showStandardStreams = true } }}
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

Running unit tests after configuration can see the following results:

Easy to Logcats

In application development we often need to print out our app's log information, unfortunately, because the app redeployment installed on the phone, the app's process ID will change, so it is difficult to get the correct log information. Pidcat11 This tool solves this problem by filtering the app's package name rather than the app's process ID. We only need to provide the app's package name to get log information for this app only in the console:

pidcat github.cesarferreira.helloworld
    • 1
    • 1

Nutshell

Finally, we summarize the following key points as described above:

    • Install Iterm2, a better command line than the system default
    • Use OH-MY-ZSH to implement automatic hints
    • Use command abbreviations, such as./gradlew iDD
    • Use offline tagging --offline for faster execution of GRADLE commands
    • Logs for unit tests are printed in the console
    • After installing the app to your phone, do not manually find it on your phone and open it, but use the android-rocket-launcher plugin to automatically open it
    • Binds the current process and debugger, no need to restart the app in debug mode.
    • Use Pidcat for smarter, more convenient logcat

Android Development Command Line full introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.