Slide 1

Slide 1 text

A Brain-Friendly Guide Android App Dev Tools Head First MOPCON shakalaca

Slide 2

Slide 2 text

Hello ! I’m Shaka • CTO @ SmarTapper Co., Ltd. • Consultant @ SleepNOVA, Inc. http:/ /about.me/shakalaca

Slide 3

Slide 3 text

Today’s topic • Genymotion (101 session) • w/ demo • Gradle (201 session) • w/ sample scripts • Android Studio (201 session)

Slide 4

Slide 4 text

Genymotion

Slide 5

Slide 5 text

Myth : App development on Android is FREE (or cheaper) than iOS

Slide 6

Slide 6 text

Really ? • Don’t have to buy a Mac
 ... you’ll buy one eventually (look at me) • There’s an emulator
 ... you really use it ? • Android phone is way cheaper than iPhone !
 ... you mean those in the next page ?

Slide 7

Slide 7 text

http://goo.gl/tt8Rp

Slide 8

Slide 8 text

There’s no such thing as free lunch ..

Slide 9

Slide 9 text

Problems with emulator • No play services (sort of) • No camera • “telnet localhost 5554” doesn’t make sense • f5g really slow in arm based emulator

Slide 10

Slide 10 text

Survival guide ! • Intel x86 Emulator Accelerator • Snapshot or Host GPU

Slide 11

Slide 11 text

Buy real phone(s) ! • For platform/screen specific issues • Nexus is enough ... • ... I’m not sure

Slide 12

Slide 12 text

Developers’ pain https://www.youtube.com/watch?v=cOUK0JZvbwI

Slide 13

Slide 13 text

It’s a bird.. It’s a plane.. It’s Genymotion ! http:/ /www.genymotion.com

Slide 14

Slide 14 text

Is it the one ? • Android x86 emulator based on AndroVM open source project • http:/ /androvm.org/ • (In some case) faster than SDK emulator • Multi-platform • IDE plugins

Slide 15

Slide 15 text

Good for .. • Test applications • Fast & cable free • Screencast • Use your favorite software (for me: QuickTime for OS X)

Slide 16

Slide 16 text

And gamers love it .. https://www.google.com.tw/search?q=神魔之塔+genymotion

Slide 17

Slide 17 text

Features (HW) • Camera • GPS • Battery • Speaker / Microphone • Rotation • Physical keys

Slide 18

Slide 18 text

Features (SW) • API 16 & 17, 18 in preview • Play store (service) • Root access • OpenGL • Virtual keys • Full screen (F11)

Slide 19

Slide 19 text

Resolution • 1280x800 • 720x1080 • 1080x1920 • 480x800 • 1024x600 • Customizable

Slide 20

Slide 20 text

Screen size • Nexus One (3.7”) • Nexus S (4”) • Galaxy Nexus (4.65”) • Nexus 7 (7”) • Galaxy S4/HTC One/Xperia Z (5”) • WSVGA Tablet (7”) • WXGA Tablet (10.1”)

Slide 21

Slide 21 text

Demo time !

Slide 22

Slide 22 text

Tips !

Slide 23

Slide 23 text

Control • Buttons • Rotation: ctrl + F11 • Full screen: F11 • Gestures • Zoom: ctrl + mouse left/right • Tile: ctrl + mouse up/down • Rotate: ctrl + shift + mouse left/right

Slide 24

Slide 24 text

Launch from CLI • VBoxManage list vms • "Galaxy Nexus - 4.2.2 - with Google Apps - API 17 - 720x1280" {fbbd7f3e-188d-4a9b-8cdc-5b70c1554f5b} • player --vm-name • /Application/Genymotion.app/Contents/MacOS/player --vm-name "Galaxy Nexus - 4.2.2 - with Google Apps - API 17 - 720x1280"

Slide 25

Slide 25 text

genyshell • Example: Setup gps to somewhere in Taipei • Content of file “gps_loc” • gps setstatus enabled • gps setlatitude 25.03 • gps setlongitude 121.54 • Command to apply configurations • genyshell -f gps_loc

Slide 26

Slide 26 text

Change resolution • Dummy way: Set in menu before launch • Geek way: Set through adb • adb shell am display-size 800x480 • adb shell am display-density 240 • adb shell am display-size reset • For 4.3+ • adb shell wm size 800x480 • adb shell wm density 240

Slide 27

Slide 27 text

Use my scripts :p • adb root • https:/ /gist.github.com/shakalaca/6716635 • screenshot • https:/ /gist.github.com/shakalaca/6822570 • migration tool • https:/ /github.com/shakalaca/ GenymotionVMMigrationTool

Slide 28

Slide 28 text

Gradle enabled android project

Slide 29

Slide 29 text

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/

Slide 30

Slide 30 text

.. short version An open source build system that combines the power of Ant & Maven but easy to use

Slide 31

Slide 31 text

Why (google wants to change the build system to) gradle ? • My guess.. • Simplify and unify project dependency management in IDE & CLI • Think about Eclipse & ant (ci server) • Android Studio is coming ! BETA

Slide 32

Slide 32 text

Should I use it ? • For small project • Easy to convert • For large project • Worth trying if it can simplify the configurations (dependency) • For project with variants • Time for better management tool

Slide 33

Slide 33 text

Will it blow up my projects ? It’s 2013 now, you should have SCM … right ?

Slide 34

Slide 34 text

How gradle works ? • Lifecycle • Initialization • Configuration • Execution • Build scripts • build.gradle • settings.gradle (optional) • gradle.properties (optional) http://www.gradle.org/docs/current/userguide/build_lifecycle.html

