Gradle enabled android project

  • Published on

  • View

  • Download

Embed Size (px)


Learn to use gradle in android project You can find the samples here:


<ul><li> Gradle enabled android project shakalaca @ Taipei GTUG 1 </li> <li> 2 </li> <li> Outline Gradle introduction Step by step tutorial Basic Dependency Sign / Proguard Variant Android Studio integration Q &amp; A 3 </li> <li> Gradle 4 </li> <li> What is gradle ? Gradle is build automation evolved. Gradle can automate the building, testing, publishing, deployment and more of software packages or other types of projects such as generated static websites, generated documentation or indeed anything else. Gradle combines the power and exibility of Ant with the dependency management and conventions of Maven into a more effective way to build. Powered by a Groovy DSL and packed with innovation, Gradle provides a declarative way to describe all kinds of builds through sensible defaults. Gradle is quickly becoming the build system of choice for many open source projects, leading edge enterprises and legacy automation challenges. - 5 </li> <li> .. short version An open source build system that combines the power of Ant &amp; Maven 6 </li> <li> Why gradle ? Powerful Build System Declarative, Flexible Imperative customization Tooling API Build System Toolkit Plugins create own DSL,APIs, IDE integration Free / Open Source 7 </li> <li> Android project integration gradle android plugin build-system/ = 8 </li> <li> command format gradle command tasks assemble assemble release assemble debug aR 9 </li> <li> output /build/apk/ 10 </li> <li> Basic 11 </li> <li> Eclipse project 12 </li> <li> 13 </li> <li> build.gradle apply plugin:android dependencies compileSdkVersion buildToolsVersion defaultCong sourceSets 14 </li> <li> dependencies compile project(:project1) compile leTree(dir:libs, include:*.jar) compile les(libs/android-support-v4.jar) compile v4:13.0.0 15 </li> <li> android packages 16 </li> <li> android packages 17 </li> <li> defaultCong versionCode versionName minSdkVersion targetSdkVersion packageName testPackageName testInstrumentatio nRunner signingCong proguardFile proguardFiles 18 </li> <li> Dependency 19 </li> <li> Project structure 20 </li> <li> 21 </li> <li> settings.gradle Used in multi-project hierarchy Dene projects to be used in build 22 </li> <li> settings.gradle 23 </li> <li> settings.gradle 24 </li> <li> er .. no direct way ? 25 </li> <li> 26 </li> <li> 27 </li> <li> 28 </li> <li> Sign release key 29 </li> <li> 30 </li> <li> Build Types default 2 types: debug &amp; release for debugging &amp; signing 31 </li> <li> Build Types debuggable jniDebugBuild renderscriptDebugBuild renderscriptOptimLevel packageNameSufx versionNameSufx signingCong zipAlign runProguard proguardFile proguardFiles 32 </li> <li> tips Save your in ~/.gradle/ .. If you work alone 33 </li> <li> Proguard 34 </li> <li> 35 </li> <li> Variant 36 </li> <li> Build variants Creating different versions of same application free/paid multi-apk BuildVariant = Build Type + Product Flavor 37 </li> <li> Product Flavors Denes a customized version of application build by the project Free / Paid Amazon / Play Store / blah store Same type as defaultCong 38 </li> <li> 39 </li> <li> 40 </li> <li> One more thing 41 </li> <li> gradle wrapper Setup gradle automatically $ANDROID_HOME/tools/templates/gradle/ wrapper/ 42 </li> <li> 43 </li> <li> summry simple android project sign release key run proguard build variants wrapper 44 </li> <li> Android Studio integration 45 </li> <li> Android Studio integration BETA 46 </li> <li> Survival guide Rule #1 Always backup your project. 47 </li> <li> Survival guide Rule #2 Dont import production code until 1.0 is out.. 48 </li> <li> Best practice ? Import modules manually pro short compile / AS startup time consider project with multiple libraries.. con no variant builds (ok for most people) 49 </li> <li> R U KIDDING ME ? 50 </li> <li> 51 </li> <li> Basic 52 </li> <li> 53 </li> <li> congurations 54 </li> <li> 55 </li> <li> import.. 56 </li> <li> import.. 57 </li> <li> import.. 58 </li> <li> import.. 59 </li> <li> Piece of cake 60 </li> <li> Dependency 61 </li> <li> project layout 62 </li> <li> congurations 63 </li> <li> ... errrrrr Dont recognize as library project No typo checking, no function reference, no ... But you can still build the project 64 </li> <li> duplicated name ? 65 </li> <li> try another way 66 </li> <li> errrrrrr 67 </li> <li> 68 </li> <li> Rene project layout 69 </li> <li> working congurations 70 </li> <li> tips as simple as possible library/xxx_lib use : instead of / in path ugly, but runs ne 71 </li> <li> Local repository 72 </li> <li> What &amp; Why ? Use aar instead of re-compiling everything aar: Binary distribution of an Android Library Project build-system/aar-format Time is money DRY 73 </li> <li> project layout 74 </li> <li> root-build.gradle 75 </li> <li> library/build.gradle 76 </li> <li> project/build.gradle archivesBaseName version 77 </li> <li> app/build.gradle 78 </li> <li> How deploy library ./gradlew deploy use local repository ./gradlew as -PuseRepo 79 </li> <li> Tricks 80 </li> <li> rename apk 81 </li> <li> launch after install 82 </li> <li> move out apk 83 </li> <li> Refresh cache --refresh-dependencies stay up-to-date (?) dependency_management.html#sec:cache_command_line_options 84 </li> <li> Q &amp; A 85 </li> <li> References build-system Guide / Samples 86 </li> </ul>