Slide 1

Slide 1 text

9-10 novembre 2015

Slide 2

Slide 2 text

• Gradle build • Android performance matters • Ingredient for a healthy code base • Barcamp • Trending Android

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

1. Initialization Choose project(s) to build 2. Configuration Execute build.gradle Build task graph 3. Execution Execute task chain

Slide 5

Slide 5 text

Subject application: Google IO app • 28 libraries • 53149 method references

Slide 6

Slide 6 text

• Configuration on Demand • Gradle Daemon • Newer versions of gradle • JVM 1.8 instead of 1.6 • Avoid expensive things during configuration phase • Don’t use dynamic dependencies (x.y.+)

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Package cost : 1.297s Resource change cost: 0.939s Jave change cost 4.462s • dex : 3.766s • Javac : 0.876s

Slide 9

Slide 9 text

small project dev { multiDexEnabled true minSdkVersion 21 } 4.633 secs prod {} 6.599 secs Bigger prject dev { multiDexEnabled true minSdkVersion 21 } 4.416 secs prod { multiDexEnabled true minSdkVersion 15 } 20.703 secs

Slide 10

Slide 10 text

Goals of a gradle plugin: • Create a gradle task that performs a custom task • Inject this task into the android task graph • Parametrize this task regarding the needs of the project • Package it and share it

Slide 11

Slide 11 text

