Slide 1

Slide 1 text

Building Android Applications 1

Slide 2

Slide 2 text

Building Java Applications 2

Slide 3

Slide 3 text

Building Java Applications javac -g Foo.java 3

Slide 4

Slide 4 text

“Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications.” Using Ant –ant.apache.org 4

Slide 5

Slide 5 text

“Maven can manage a project's build, reporting and documentation from a central piece of information.” Using Maven –maven.apache.org 5

Slide 6

Slide 6 text

“Gradle combines the power and flexibility of Ant with the dependency management and conventions of Maven into a more effective way to build.” Using Gradle –gradle.org 6

Slide 7

Slide 7 text

“Buck is a build system for Java and Android that encourages the creation of small, reusable modules consisting of code and resources.” Using Buck –facebook.github.io/buck/ 7

Slide 8

Slide 8 text

Building Android Applications 8

Slide 9

Slide 9 text

Creating Android Applications 9

Slide 10

Slide 10 text

Creating Android Applications android create project --target 25 --path . --package com.project --activity MainActivity 10

Slide 11

Slide 11 text

Creating Android Applications For both the apk and aar: - AndroidManifest.xml - classes.jar - res - R.java 11

Slide 12

Slide 12 text

Building Android Applications 12

Slide 13

Slide 13 text

13

Slide 14

Slide 14 text

Step 1: Generate Resource java code and packaged Resources aapt package -f -M ${manifest.file} -F ${packaged.resource.file} -I $ {path.to.android-jar.library} -S ${android-resource-directory} [-m -J $ {folder.to.output.the.R.java}] Step 2: Compile java source codes + R.java use javac Step 3: Convert classes to Dalvik bytecode dx.bat –dex –output=${output.dex.file} ${compiled.classes.directory} $ {jar files..} Step 4: Create unsigned APK apkbuilder ${output.apk.file} -u -z ${packagedresource.file} -f ${dex.file} 14

Slide 15

Slide 15 text

With Gradle buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } apply plugin: 'android' android { compileSdkVersion 19 buildToolsVersion "19.0.3" } 15

Slide 16

Slide 16 text

Gradle benefits • Integration with Android Studio • Simple, Declarative, Domain-specific Language - Groovy • A Single Build System • Product Flavors, Build Variants, and Build Type • Android Signing Configuration • Dependency Management • Multi-project Support • Binary Bundles for Libaries (.aar) • Full Incremental Builds • A Focus on Testing • Test Server API supports Hosted Testing - Integration with Jenkins-based build servers and services from AppThwack, TestDroid, and Manymo 16

Slide 17

Slide 17 text

Gradle bonuses • Android’s official build tool: after 1.0 though! • Gradle has frequent releases demonstrating significant feature development - The Gradle project has a six week release cycle and practices complete transparency for feature planning. On the other hand, Maven had two releases in 2012 and one release in 2013. Gradle has momentum, we're moving very quickly to expand support for other languages while Maven stands still • Gradle provides more natural support for multiple languages and platforms - Scala, Groovy, C/C+ +, and Android first class plugins. 17

Slide 18

Slide 18 text

Gradle drawbacks • No official support for Unit Testing: through plugins (Novoda, JakeWharton) • No support for debugging in testing • No maven archetypes 18

Slide 19

Slide 19 text

Gradle todos • run test coverage using emma (standard tests): • run test coverage using cobertura (robolectric) • run test coverage using jacoco (both tests): • play uiautomator tests • play monkey runner tests 19

Slide 20

Slide 20 text

Gradle features 20

Slide 21

Slide 21 text

Wrapper - No need to have Gradle installed - Everyone builds with the same version task wrapper(type: Wrapper) { gradleVersion = '1.11' } 21

Slide 22

Slide 22 text

Consistency in the tools buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } android { buildToolsVersion "19.0.3" } 22

Slide 23

Slide 23 text

Flexible android { sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = [‘src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } androidTest.setRoot('tests') } } // NOTE: several srcDirs allowed! 23

Slide 24

Slide 24 text

Tasks • assemble • check • build • clean 24

Slide 25

Slide 25 text

Tasks • assembleDebug • checkDebug • buildDebug • cleanDebug 25

Slide 26

Slide 26 text

Tests • check • lint • connectedCheck • connectedAndroidTest • connectedUiAutomatorTest (not implemented yet) • deviceCheck • This depends on tasks created when other plugins implement test extension points. 26

Slide 27

Slide 27 text

Dependencies dependencies { compile project(‘:libraries:NetworkStack') compile files('libs/crittercism_v3_0_8_sdkonly.jar') compile ‘com.actionbarsherlock:actionbarsherlock:4.4.0@aar’ internalReleaseCompile ‘net.hockeyapp.android:HockeySDK:3.0.1' testCompile 'org.robolectric:robolectric:2.3-SNAPSHOT' androidTestCompile ‘com.google.guava:guava:11.0.2' } 27

Slide 28

Slide 28 text

Build Variants Build Type + Product Flavour - assembleReleaseFlavour - assembleDebugFlavour 28

Slide 29

Slide 29 text

Testing Build Variants Build Type + Product Flavour - assembleReleaseFlavourTest - assembleDebugFlavourTest 29

Slide 30

Slide 30 text

Configurability • versionCode • versionName • minSdkVersion • targetSdkVersion • packageName • TestPackageName • testInstrumentationRunner • signingConfig • proguardFile • proguardFiles 30

Slide 31

Slide 31 text

BuildConfig release { buildConfigField "String", “API”, “api/v2.2/“ buildConfigField "boolean", "RELEASE", "true" } 31

Slide 32

Slide 32 text

Source Compatibility 1.7 android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } } 32

Slide 33

Slide 33 text

References • developer.android.com/ • tools.android.com/ • gradle.org • maven.apache.org/ • ant.apache.org • facebook.github.io/buck/ • asantoso.wordpress.com/2009/09/15/how-to-build-android- application-package-apk-from-the-command-line-using-the-sdk- tools-continuously-integrated-using-cruisecontrol/ 33

Slide 34

Slide 34 text

Questions? “Wer nicht fragt, bleibt dumm” 34

Slide 35

Slide 35 text

Thanks! Hugo Doménech Juárez @hudomju 35