My Android Studio Road Day 02

Source: Internet
Author: User

In the middle because of busy 2 days, did not put their study summary in time to write up, today specific summary in my study of enterprise-level project Build.gradle Some of the basic configuration properties,

When you create a new project using Android Studio, two Build.gralde files are generated by default, one located in the project root directory and one in the app directory. There is also another file--settings.gradle.

The script file under the root directory is the global configuration for module, and all of the module that the action threshold contains is configured by Settings.gradle.

The app folder is a module, and if you add a new module-Lib in the current project, you need to include the new module in the Settings.gralde file.

To import a new local jar package, you can directly pastejar the package to the Lib directory and then select Add file through the dependencies of the project right-click Open Module setting.

This completes the JAR file addition

Open the App directory has a build.gradle file should be the project structure file, the above action is just to add under the file

dependencies {

Compile files (' Libs/android-support-v13.jar ')

Compile files (' Libs/odata4j-0.7.0-clientbundle.jar ')

}

Package dependency Relationship

AAR in local directory

First, add the calling method to the Android parameter closure repositories

Repositories {    Flatdir {        dirs ' libs '    }}
Remove Duplicate dependencies
Compile ' com.alibaba.fastjson.latest.integration ' {    exclude module: ' Annotations ', group: ' Com.google.android '}

There are also some information about setting up the SDK, including the version level of the SDK, the tool level of the SDK, etc., which can be modified in this area.

Refer to the Learning Link: http://my.oschina.net/u/1471093/blog/341990 Below is a excerpt from the original text of this link

Setting the run environment for scriptsBuildscript {Supports Java-dependent Library Management (MAVEN/IVY) for project dependencies.repositories {mavencentral ()}The definition of the dependent package. Support Maven/ivy, remote, local library, also support single filedependencies {Classpath' com.android.tools.build:gradle:0.4 '}}Declare the type of project that was built, here of course Android has the Apply plugin:' Android 'Set the parameters for compiling Android project Android {compilesdkversionBuildtoolsversion"Defaultconfig" {minsdkversion8 Targetsdkversion17}Android Default configurationSourcesets {main {manifest.srcfile' Androidmanifest.xml ' java.srcdirs = [' src '] resources.srcdirs = [' src '] aidl.srcdirs = [' src '] renderscript.srcdirs = [' src '] res.srcdirs = [' res '] assets.srcdirs = [' Assets ']}The path where the test is located is assumed to be the tests folder, and there is no way to write this line instrumenttest.setroot (' Tests ')}This is the code to resolve lint error Lintoptions {AbortonerrorFalse}/** * Signature Settings */signingconfigs {myconfigs {storefileFile"Signature file Address") Keyalias"..." Keypassword"..." Storepassword"..."            }        }/** * Obfuscation Settings */buildtypes {release {signingconfig signingconfigs.myconfi GS RunproguardTrue Proguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro '}}/** * Channel packaging (different package name) */productflavors {qqqq {ApplicationID =' Package name '} hhhhh {applicationid=' Package Name '}}}/** *. so file import */Task Copynativelibs (Type:Copy) {FromFiletree (dir:' Libs ',Include' Armeabi/*.so ')Into' Build/lib '} tasks.withtype (Compile) {Options.encoding ="UTF-8"} tasks.withtype (Compile) {compiletask, Compiletask.dependson copynativelibs} Clean.dependson' Cleancopynativelibs ' Tasks.withtype (com.android.build.gradle.tasks.PackageApplication) {pkgtask-pkgt Ask.jnifolders = [new File (BuildDir, ' Lib ')]} //dependent library dependencies { compile filetr EE (dir: ' Libs ', include: [' *.jar '])}          

Local dependency

Gradle as a build tool, it is easy to use the local jar package, the following is the code block used.

dependencies {        //单文件依赖    compile files(‘libs/android-support-v4.jar‘) //某个文件夹下面全部依赖 compile fileTree(dir: ‘libs‘, include: ‘*.jar‘)}android { }

Remote dependency

Gradle also supports Maven,ivy, because Ivy I have not used, so with Maven as an example, the following is the code block:

repositories {        //从中央库里面获取依赖    mavenCentral()    //或者使用指定的本地maven 库    maven{        url "file://F:/githubrepo/releases"    }    //或者使用指定的远程maven库 maven{ url "远程库地址" }}dependencies {        //应用格式: packageName:artifactId:version compile ‘com.google.android:support-v4:r13‘}android {}

Android Library Dependent

For a project that relies on the Android library, it's not dependent on a jar, so it's easy to use the Gradle mulit project mechanism here. In the past, the Android library did not have a good package management method, in short, before the advent of Gradle, the official does not have a way to manage the Android library dependency package, generally we are directly download other people's Android library The project source code is integrated, and the Android-maven-plugin for third parties is in apklib format.

Now, officially, the official launch of an Android library packaging format, the extension of the *.aar . As mentioned earlier, the current Android Gradle plugin does not support the local direct use *.aar of the file, however, support package management Library Reference Way, below, I say for everyone, how to release the Android library to use.

Pack Android Library

The Android library is packaged directly under the Library project, gradle build and then you will see two files in the Build/libs directory, one for the debug pack, *.aar one for release, and for personal use, Here we are using the release version of the. aar file.

The reference script is similar to the previously mentioned dependency library

dependencies {    compile(name: ‘pulltorefresh‘, ext: ‘aar‘)}

Finally, share a MAVEN library address: http://mvnrepository.com/and Gradle version address: Http://tools.android.com/tech-docs/new-build-system

Additionally, the Gradle file configuration section is updated: http://my.oschina.net/u/1471093/blog/354442

added here, the latest Grad has a configuration address of : http://my.oschina.net/u/1471093/blog/539075

My Android Studio Road Day 02

Related Article

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.