Slide 35

Slide 35 text

Command • gradle • tasks • clean • assemble • assembleRelease • assembleDebug • aR / asD

Slide 36

Slide 36 text

Android integration • gradle android plugin • http:/ /tools.android.com/tech-docs/new- build-system/ • output • /build/apk/

Slide 37

Slide 37 text

Step by step tutorial • Basic • Dependency • Sign / Proguard • Variant

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Eclipse project

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Dependencies • compile files(‘libs/android-support-v4.jar’) • compile fileTree(dir: ‘libs’, include: ‘*.jar’) • compile ‘com.android.support:support- v4:18.0.0’

Slide 42

Slide 42 text

Android 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.65

Slide 43

Slide 43 text

defaultConfig • versionCode • versionName • minSdkVersion • targetSdkVersion • packageName • signingConfig • proguardFile • proguardFiles • testPackageName • testInstrumentation Runner

Slide 44

Slide 44 text

Happy building • Put build.gradle in project directory • Build: gradle assemble • build/apk/ • Install: gradle installDebug or gradle installRelease

Slide 45

Slide 45 text

Step by step tutorial • Basic • Dependency • Sign / Proguard • Variant

Slide 46

Slide 46 text

Project structure

Slide 47

Slide 47 text

app

Slide 48

Slide 48 text

include library project

Slide 49

Slide 49 text

ActionBarSherlock

Slide 50

Slide 50 text

Happy building • Put build.gradle & settings.gradle in app project directory • Put build.gradle in library project directory • Build: gradle assemble • build/apk/

Slide 51

Slide 51 text

settings.gradle • Used in multi-project hierarchy • Define projects to be used in build

Slide 52

Slide 52 text

settings.gradle

Slide 53

Slide 53 text

er.. no direct way ?

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Known issue • Library project is always “release” build • define your own debug flags.. • in AndroidManifest.xml

Slide 57

Slide 57 text

Step by step tutorial • Basic • Dependency • Sign / Proguard • Variant

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

Build types • default 2 types: debug & release • for debugging & signing

Slide 60

Slide 60 text

Build types • debuggable • jniDebugBuild • renderscriptDebugBuild • renderscriptOptimLevel • packageNameSuffix • versionNameSuffix • signingConfig • zipAlign • runProguard • proguardFile • proguardFiles

Slide 61

Slide 61 text

Tips • Save your gradle.properties in ~/.gradle/ • .. If you work alone

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

Step by step tutorial • Basic • Dependency • Sign / Proguard • Variant

Slide 64

Slide 64 text

Build variant • Creating different versions of same application • free/paid • multi-apk • Build Variant = Build Type + Product Flavor

Slide 65

Slide 65 text

Product flavor • Defines a customised version of application build by the project • Free / Paid • Amazon / Play Store / blah store • Same type as defaultConfig

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

Build • gradle assemblePaid • gradle aPD / gradle aPR • gradle assembleFree • gradle aFD / gradle aFR

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

One more thing..

Slide 70

Slide 70 text

gradle wrapper • Setup gradle automatically • $ANDROID_HOME/tools/templates/gradle/ wrapper/ • for gradle 1.7+ • execute “gradle wrapper”

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

Compatible with older version of gradle • change gradleVersion • run ‘./gradlew wrapper’

Slide 73

Slide 73 text

Summary • Simple android project • Sign release key • Run proguard • Build variants • Wrapper

Slide 74

Slide 74 text

All samples are here http:/ /github.com/shakalaca/ learning_gradle_android

Slide 75

Slide 75 text

Maven repository

Slide 76

Slide 76 text

Why & How ? • Time is money • 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

Slide 77

Slide 77 text

Project layout

Slide 78

Slide 78 text

root-build.gradle

Slide 79

Slide 79 text

library/build.gradle

Slide 80

Slide 80 text

project/build.gradle • archivesBaseName • version

Slide 81

Slide 81 text

app/build.gradle

Slide 82

Slide 82 text

How • deploy library • ./gradlew deploy • use local repository • ./gradlew as -PuseRepo

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

Performance boost • in ~/.gradle/gradle.properties • org.gradle.daemon=true • org.gradle.parallel=true (be careful) • stop the daemon • gradle --stop

Slide 85

Slide 85 text

Refresh cache • --refresh-dependencies • stay up-to-date (?) http://www.gradle.org/docs/current/userguide/ dependency_management.html#sec:cache_command_line_options

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 • Tool • http:/ /gradleplease.appspot.com/

Slide 87

Slide 87 text

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

Slide 88

Slide 88 text

Q & A

Slide 89

Slide 89 text

Bonus !

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

Remove jars in output apk

Slide 92

Slide 92 text

Remove jars in certain build type

Slide 93

Slide 93 text

Launch after install

Slide 94

Slide 94 text

Move out and rename output apk files • android.applicationVariant.all { variant ->
 variant.assemble.doLast { do_the_magic } 
 } • variant.zipAlign • true: extra variant.outputFile • false: variant.packageApplication.outputFile • https:/ /gist.github.com/shakalaca/6422811

Slide 95

Slide 95 text

NDK support • https:/ /gist.github.com/pboos/5802233#file- ndk-build-gradle

Slide 96

Slide 96 text

For other issues .. • Google Maps Android API v2 gradle integration • Different resources for build types • http:/ /23pin.logdown.com/posts/144771-google- maps-android-api-v2-gradle-integration • Gradle and GCM project integration • Difference in AndroidManifest.xml • http:/ /23pin.logdown.com/posts/144770-gradle-and- gcm-project-integration