Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Gradle enabled android project

Gradle enabled android project

Learn to use gradle in android project

Samples are here: https://github.com/shakalaca/learning_gradle_android

Shaka Huang

August 28, 2013
Tweet

More Decks by Shaka Huang

Other Decks in Programming

Transcript

  1. Outline • Gradle introduction • Step by step tutorial •

    Basic • Dependency • Sign / Proguard • Variant • Android Studio integration • Local Repository • Tricks & Tips • Q & A
  2. • Gradle introduction • Step by step tutorial • Basic

    • Dependency • Sign / Proguard • Variant • Android Studio integration • Local Repository • Tricks & Tips • Q & A
  3. 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 flexibility 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. - http://www.gradle.org/
  4. Why gradle ? • Powerful Build System • Declarative, Flexible

    • Imperative customization • Tooling API • Build System Toolkit • Plugins create own DSL, APIs, IDE integration • Free / Open Source
  5. How gradle works ? • Lifecycle • Initialization • Configuration

    • Execution • Build scripts • settings.gradle • build.gradle • gradle.properties
  6. Command • gradle <task name> • tasks • clean •

    assemble • assembleRelease • assembleDebug • aR / asD
  7. • Gradle introduction • Step by step tutorial • Basic

    • Dependency • Sign / Proguard • Variant • Android Studio integration • Local Repository • Tricks & Tips • Q & A
  8. Dependencies • compile project(‘:project1’) • compile fileTree(dir: ‘libs’, include: ‘*.jar’)

    • compile files(‘libs/android-support-v4.jar’) • compile ‘com.android.support:support- v4:18.0.0’
  9. Android packages • SDK Manager • Google Repository & Android

    Repository • Packages • com.android.support:support-v4:18.0.0 • com.android.support:appcompat-v7:18.0.0 • com.android.support:gridlayout-v7:18.0.0 • com.android.support:support-v7-mediarouter:18.0.0 • com.android.support:support-v13:18.0.0 • com.google.android.gms:play-services:3.2.25
  10. defaultConfig • versionCode • versionName • minSdkVersion • targetSdkVersion •

    packageName • testPackageName • testInstrumentatio nRunner • signingConfig • proguardFile • proguardFiles
  11. • Gradle introduction • Step by step tutorial • Basic

    • Dependency • Sign / Proguard • Variant • Android Studio integration • Local Repository • Tricks & Tips • Q & A
  12. • Gradle introduction • Step by step tutorial • Basic

    • Dependency • Sign / Proguard • Variant • Android Studio integration • Local Repository • Tricks & Tips • Q & A
  13. Build types • debuggable • jniDebugBuild • renderscriptDebugBuild • renderscriptOptimLevel

    • packageNameSuffix • versionNameSuffix • signingConfig • zipAlign • runProguard • proguardFile • proguardFiles
  14. • Gradle introduction • Step by step tutorial • Basic

    • Dependency • Sign / Proguard • Variant • Android Studio integration • Local Repository • Tricks & Tips • Q & A
  15. Build variants • Creating different versions of same application •

    free/paid • multi-apk • Build Variant = Build Type + Product Flavor
  16. Product flavors • Defines a customized version of application build

    by the project • Free / Paid • Amazon / Play Store / blah store • Same type as defaultConfig
  17. Build • gradle assemblePaid • gradle aPD / gradle aPR

    • gradle assembleFree • gradle aFD / gradle aFR
  18. Summary • Simple android project • Sign release key •

    Run proguard • Build variants • Wrapper
  19. • Gradle introduction • Step by step tutorial • Basic

    • Dependency • Sign / Proguard • Variant • Android Studio integration • Local Repository • Tricks & Tips • Q & A
  20. • Gradle introduction • Step by step tutorial • Basic

    • Dependency • Sign / Proguard • Variant • Android Studio integration • Local Repository • Tricks & Tips • Q & A BETA
  21. Best practice ? • Import modules manually • pro •

    short compile / AS startup time • consider project with multiple libraries.. • con • no variant builds (ok for most people)
  22. ... errrrrr • Don’t recognize as library project • No

    typo checking, no function reference, no ... • But you can still build the project
  23. Tips • as simple as possible • library/xxx_lib • use

    ‘:’ instead of ‘/’ in path • ugly, but runs fine
  24. • Gradle introduction • Step by step tutorial • Basic

    • Dependency • Sign / Proguard • Variant • Android Studio integration • Local Repository • Tricks & Tips • Q & A
  25. What & Why ? • Use aar instead of re-compiling

    everything • aar: Binary distribution of an Android Library Project • http://tools.android.com/tech-docs/new- build-system/aar-format • Time is money • DRY
  26. How • deploy library • ./gradlew deploy • use local

    repository • ./gradlew as -PuseRepo
  27. • Gradle introduction • Step by step tutorial • Basic

    • Dependency • Sign / Proguard • Variant • Android Studio integration • Local Repository • Tricks & Tips • Q & A
  28. Known issues • Library project is always release build •

    Poor NDK support • https://gist.github.com/pboos/ 5802233#file-ndk-build-gradle
  29. • Gradle introduction • Step by step tutorial • Basic

    • Dependency • Sign / Proguard • Variant • Android Studio integration • Local Repository • Tricks & Tips • Q & A
  30. References • Documentation • http://tools.android.com/tech-docs/new-build-system (Guide / Samples) • http://www.gradle.org/documentation

    • Forums • https://plus.google.com/u/0/communities/114791428968349268860 • https://groups.google.com/forum/#!forum/adt-dev • http://stackoverflow.com/questions/tagged/gradle • Tool • http://gradleplease.appspot.com/