class MyCustomTask extends DefaultTask { @Input def String input; @Output def String output; @TaskAction def trigger() { // Do your stuff here } }

Slide 12

Slide 12 text

public class MyPlugin implements Plugin { @Override void apply(Project project) { project.afterEvaluate ({ def myTask = project.tasks.create("mytask", MyCustomTask ); myTask.input = "doStuff" def jarTask = project.tasks.findByName("jar") jarTask.dependsOn(myTask); } }) }

Slide 13

Slide 13 text

class MyTaskExtension { def String input = null; }

Slide 14

Slide 14 text

public class MyPlugin implements Plugin { @Override void apply(Project project) { project.extensions.create("myExtension", MyTaskExtension) project.afterEvaluate ({ // ... myTask.input = project.myExtension.input // ... } }) }

Slide 15

Slide 15 text

apply: "myPlugin" android { // ... } myExtension { input "doStuff" }

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

• Static analysis tools – checkstyle – … • Google Play Store publishing • Groovy library for git • Dex count • Sqlite Analyzer Plugin • ...

Slide 19

Slide 19 text

• Gradle performance: https://speakerdeck.com/madisp/squeezing- the-last-drop-of-performance-out-of-your-gradle-builds-droidcon- paris-2015 • Build your gradle plugin https://bit.ly/gradle-plugin-next-level • Improve android builds: https://speakerdeck.com/florianmski/level- up-your-android-build

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

• Networking is the main battery consumer – Less radio time means less data – Batching to minimize radio transmission – Prefetching by predicting what the user will do

Slide 22

Slide 22 text

• GC events eats your app framerate – Reduce images size – Use primitives instead of objects – Keep an eye on your memory with management tools (AllocationTracker, TraceView)

Slide 23

Slide 23 text

->

Slide 24

Slide 24 text

• Create your own scrolling container – Movement tracking – Inertia scrolling – Scrollbars drawing – Edge detection to get feedback

Slide 25

Slide 25 text

Performance Matter - Ran Nachmany, Google https://youtu.be/04igNM9IpwE?list=PLn7H9CUCuXAv_kAdS0rxL1_jdxXp FVb0r ViewGroups - François Blavoet, Deezer https://youtu.be/MSTG0JPOrYk?list=PLn7H9CUCuXAv_kAdS0rxL1_jdxX pFVb0r Advanced Scrolling - Cyril Mottier, Captain Train https://youtu.be/N3J4ZFiR_3Q?list=PLn7H9CUCuXAv_kAdS0rxL1_jdxX pFVb0r

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

DATA LAYER DOMAIN LAYER PRESENTER LAYER

Slide 29

Slide 29 text

Retrofit client DB client ArtistRepository • Shared preferences • ContentProvider • BDD

Slide 30

Slide 30 text

• Orchestrates the flow of data with use “cases” • Offers its services to presentation layer • Pure Java module • No Android UI dependencies • No dependency to external source (db,content provider, shared preferences…)

Slide 31

Slide 31 text

▸ public class Artist { String displayName; Date onTourUntil; String uri; String id; String url; String htmlUrl; String …; Object…; Object …; Object …; } public class ArtistViewModel { String name; boolean isOnTour; } VIEW MODEL PRESENTER VIEW

Slide 32

Slide 32 text

public interface SearchPresenter { void searchUser(String searchItem); void clickUser(ArtistViewModel artist); } public interface SearchView { void showProgress(); void hideProgress(); void showUser(List artistes); } VIEW MODEL PRESENTER VIEW

Slide 33

Slide 33 text

public class SearchFragment extends Fragment implements SearchView { private SearchPresenter searchPresenter; @Override public void showProgress() { //... } @Override public void hideProgress() { //... } @Override public void showUser(List users) { //... } }

Slide 34

Slide 34 text

DATA LAYER DOMAIN LAYER PRESENTER LAYER OBSERVABLE OBSERVABLE SUBSCRIBER

Slide 35

Slide 35 text

• Provides dependency: @Provides and @Module • Request dependency: @Inject • Link modules and injections: @Component • Implement the singleton pattern : @Singleton

Slide 36

Slide 36 text

APPLICATION MODULE ACTIVITY MODULE FRAGMENT MODULE Repository Domain Activity Activity component Application component Presenter Use case

Slide 37

Slide 37 text

DATA LAYER DOMAIN LAYER PRESENTER LAYER USER REPOSITORY SEARCH USED CASE SEARCH PRESENTER SEARCH FRAGMENT

Slide 38

Slide 38 text

DATA LAYER DOMAIN LAYER PRESENTER LAYER .JSON

Slide 39

Slide 39 text

• Choose an architecture and stick with it • Test while your code • Retrofit • Dagger 2 • Rx-java • Espresso • Junit

Slide 40

Slide 40 text

• Clean Architecture : https://www.youtube.com/watch?v=- oZswd1j5H0 • Slide https://speakerdeck.com/romainpiel/ingredients-for-a-healthy- codebase • Presentation Dagger 2 : https://www.youtube.com/watch?v=IkTST564lA4 • slide Dagger 2 https://speakerdeck.com/jeremiemartinez/dagger-2- back-to-basics

Slide 41

Slide 41 text

It’s a tool to : ▸ Enhance modularity ▸ Focus on business logic ▸ Reduce noise in the source code Occurs at compile time with byte code modification

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

• To minimize the code necessary to bind your logic and your view • Still in Beta • Support library API 7

Slide 46

Slide 46 text

Slide 47

Slide 47 text

public class User { public final String firstName; public final String lastName; public User (String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } }

Slide 48

Slide 48 text

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MainActivityBinding binding = MainActivityBinding.inflate(getLayoutInflater()); User user = new User("Test", "User"); binding.setUser(user); }

Slide 49

Slide 49 text

Le Data Binding sur Android - Guillaume Bernard, Koridev https://youtu.be/fG_93vUfm5s?list=PLn7H9CUCuXAv_kAdS0rxL1_jdxXpFV b0r Data Binding -- Write Apps Faster (Android Dev Summit 2015) https://youtu.be/NBbeQMOcnZ0

Slide 50

Slide 50 text

• Android Emulator • Gives control on hardware features : – Control the battery level – GPS Location – Network and call management $

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

• Jack & Jill • Kotlin • Eddystone

Slide 53

Slide 53 text

Java Android Compiler Kit Jack Intermediate Library Linker Goal is to improve incremental build More efficient to compile compared to javac + dex, but still experimental

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

The swift of Android ?

Slide 56

Slide 56 text

Kotlin is compiled to Java bytecode Possibility to use both java and Kotlin in the same project

Slide 57

Slide 57 text

Pros • Compile time detection of NPE with nullable type • Lambda • Type inference • Class extensions

Slide 58

Slide 58 text

Cons • Overhead of 924 KB for runtime • Still in beta • Will it be adopted by the community ?

Slide 59

Slide 59 text

Beacon • Autonomous • Cheap (15-20€) • Advertise data in a one way communication Eddystone Open beacon format

Slide 60

Slide 60 text

3 possible messages with Eddystone • UID – Beacon broadcast its unique identifier • URL – Beacon broadcast – Physical web – Short range and contactless QRCode • TLM (Telemetry) – Maintenance (battery level, …)

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Evolution inside the android build system https://drive.google.com/file/d/0B1CCib0JzAOJRXZSY0c1ckZTU0E Kotlin for Android https://www.youtube.com/watch?v=50lASllvG3Q Eddystone https://www.youtube.com/watch?v=HR3X5h9xdno

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

ANDROID STUDIO 2.0

Slide 65

Slide 65 text

USABILITY (GUI) GPS POINTS KML BATTERY PHONE CALL SMS ROTATION RESIZE DRAG-DROP FINGERPRINT