Slide 1

Slide 1 text

安桌椅⼯工作室攻略 shakalaca @ GDG

Slide 2

Slide 2 text

Log.i(“Shaka”, “01134”) • Co-organizer @ GDG Taipei • Consultant @ SleepNOVA, Inc. • CTO @ SmarTapper Co., Ltd. 2 http://about.me/shakalaca

Slide 3

Slide 3 text

Outline • Introduction • interface / keymap / plugin • Android tools • ddms / wizard / resource editor • Gradle plugin • 101 • migration from eclipse project 3

Slide 4

Slide 4 text

Introduction

Slide 5

Slide 5 text

History • 2012/11/13 ADT Bundle • 2013/05/23 Preview released (0.1.1) • 2014/06/27 Beta released (0.8.0) • 2014/12/08 1.0 released 5

Slide 6

Slide 6 text

The official Android IDE • Based on IntelliJ IDEA • Flexible Gradle-based build system • Build variants and multiple apk file generation • Code templates to help you build common app features • Rich layout editor with support for drag and drop theme editing • Lint tools to catch performance, usability, version compatibility, and other problems • ProGuard and app-signing capabilities • Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud Messaging and App Engine 6 http://developer.android.com/tools/studio/index.html

Slide 7

Slide 7 text

7

Slide 8

Slide 8 text

8

Slide 9

Slide 9 text

9

Slide 10

Slide 10 text

10

Slide 11

Slide 11 text

11

Slide 12

Slide 12 text

12

Slide 13

Slide 13 text

https://developer.android.com/sdk/installing/studio-tips.html Programming key commands 13

Slide 14

Slide 14 text

14 • Column selection • CMD + Shift + 8 • Duplicate line • CMD + D (Mac) • Ctrl + D (Windows/Linux) • Expand shrink selection • Alt + UP or DOWN (Mac) • Ctrl + W or Shift + W (Windows/Linux) Programming key commands

Slide 15

Slide 15 text

15 • Override methods • Ctrl + O • Implement methods • Ctrl + I • Rename • Shift + F6 • Extract method • CMD + Alt + M (Mac) , Ctrl + Alt + M (Windows/Linux) • Extract parameter • CMD + Alt + P (Mac), Ctrl + Alt + P (Windows/Linux) Programming key commands

Slide 16

Slide 16 text

https://developer.android.com/sdk/installing/studio-tips.html Editor key commands 16

Slide 17

Slide 17 text

17 • Recent files • CMD + E (Mac) • Ctrl + E (Windows/Linux) • The switcher • Ctrl + Tab • Close other tabs • Hold Alt when hit ‘x’ on tab Editor key commands

Slide 18

Slide 18 text

18

Slide 19

Slide 19 text

Help -> Productivity Guide 19

Slide 20

Slide 20 text

20

Slide 21

Slide 21 text

Android Tools

Slide 22

Slide 22 text

22

Slide 23

Slide 23 text

23

Slide 24

Slide 24 text

24

Slide 25

Slide 25 text

25

Slide 26

Slide 26 text

26

Slide 27

Slide 27 text

27

Slide 28

Slide 28 text

28

Slide 29

Slide 29 text

29

Slide 30

Slide 30 text

30

Slide 31

Slide 31 text

Do not hard coding • in xml file • xmlns:tools=“http://schemas.android.com/tools" • Add theme/layout/default value in layout editor • tools:context • tools:layout • tools:listitem / listheader / listfooter • android:xxx attributes 31 http://tools.android.com/tech-docs/tools-attributes

Slide 32

Slide 32 text

Do not hard coding • in xml file • xmlns:tools=“http://schemas.android.com/tools" • Add theme/layout/default value in layout editor • tools:context • tools:layout • tools:listitem / listheader / listfooter • android:xxx attributes 32 http://tools.android.com/tech-docs/tools-attributes

Slide 33

Slide 33 text

Do not hard coding • in xml file • xmlns:tools=“http://schemas.android.com/tools" • Add theme/layout/default value in layout editor • tools:context • tools:layout • tools:listitem / listheader / listfooter • android:xxx attributes 33 http://tools.android.com/tech-docs/tools-attributes

Slide 34

Slide 34 text

Do not hard coding • in xml file • xmlns:tools=“http://schemas.android.com/tools" • Add theme/layout/default value in layout editor • tools:context • tools:layout • tools:listitem / listheader / listfooter • android:xxx attributes 34 http://tools.android.com/tech-docs/tools-attributes

Slide 35

Slide 35 text

Do not hard coding • in xml file • xmlns:tools=“http://schemas.android.com/tools" • Add theme/layout/default value in layout editor • tools:context • tools:layout • tools:listitem / listheader / listfooter • android:xxx attributes 35 http://tools.android.com/tech-docs/tools-attributes

Slide 36

