android development with gradle

Download Android development with Gradle

Post on 14-Jun-2015

621 views

Category:

Software

3 download

Embed Size (px)

DESCRIPTION

Speaker:

TRANSCRIPT

  • 1. Gradle for AndroidKenneth Kousen@kenkousenken.kousen@kousenit.com 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.

2. Contact InfoKen Kousenken.kousen@kousenit.com@kenkousenMaking Java Groovyhttp://manning.com/kousen 3. Upcoming BookGradle for AndroidO'ReillyPart of the Gradle series 4. Android Home PageDeveloper home pagehttp://developer.android.com 5. SDK Bundlehttps://developer.android.com/sdk/index.htmlEclipse + 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 Studiohttps://developer.android.com/sdk/installing/studio.htmlEarly Access Preview 11. Android Studiohttps://developer.android.com/sdk/installing/studio.htmlEarly Access PreviewBased on IntelliJ IDEA 12. Android Studiohttps://developer.android.com/sdk/installing/studio.htmlEarly Access PreviewBased on IntelliJ IDEAUses Gradle for builds 13. Android Studiohttps://developer.android.com/sdk/installing/studio.htmlEarly 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 android.app.ActivityFull 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 resourceshttps://developer.android.com/guide/topics/resources/providing-resources.htmlSpecially named subdirectoriesvaluesConfiguration qualifiersvalues-v11values-sw720dp-land 25. valueskeys and values layer of indirectionstrings.xml:Hello world! 26. Accessing resourcesXML compiled intoR.java: full of public inner classes (!)(Button) findViewById(R.id.hello_button) 27. BasicsAndroid plugin for GradleAdded via buildScriptLots of customization 28. Basicsbuildscript {repositories { mavenCentral() } // or jcenter()dependencies {classpath 'com.android.tools.build:gradle:0.12.2'}}apply plugin: 'com.android.application' 29. Properties in build.gradleandroid {versionCode versionName }or even in gradle.properties 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 Androidhttp://projects.spring.io/spring-android/RestTemplate classMap classes to JSON structure 49. ReferencesAndroid new build systemhttp://tools.android.com/tech-docs/new-build-systemhttp://tools.android.com/tech-docs/new-build-system/user-guideDeveloper's Guide section on Gradlehttps://developer.android.com/sdk/installing/studio-build.htmlAndroid Developers on G+https://plus.google.com/+AndroidDevelopers/posts 50. ReferencesXavier Ducrohet on G+https://plus.google.com/+XavierDucrohet/postsadt-dev on Google Groupshttps://groups.google.com/forum/#!forum/adt-dev 51. The Ultimate Android OSSpockTesting Shouldn'tData run onAndroid? 52. The Ultimate Android OS