Gradle Command Detail and import third-party packages

Source: Internet
Author: User

The combination of Android Studio + Gradle is very handy, and many third-party open source projects have migrated to Studio early, so today you'll find ways to view, compile, and import third-party open source projects.

Sublime + Terminal compile and view the source code

First of all, to introduce a simple and personal favorite way. Many times we see a good open source project on GitHub, generally there are two kinds of requirements, read the source and view the running effect, if it is simple to view the source code I prefer to use some lightweight editor, such as Vim,sublime, Vim is not very skilled, So the individual is accustomed to use sublime to view and read the source code (the actual development or Android Studio, Eclipse and other Ides more efficient); As for the first need to see the performance of the APK, for some open source projects have been provided apk download, it is good to do, Install directly to your phone. For some that do not provide apk download, you need to manually compile the package yourself.

The following is a 9GAG example to explain the command line Gradle compilation process.

    • 1. Switch to the root directory of the 9GAG project and execute the ./gradlew-v to see the gradle version of the project

If you are doing the first time to download gradle, this process if not fq very slow, suggest FQ

Immediately after the download, you will see the following information:

------------------------------------------------------------Gradle2.2.1------------------------------------------------------------BuildTime:2014-11-2409:45:35UtcBuildNumber:NoneRevision:6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4aGroovy:2.3.6Ant:ApacheAnt(Tm)Version1. 9. 3 compiled on december 23 2013< Span class= "ss" >jvm: 1. 7. 0_60  (oracle corporation 24.< Span class= "Mi" >60-b09) os: Span class= "No" >mac os x 10. 9. 5 x86_64              
    • 2, then execute ./gradlew Clean

Executing this command will download some dependencies for Gradle, and when the download is successful and compiled, you will see the following information:

:app:clean UP-TO-DATE:extras:ShimmerAndroid:clean UP-TO-DATEBUILD SUCCESSFUL
    • 3, the final implementation ./gradlew Build

This command compiles and generates the appropriate APK file, and if you see the following, the build succeeds.

BUILD SUCCESSFULTotal time: 31.456 secs

Immediately following the 9gag/app/build/outputs/apk directory you will see similar to app-debug-unaligned.apk, APP-RELEASE-UNSIGNED.APK, see the name should be able to understand the meaning, unaligned representative did not zip optimization, unsigned representative unsigned. You can then install the APK directly to see how it works.

These are my personal habits of a reading of the third-party source code habits, about the above mentioned some of the Gradle command you should not understand, the following will be explained.

Import Android Studio

But if you still want to import Android studio, here's a quick introduction to how to import studio and some caveats.

    • 1. Select File->import Project to select a directory for local 9GAG projects

    • 2, the first time will still download gradle, in fact, the command line has been downloaded, but this time still have to download (still FQ), may be a bug

    • 3, after the import you need to pay attention to the following several places
    1. The buildtoolsversion under the build.gradle under each module, namely 9gag/app/build.gradle and 9gag/extras/ Shimmerandroid/build.gradle , you can open the SDK Manager to view the local SDK Build-toolsthat you installed, for example, if the corresponding version is not installed please download it first.

    1. Project root directory under build.gradle gradle plug-in version, such as 9gag/build.gradle content:

      Classpath ' com.android.tools.build:gradle:1.0.0 '

Android Studio 1.0 must specify the version of the Gradle plugin 1.0

    1. Gradle wrapper version, in the 9gag/gradle/wrapper/gralde-wrapper.properties file has the following content:
#Thu Dec 16:02:24 CST 2014Distributionbase=Gradle_user_homeDistributionpath=wrapper/distszipstorebase=< Span class= "No" >gradle_user_homezipstorepath=wrapper /distsdistributionurl=https< Span class= "p" >\://services. Gradle. Org/distributions/gradle-2. 2. 1-all. Zip                  

The above content has developed a version of Gradle using 2.2.1, in Studio if you manually change the version of the Gradle plugin you will be prompted to update Gradle wrapper version.

If the above several places to determine the version is OK, then import Android Studio should be no problem, some old project may gradle version older, still use some old syntax, if the compilation also does not pass reference to the Android Studio series Tutorial IV – The Gradle base changes to the latest syntax.

Gradle Common Commands

The above has been touched by a number of commands such as ./gradlew-v ./gradlew clean ./gradlew build, note here is ./gradlew, ./< /c4> represents the current directory,Gradlew represents gradle wrapper, meaning gradle a layer of packaging, you can understand that in this project locally encapsulated Gradle, Gradle Wrapper, in 9gag/ the directory and version that it points to are declared in the Gradle/wrapper/gralde-wrapper.properties file. As long as the download succeeds, replace the Global gradle command with the Grdlew Wrapper command.

Understanding the concept of Gradle wrapper, the following common commands are easy to understand.

    • ./gradlew-v Version Number

    • ./gradlew clean Clear the Build folder under the 9gag/app directory

    • ./gradlew build check dependencies and compile package

Note here that the ./gradlew build command to the debug, Release environment package all out, if the official release only need to hit release package, what to do, the following is a very useful command **assemble**, such as

    • ./gradlew Assembledebug compiles and hits the debug package

    • ./gradlew Assemblerelease compiling and playing the release package

In addition, assemble can also be used in conjunction with productflavors, specifically in the next multi-channel packaging further explanation.

    • ./gradlew installrelease Release mode package and install

    • ./gradlew Uninstallrelease Uninstall Release Mode pack

Gradle Command Detail and import third-party packages

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.