Slide 36 text

Do not hard coding • in xml file • xmlns:tools=“http://schemas.android.com/tools" • Add theme/layout/default value in layout editor • tools:context • tools:layout • tools:listitem / listheader / listfooter • android:xxx attributes 36 http://tools.android.com/tech-docs/tools-attributes

Slide 37

Slide 37 text

Other features .. • Resources preview in source code editor • color / icon / string .. • Powerful autocomplete • use with Tab key • Build variants 37

Slide 38

Slide 38 text

Gradle plugin

Slide 39

Slide 39 text

Inside the project • project • modules • build files • build files • plugin • dependencies • tasks 39

Slide 40

Slide 40 text

Inside the project • project • modules • build files • build files • plugin • dependencies • tasks 40

Slide 41

Slide 41 text

Inside the project • project • modules • build files • build files • plugin • dependencies • tasks 41

Slide 42

Slide 42 text

Modules • android application module • android library module • app engine module • java module 42

Slide 43

Slide 43 text

Build configurations • variants • manifest • signing • proguard • testing 43

Slide 44

Slide 44 text

Basic project layout / • build.gradle • settings.gradle • app/ • build.grade • src/main/java … • library1/ • build.gradle • src/main/java … • library2/ • build.gradle • src/main/java … 44

Slide 45

Slide 45 text

Basic project layout / • build.gradle • settings.gradle • app/ • build.grade • src/main/java … • library1/ • build.gradle • src/main/java … • library2/ • build.gradle • src/main/java … 45

Slide 46

Slide 46 text

Basic project layout / • build.gradle • settings.gradle • app/ • build.grade • src/main/java … • library1/ • build.gradle • src/main/java … • library2/ • build.gradle • src/main/java … 46

Slide 47

Slide 47 text

Project build file /build.gradle 47 buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.0.0' } }

Slide 48

Slide 48 text

Project build file /settings.gradle 48 include ':app' include ':library1' include ':library2' project(':library1').projectDir = new File('/other/places/on/the/computer')

Slide 49

Slide 49 text

Application module /app/build.gradle 49 apply plugin: 'com.android.application' dependencies { compile 'com.android.support:support-v4:21.0.3' compile project(‘:library1') compile project(':library2') compile fileTree(dir: 'libs', include: ['*.jar']) } android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { minSdkVersion 14 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { debug { debuggable true versionNameSuffix "-debug" } release { shrinkResources true minifyEnabled true proguardFile getDefaultProguardFile('proguard-android.txt') } } }

Slide 50

Slide 50 text

Dependencies • module dependencies • compile project(‘:module’) • local dependencies • compile files(‘libs/core.lib’) • compile fileTree(dir: 'libs', include: [‘*.jar’]) • remote dependencies • compile 'com.android.support:support-v4:21.0.3' • 50

Slide 51

Slide 51 text

Dependencies • module dependencies • compile project(‘:module’) • local dependencies • compile files(‘libs/core.lib’) • compile fileTree(dir: 'libs', include: [‘*.jar’]) • remote dependencies • compile 'com.android.support:support-v4:21.0.3' • 51

Slide 52

Slide 52 text

Dependencies • module dependencies • compile project(‘:module’) • local dependencies • compile files(‘libs/core.lib’) • compile fileTree(dir: 'libs', include: [‘*.jar’]) • remote dependencies • compile 'com.android.support:support-v4:21.0.3' • 52

Slide 53

Slide 53 text

Dependencies • module dependencies • compile project(‘:module’) • local dependencies • compile files(‘libs/core.lib’) • compile fileTree(dir: 'libs', include: [‘*.jar’]) • remote dependencies • compile 'com.android.support:support-v4:21.0.3' • 53

Slide 54

Slide 54 text

Repo by google • com.android.support:support-v4:21.0.3 • com.android.support:support-v13:21.0.3 • com.android.support:appcompat-v7:21.0.3 • com.android.support:cardview-v7:21.0.3 • com.android.support:gridlayout-v7:21.0.3 • com.android.support:leanback-v17:21.0.3 • com.android.support:mediarouter-v7:21.0.3 • com.android.support:palette-v7:21.0.3 • com.android.support:recyclerview-v7:21.0.3 • com.android.support:support-annotations:21.0.3 • com.google.android.gms:play-services:6.5.87 54 http://gradleplease.appspot.com/

Slide 55

Slide 55 text

Library module /library1/build.gradle 55 apply plugin: 'com.android.library' dependencies { compile 'com.google.android.gms:play-services:6.5.87' } android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { minSdkVersion 14 targetSdkVersion 21 } }

Slide 56

Slide 56 text

Tasks • gradle tasks • display all tasks runnable from root project • gradle assemble • build the project • gradle check • run checks and tests • gradle build • runs both assemble and check • gradle clean • performs the clean 56

Slide 57

Slide 57 text

Variant • productFlavors + buildTypes 57 android { productFlavors { full { applicationId "com.corner23.android.full" } demo { applicationId "com.corner23.android.demo" } } buildTypes { debug { versionNameSuffix "-debug" } release { minifyEnabled true shrinkResources true } } }

Slide 58

Slide 58 text

Variant • productFlavors + buildTypes • fullDebug • fullRelease • demoDebug • demoRelease 58 android { productFlavors { full { applicationId "com.corner23.android.full" } demo { applicationId "com.corner23.android.demo" } } buildTypes { debug { versionNameSuffix "-debug" } release { minifyEnabled true shrinkResources true } } }

Slide 59

Slide 59 text

Variant • additional source directory for each flavor • app/src/demo/java • app/src/demo/res • .. or build type • app/src/debug/java • app/src/debug/res 59

Slide 60

Slide 60 text

Building variant • gradle assemble fullRelease • gradle assemble demoDebug 60

Slide 61

Slide 61 text

Build in Android Studio 61

Slide 62

Slide 62 text

Sign configuration 62 android { signingConfigs { release { storeFile file("other.keystore") storePassword "android" keyAlias "androiddebugkey" keyPassword "android" } myConfig { storeFile file("other2.keystore") storePassword "android2" keyAlias "androiddebugkey2" keyPassword "android2" } } buildTypes { release { signingConfig signingConfigs.release } foo { signingConfig signingConfigs.myConfig } } }

Slide 63

Slide 63 text

Migration from Eclipse

Slide 64

Slide 64 text

64

Slide 65

Slide 65 text

65

Slide 66

Slide 66 text

66

Slide 67

Slide 67 text

67

Slide 68

Slide 68 text

68

Slide 69

Slide 69 text

69

Slide 70

Slide 70 text

70

Slide 71

Slide 71 text

71

Slide 72

Slide 72 text

72

Slide 73

Slide 73 text

Tips for migration • organise your project layout 73

Slide 74

Slide 74 text

Tips for migration • organise your project layout • organise your module layout 74

Slide 75

Slide 75 text

Tips for migration • organise your project layout • organise your module layout 75 android { sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } } }

