android development with gradle

Download Android development with Gradle

Post on 14-Jun-2015




3 download

Embed Size (px)




  • 1. Gradle for AndroidKenneth 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.

2. Contact InfoKen Java Groovy 3. Upcoming BookGradle for AndroidO'ReillyPart of the Gradle series 4. Android Home PageDeveloper home page 5. SDK Bundle + ADT toolsAndroid SDK toolsAndroid Platform toolsLatest Android SDK + emulator 6. Eclipse ADTDoes not support Gradle directlyGenerate gradle build filemaps default structure to standard layoutno longer needed can import project 7. GradleWhy Gradle? 8. GradleBecause reasons 9. GradleBecause reasons(This is a Groovy conference.You already know why) 10. Android Studio Access Preview 11. Android Studio Access PreviewBased on IntelliJ IDEA 12. Android Studio Access PreviewBased on IntelliJ IDEAUses Gradle for builds 13. Android Studio Access PreviewBased on IntelliJ IDEAUses Gradle for buildsBeta some bugs andunsupported features, butpretty solid so far 14. Android StudioActually, latest version* is very useful*As of SpringOne2GX 2014, version 0.8.9 15. Creating an applicationMust select unique package namecom.example.myapp(com.example reserved for samples)Used in Google Play store 16. Creating an applicationChoose min SDK levelChoose target SDK level 17. ManifestAndroidManifest.xml // old style... 18. Change for GradleNow minSdkVersion, targetSdkVersionset in build.gradleOverrides AndroidManifest.xml,so best to leave it out 19. ManifestAll activities must be declaredList permissionsIntent filtersServicesContent providers 20. ActivitiesRepresents a screenExtend of callback methods 21. ActivitiesEach activity has an XML layoutactivity_main.xmlactivity_welcome.xmlXML tags with many attributes 22. ActivitiesCallback methods:onCreate, onDestroyonStart, onStoponPause, onResume many others 23. resResources folder contains subfoldersdrawablelayoutmenuvalues... 24. Providing resources named subdirectoriesvaluesConfiguration qualifiersvalues-v11values-sw720dp-land 25. valueskeys and values layer of indirectionstrings.xml:Hello world! 26. Accessing resourcesXML compiled full of public inner classes (!)(Button) findViewById( 27. BasicsAndroid plugin for GradleAdded via buildScriptLots of customization 28. Basicsbuildscript {repositories { mavenCentral() } // or jcenter()dependencies {classpath ''}}apply plugin: '' 29. Properties in build.gradleandroid {versionCode versionName }or even in 30. Multiproject BuildsBy default, apps in AS are multiproject buildsbuild.gradlesettings.gradleCan add additional libraries, other modules,and more 31. Build TypesTwo default build types:debugrelease 32. Configuring Build TypesUse buildTypes section of build.gradlebuildTypes {release { }debug { }}Can also add custom build types that way 33. Configuring Build TypesEach build type defines a source setsrc/main/ src/debug/ src/release/ src/androidTest/ (discussed below) 34. Configuring Build TypesResources in build type source setsreplace their counterparts in mainJava classes conflict, howeverDefine class in each, or just in main 35. Generating a ReleaseCan't assemble a release untilyou can sign it 36. Signing Your AppUse Java's keytool to generate cert 37. Signing Your AppAdd signing block to build.gradlesigningConfigs {release {storeFile file('ICNDB.keystore')keyAlias 'ICNDB'storePassword 'gradle_rules'keyPassword 'carlos_ray_aka_chuck'}} 38. Signing Your AppPasswords don't have to be in build file- Can use system properties- Can prompt user- Can use external filesSee docs for suggestions 39. Signing Your AppAdd signingConfig to build type configbuildTypes {release {// signingConfig signingConfigs.release}} 40. Signing Your AppThe signingReport task shows details 41. Signing Your AppInvoke assembleRelease taskResulting apk in build/outputs/apk folder 42. TestingUse androidTest source setsrc/androidTest/java 43. TestingUse androidTest source setsrc/androidTest/javacompileAndroidTest dependencies 44. TestingUse androidTest source setsrc/androidTest/javaandroidTestCompile dependenciesRun connectedCheck task 45. Flavors and VariantsbuildTypesdebug, releaseflavors different versions of same appfree, paid 46. Flavors and VariantsEach flavor generates an apkVariants combine buildTypes and flavorsfree+debug, free+release,paid+debug, paid+release 47. Multiple FlavorsSee flavors sampleSee basicMultiFlavors sampleflavorDimensions productFlavors { } 48. RESTInstead of JSON and Apache HTTP:Spring for Android classMap classes to JSON structure 49. ReferencesAndroid new build system's Guide section on Gradle Developers on G+ 50. ReferencesXavier Ducrohet on G+ on Google Groups!forum/adt-dev 51. The Ultimate Android OSSpockTesting Shouldn'tData run onAndroid? 52. The Ultimate Android OS