Android uses Gradle for packaging and obfuscation, including dependent libraries and androidgradle

Source: Internet
Author: User
Tags jcenter

Android uses Gradle for packaging and obfuscation, including dependent libraries and androidgradle

The following script 100% can be used, as long as your version and path are correctly configured

Environment: Eclipse Windows 7

Gradle: 2.3

The Android project contains multiple libraries.

Main project Configuration:


Settings. gradle file configuration library

include 'lib_01'include 'lib_02'project(':lib_01').projectDir = new File('D:\\pj1')project(':lib_02').projectDir = new File('D:\\pj2')

The Library name corresponds to the project path of the database. If the library name is associated with the main project, you can use the relative path.

Build. gradle content


buildscript {    repositories {        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:1.1.2'    }}apply plugin: 'com.android.application'android {    compileSdkVersion 18    buildToolsVersion "19.1.0"        lintOptions {       abortOnError false    }            sourceSets {        main {            manifest.srcFile 'AndroidManifest.xml'            java.srcDirs = ['src']            resources.srcDirs = ['src']            res.srcDirs = ['res']            assets.srcDirs = ['assets']        }    }signingConfigs {        release {            storeFile file("D:\\my.keystore")            storePassword "112233"            keyAlias "test"            keyPassword "112233"        }    }    buildTypes {        release {            signingConfig signingConfigs.release    minifyEnabled true            proguardFile 'proguard.txt'        }    }        }dependencies {   compile files('libs/ftp4j-1.7.2.jar','libs/mymap.jar')   compile project(':lib_01')   compile project(':lib_02')}


In general, proguard.txt is configured under the main project, but you do not need to add -- libraryjars in the file. Otherwise, you will be reported to have referenced jar twice for twice.


The compile project corresponds to the two library libraries above.


Two Dependent libraries also require a build. gradle. Each dependent library project requires a build. gradle.

Content:

buildscript {    repositories {        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:1.1.2'    }}apply plugin: 'android-library'android {    compileSdkVersion 18    buildToolsVersion "19.1.0"    defaultConfig {        minSdkVersion 14        targetSdkVersion 19    }    sourceSets {        main {            manifest.srcFile 'AndroidManifest.xml'            jniLibs.srcDirs = ['libs']            java.srcDirs = ['src']            resources.srcDirs = ['src']            aidl.srcDirs = ['src']            renderscript.srcDirs = ['src']            res.srcDirs = ['res']            assets.srcDirs = ['assets']        }    }        }

When the project is packaged, find the dependent database to process and generate the dependent aar, and all the APK files are in the build/output directory. JniLibs. srcDirsIs used to process so module files.

Note: by default, no Activity exists in the AndroidManifest. xml file of the sub-project. If so, remove the Activity. (This area does not study how to avoid multiple manifest problems)


The dependency file should be empty.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="my.mobile.package01" >    <uses-sdk        android:minSdkVersion="9"        android:targetSdkVersion="19" />    <application        android:allowBackup="true"        android:icon="@drawable/app_icon"        >    </application></manifest>


Configure the environment variables for the downloaded gradle.
In the main project

Execute gradle tasks

Execute gradle build

Gradle although convenient, but Gradle version is not compatible with the problem, and need to download the relevant library and jar files, just need to constantly try, go to the http://stackoverflow.com/above generally can know to find the answer.



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.