Your SlideShare is downloading. ×
0
Gradle enabled android
project
shakalaca @ Taipei GTUG
1
about.me/shakalaca
shakalaca@gmail.com
http://profiles.google.com/shakalaca
2
Outline
• Gradle introduction
• Step by step tutorial
• Basic
• Dependency
• Sign / Proguard
• Variant
• Android Studio in...
Gradle
4
What is gradle ?
Gradle is build automation evolved. Gradle can automate the
building, testing, publishing, deployment and...
.. short version
An open source build system that combines the
power of Ant & Maven
6
Why gradle ?
• Powerful Build System
• Declarative, Flexible
• Imperative customization
• Tooling API
• Build System Toolk...
Android project
integration
• gradle android plugin
• http://tools.android.com/tech-docs/new-
build-system/
=
8
command
• format
• gradle <command>
• command
• tasks
• assemble
• assemble release
• assemble debug
• aR
9
output
• <project>/build/apk/
10
Basic
11
Eclipse project
12
13
build.gradle
• apply plugin:‘android’
• dependencies
• compileSdkVersion
• buildToolsVersion
• defaultConfig
• sourceSets
14
dependencies
• compile project(‘:project1’)
• compile fileTree(dir:‘libs’, include:‘*.jar’)
• compile files(‘libs/android-su...
android packages
• com.android.support:support-v4:13.0.0
• com.android.support:support-v13:13.0.0
• com.android.support:gr...
android packages
• com.android.support:support-v4:18.0.0
• com.android.support:support-v13:18.0.0
• com.android.support:gr...
defaultConfig
• versionCode
• versionName
• minSdkVersion
• targetSdkVersion
• packageName
• testPackageName
• testInstrume...
Dependency
19
Project structure
20
21
settings.gradle
• Used in multi-project hierarchy
• Define projects to be used in build
22
settings.gradle
23
settings.gradle
24
er .. no direct way ?
25
26
27
28
Sign release key
29
30
Build Types
• default 2 types: debug & release
• for debugging & signing
31
Build Types
• debuggable
• jniDebugBuild
• renderscriptDebugBuild
• renderscriptOptimLevel
• packageNameSuffix
• versionNam...
tips
• Save your gradle.properties in ~/.gradle/
• .. If you work alone
33
Proguard
34
35
Variant
36
Build variants
• Creating different versions of same
application
• free/paid
• multi-apk
• BuildVariant = Build Type + Pro...
Product Flavors
• Defines a customized version of application
build by the project
• Free / Paid
• Amazon / Play Store / bl...
39
40
One more thing
41
gradle wrapper
• Setup gradle automatically
• $ANDROID_HOME/tools/templates/gradle/
wrapper/
42
43
summry
• simple android project
• sign release key
• run proguard
• build variants
• wrapper
44
Android Studio integration
45
Android Studio integration
BETA
46
Survival guide
Rule #1
Always backup your project.
47
Survival guide
Rule #2
Don’t import production code until 1.0 is out..
48
Best practice ?
• Import modules manually
• pro
• short compile / AS startup time
• consider project with multiple
librari...
R U KIDDING ME ?
50
51
Basic
52
53
configurations
54
55
import..
56
import..
57
import..
58
import..
59
Piece of cake
60
Dependency
61
project layout
62
configurations
63
... errrrrr
• Don’t recognize as library project
• No typo checking, no function reference,
no ...
• But you can still bui...
duplicated name ?
65
try another way
66
errrrrrr
67
68
Refine project layout
69
working configurations
70
tips
• as simple as possible
• library/xxx_lib
• use ‘:’ instead of ‘/’ in path
• ugly, but runs fine
71
Local repository
72
What & Why ?
• Use aar instead of re-compiling everything
• aar: Binary distribution of an Android
Library Project
• http:...
project layout
74
root-build.gradle
75
library/build.gradle
76
project/build.gradle
• archivesBaseName
• version
77
app/build.gradle
78
How
• deploy library
• ./gradlew deploy
• use local repository
• ./gradlew as -PuseRepo
79
Tricks
80
rename apk
81
launch after install
82
move out apk
83
Refresh cache
• --refresh-dependencies
• stay up-to-date (?)
http://www.gradle.org/docs/current/userguide/
dependency_mana...
Q & A
85
References
• http://tools.android.com/tech-docs/new-
build-system
• Guide / Samples
• http://www.gradle.org/documentation
...
Upcoming SlideShare
Loading in...5
×

Gradle enabled android project

6,224

Published on

Learn to use gradle in android project

You can find the samples here: https://github.com/shakalaca/learning_gradle_android

Published in: Self Improvement, Technology

Transcript of "Gradle enabled android project"

  1. 1. Gradle enabled android project shakalaca @ Taipei GTUG 1
  2. 2. about.me/shakalaca shakalaca@gmail.com http://profiles.google.com/shakalaca 2
  3. 3. Outline • Gradle introduction • Step by step tutorial • Basic • Dependency • Sign / Proguard • Variant • Android Studio integration • Q & A 3
  4. 4. Gradle 4
  5. 5. 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/ 5
  6. 6. .. short version An open source build system that combines the power of Ant & Maven 6
  7. 7. 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
  8. 8. Android project integration • gradle android plugin • http://tools.android.com/tech-docs/new- build-system/ = 8
  9. 9. command • format • gradle <command> • command • tasks • assemble • assemble release • assemble debug • aR 9
  10. 10. output • <project>/build/apk/ 10
  11. 11. Basic 11
  12. 12. Eclipse project 12
  13. 13. 13
  14. 14. build.gradle • apply plugin:‘android’ • dependencies • compileSdkVersion • buildToolsVersion • defaultConfig • sourceSets 14
  15. 15. dependencies • compile project(‘:project1’) • compile fileTree(dir:‘libs’, include:‘*.jar’) • compile files(‘libs/android-support-v4.jar’) • compile ‘com.android.support:support- v4:13.0.0’ 15
  16. 16. android packages • com.android.support:support-v4:13.0.0 • com.android.support:support-v13:13.0.0 • com.android.support:gridlayout-v7:13.0.0 • com.google.android.gms:play-services:3.1.36 16
  17. 17. android packages • com.android.support:support-v4:18.0.0 • com.android.support:support-v13:18.0.0 • com.android.support:gridlayout-v7:18.0.0 • com.google.android.gms:play-services:3.2.25 17
  18. 18. defaultConfig • versionCode • versionName • minSdkVersion • targetSdkVersion • packageName • testPackageName • testInstrumentatio nRunner • signingConfig • proguardFile • proguardFiles 18
  19. 19. Dependency 19
  20. 20. Project structure 20
  21. 21. 21
  22. 22. settings.gradle • Used in multi-project hierarchy • Define projects to be used in build 22
  23. 23. settings.gradle 23
  24. 24. settings.gradle 24
  25. 25. er .. no direct way ? 25
  26. 26. 26
  27. 27. 27
  28. 28. 28
  29. 29. Sign release key 29
  30. 30. 30
  31. 31. Build Types • default 2 types: debug & release • for debugging & signing 31
  32. 32. Build Types • debuggable • jniDebugBuild • renderscriptDebugBuild • renderscriptOptimLevel • packageNameSuffix • versionNameSuffix • signingConfig • zipAlign • runProguard • proguardFile • proguardFiles 32
  33. 33. tips • Save your gradle.properties in ~/.gradle/ • .. If you work alone 33
  34. 34. Proguard 34
  35. 35. 35
  36. 36. Variant 36
  37. 37. Build variants • Creating different versions of same application • free/paid • multi-apk • BuildVariant = Build Type + Product Flavor 37
  38. 38. Product Flavors • Defines a customized version of application build by the project • Free / Paid • Amazon / Play Store / blah store • Same type as defaultConfig 38
  39. 39. 39
  40. 40. 40
  41. 41. One more thing 41
  42. 42. gradle wrapper • Setup gradle automatically • $ANDROID_HOME/tools/templates/gradle/ wrapper/ 42
  43. 43. 43
  44. 44. summry • simple android project • sign release key • run proguard • build variants • wrapper 44
  45. 45. Android Studio integration 45
  46. 46. Android Studio integration BETA 46
  47. 47. Survival guide Rule #1 Always backup your project. 47
  48. 48. Survival guide Rule #2 Don’t import production code until 1.0 is out.. 48
  49. 49. 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
  50. 50. R U KIDDING ME ? 50
  51. 51. 51
  52. 52. Basic 52
  53. 53. 53
  54. 54. configurations 54
  55. 55. 55
  56. 56. import.. 56
  57. 57. import.. 57
  58. 58. import.. 58
  59. 59. import.. 59
  60. 60. Piece of cake 60
  61. 61. Dependency 61
  62. 62. project layout 62
  63. 63. configurations 63
  64. 64. ... errrrrr • Don’t recognize as library project • No typo checking, no function reference, no ... • But you can still build the project 64
  65. 65. duplicated name ? 65
  66. 66. try another way 66
  67. 67. errrrrrr 67
  68. 68. 68
  69. 69. Refine project layout 69
  70. 70. working configurations 70
  71. 71. tips • as simple as possible • library/xxx_lib • use ‘:’ instead of ‘/’ in path • ugly, but runs fine 71
  72. 72. Local repository 72
  73. 73. 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 73
  74. 74. project layout 74
  75. 75. root-build.gradle 75
  76. 76. library/build.gradle 76
  77. 77. project/build.gradle • archivesBaseName • version 77
  78. 78. app/build.gradle 78
  79. 79. How • deploy library • ./gradlew deploy • use local repository • ./gradlew as -PuseRepo 79
  80. 80. Tricks 80
  81. 81. rename apk 81
  82. 82. launch after install 82
  83. 83. move out apk 83
  84. 84. Refresh cache • --refresh-dependencies • stay up-to-date (?) http://www.gradle.org/docs/current/userguide/ dependency_management.html#sec:cache_command_line_options 84
  85. 85. Q & A 85
  86. 86. References • http://tools.android.com/tech-docs/new- build-system • Guide / Samples • http://www.gradle.org/documentation 86
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×