Android--android Studio's compilation system Gradle (ii)

Source: Internet
Author: User

To execute the command line, first, configure it inside the environment variable.

1, manually install Gradle,bin-->gradle.bat, this directory is configured to the environment variable path inside, so as to run in the variable.

2. There are gradle in Android Studio. There are also gradle here.

Below each project there is a gradlew.bat this batch processing. Like the following command:

Gradle tasks lists all commands. If the build.gradle is more complicated, we can compare

Gradle build compiles all the tasks

Gradle assemblerelease only compile release

The Gradle Clean Command clearly describes the package under the app.

Android also provides a shell environment inside the terminal. can also be compiled here

Theoretically, only apply plugin and android{} can be compiled, if the project is more complex, you can use dependencies{} to introduce a dependency package, compile

Although already in a folder, but here, our app did not introduce the package inside the library

Write some configuration and know under which modules

It can also be done in eclipse, we can specify that a certain type of file exists under a certain directory, can be compiled with Gradle script

Android {//This is an Android module    compilesdkversion    buildtoolsversion "20.0.0"    sourcesets {//here is Difference.        Main {            manifest. Srcfile ' androidmanifest.xml '            java. srcdirs = [' src ']             Resources. srcdirs = [' src ']            aidl. srcdirs = [' src ']            renderscript.srcdirs = [' src ']            res. srcdirs = [' res ']            assets. srcdirs = [' Assets ']        }        instrumenttest.setroot (' Tests ')        debug.setroot (' build-types/debug ')        release.setroot (' Build-types/release ')    } 

Dependent Project Settings

1. Introduction of Rack Package

Right-click Properties, Open Module Settings F4, tap + sign, second item. After introducing Gson.jar and Gcm.jar, there are two more lines of files in the script.

dependencies {    Compile filetree (dir: ' Libs ', include: [' *.jar '])    compile ' com.android.support:appcompat-v7 : 22.2.1 '    compile files (' Libs/gcm.jar ')    compile files (' Libs/gson-2.3.1.jar ')
Of course, after we have modified the version of the Gson, or to change the name here, paralysis, will not automatically change. Use the following line of code to resolve. As soon as there is a new rack to throw into the libs inside, we directly quoted, no need to write code
Compile Filetree (include: ' *.jar ', dir: ' Libs ')
}

2, the introduction of local projects, the introduction of the new Moudle (library,)

Right-click Properties, Open Module Settings F4, tap + sign, third item.

dependencies {    Compile filetree (dir: ' Libs ', include: [' *.jar '])    compile ' com.android.support:appcompat-v7 : 22.2.1 '    Compile project (': Library:mylibrary ')}

Represents a module that is referenced.

Reference v4 package, V7 package.

Right-click Properties, Open Module Settings F4, tap + sign, first item.

  Compile ' com.android.support:appcompat-v7:22.2.1 '

    defaultconfig {        ApplicationID "Com.example.administrator.turnplatemenu"        minsdkversion        Targetsdkversion        versioncode 1        versionname "1.0"    }

This, if not written, Manifast will cover it.

3. Introduction of Remote Library

Right-click Properties, Open Module Settings F4, tap + sign, first item. Search Gson Library, after import, in the app below Lib inside is not. It's just a script to download the library remotely.

Modify package information at compile time

The real strength is the ability to modify definitions, package names, Versioncode Versionname,

Settings for signature files
    signingconfigs{//The following two names can be customized        releasekey{            storefile file (' MYKEY ')            storepassword ' 123456 '            keyalias 'androidrelease'   modified to--->andoridkey            keypassword (' 123456 ')        }        debugkey{            StoreFile file (' Mykey.debug ')            Storepassword ' android '            keyalias ' Androidbugkey '            keypassword Android        }    }

With this node, how to use it?

    defaultconfig {        ApplicationID "Com.example.administrator.turnplatemenu"        minsdkversion        Targetsdkversion        versioncode 1        versionname "1.0"        signingconfig Signingconfigs.releasekey     }

Add the last node to the Defaultconfig, specifying the signature document. but the defaultconfig must be defined below the Signingconfigs. This is a scripting language, not the same as a class.

Failed to read key from KeyStore

It says there's a problem with our code, and here we change it to Androidkey.

Compilation type: BuildType

The package used for compiling is used to do something. The general system defaults to two, one release a debug, but the following self-defined two.

buildtypes{        forrelease{            debuggable false        }        fordebug{            applicationidsuffix '. Debug '        }        fordailybuild{//Then there is an extension, sustainable inheritance,            Applicationidsuffix '. db '        }        formonkeytest{//with Monke Y run with            applicationidsuffix '. Monkey '        }

    productflavors {

phone{
ApplicationID ' Com.win16.nyapplicaiton '
Signingconfig Signingconfigs.releasekey
}
    
pad{
ApplicationID ' CON.WIN16.MYAPPLICATION.HD '
Signingconfig Singingconfigs.debugkey
}

       default_channel{} wandoujia{} _360{} yingyongbao{} xiaomi{} baidu{} huawei{} jifeng{} }

The so-called productflavors is actually a definable product feature that, manifest merger when used, can be achieved by producing multiple versions with its own feature configuration during a single compilation.

The function of the above configuration is to produce different values for each channel package UMENG_CHANNEL_VALUE .

Android--android Studio's compilation system Gradle (ii)

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.