Slide 76

Slide 76 text

Tips for migration • replace ‘*@@aar’ with correct library module • use local module • create build.gradle under library module • add library project in settings.gradle • modify build.gradle under app (library) module • use remote module • http://gradleplease.appspot.com/ • check remote dependencies 76

Slide 77

Slide 77 text

Tips for migration • replace ‘*@@aar’ with correct library module • use local module • create build.gradle under library module • add library project in settings.gradle • modify build.gradle under app (library) module • use remote module • http://gradleplease.appspot.com/ • check remote dependencies 77

Slide 78

Slide 78 text

Tips for migration • replace ‘*@@aar’ with correct library module • use local module • create build.gradle under library module • add library project in settings.gradle • modify build.gradle under app (library) module • use remote module • http://gradleplease.appspot.com/ • check remote dependencies 78

Slide 79

Slide 79 text

Tips for migration • replace ‘*@@aar’ with correct library module • use local module • create build.gradle under library module • add library project in settings.gradle • modify build.gradle under app (library) module • use remote module • http://gradleplease.appspot.com/ • check remote dependencies 79

Slide 80

Slide 80 text

Tips for migration • import project to a new directory, see if everything is all right • modify module settings, see what changed inside the build.gradle • use the imported project as reference, create the build files from scratch for your original project 80

Slide 81

Slide 81 text

Tips for migration • import project to a new directory, see if everything is all right • modify module settings, see what changed inside the build.gradle • use the imported project as reference, create the build files from scratch for your original project 81

Slide 82

Slide 82 text

Tips for migration • import project to a new directory, see if everything is all right • modify module settings, see what changed inside the build.gradle • use the imported project as reference, create the build files from scratch for your original project 82

Slide 83

Slide 83 text

Tips for migration • import project to a new directory, see if everything is all right • modify module settings, see what changed inside the build.gradle • use the imported project as reference, create the build files from scratch for your original project 83

Slide 84

Slide 84 text

Shared library • define path_to_share_library in ~/.gradle/ gradle.properties or / gradle.properties • project(‘:xxx’).projectDir = new File(path_to_share_library) • dependencies in shared library should be defined in project’s settings.gradle also. 84

Slide 85

Slide 85 text

Q & A

Slide 86

Slide 86 text

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 • http://stackoverflow.com/questions/tagged/android-studio 86

Slide 87

Slide 87 text

Or follow me @ • G+ • http://google.com/profiles/shakalaca • Blog • http://23pin.logdown.com • Github • https://github.com/shakalaca/learning_gradle_android • Taipei GDG (G+ Community) • https://plus.google.com/communities/100566773212437391191 87