SlideShare uma empresa Scribd logo
1 de 33
Android Technical Lead
Applause Inc.
Przemek Jakubczyk
pjakubczyk
@pjakubczyk
1
A guide to make crashproof libraries
It's always your fault
2
Background
At Applause I am responsible for quality
Applause SDK is crash and bug reporting library
shipped to over 1000 customers
SDK works with apps around the world
3
History
Joined 2 years ago to project with no QA
Today ~1800 unit tests covering 3k methods
82% lines covered
Last major problem was support for Marshmallow
4
Other than that over 6 months of no customer complain
How your SDK should look like
Be universal
Work in every provided configuration
Be robust
Work in any environment
Be defensive
5
GRADLE
6
Just use it.
7
because it’s the base for Android build system
Gradle
use simple tricks to protect your
styling
8
android {
resourcePrefix 'applause_'
}
or pass custom values to source
code via DSL
defaultConfig {
resValue "string",
"applause_library_version”,
"$version"
}
Gradle
easier integration with your Groovy
scripts
for example create own distribution
task
task buildAll (
dependsOn: 'assembleRelease',
type: Copy) {
from “build/outputs/”
into “another_path”
}
9
Gradle
10
Not possible :)
Often heard question. How to pass arguments to tasks?
Create new task for each configuration.
Gradle
11
task buildAll (
dependsOn:
["assembleFreeRelease,
assemblePaidRelease"]
)
Gradle
With great power comes great responsibility
Mind the execution time
Common trick is to use VCS for versionNumber, each run takes time
If possible (please!) don’t make http calls - huge delay, timeout, offline?
Use only in tasks, not in build script evaluation.
12
Java
13
Java
catching Exception doesn’t solve problem
often hides real cause
tempting but dangerous
14
try {
network.getClients();
} catch (Exception e) {
// handle exception
}
Java
Null Object Pattern
instead constantly checking for not null
value
15
public interface Api {
void post(String action);
Api NULL = new Api() {
void post(String action){}
};
}
getApi().post(“Works”)
Java
NPE
Null Pointer Exception is the most popular
exception thrown in runtime.
NullObject pattern partially solves the problem.
Use empty objects, collections etc;
16
List<User> fetchUsers(){
try {
return api.getAllUsers();
} catch (IOException e){
return new
ArrayList<Users>();
}
}
Java
Usually library is started by one static method
… and next versions provide more functionality
Init interface becomes complex
17
Java
public static void start(
String baseUrl,
String defaultUser,
String defaultPassword,
boolean cacheRequests,
boolean forceHttps,
int timeout
)
18
Conf conf = new Conf.Builder()
.withUrl(“http://api.github.com”)
.withUser(“pjakubczyk”)
.withPassword(“droidcon2015Krakow”)
.withCache(false)
.withHttps(true)
.withTimeout(15)
.build();
Library.start(conf);
Java
Builder pattern organize configuration
Easier data validation
Pass only parameters user wants
Handling default values
19
Java
methods, fields, constructors
default, private, protected, public
Might sound a bit controversial
I use default or public
A.Reflection
B.Allow developers to override, it’s their responsibility 20
Android
21
Android
View.inEditMode() determines if view is drawn in Android Studio
Usually to disable other components
Let’s invert the usage
22
23
public void onFinishInflate(){
TextView title = findViewById(R.id.title);
if(inEditMode()) {
int count = title.getText().length();
if(count > 30){
title.setTextSize(24.0f);
} else {
title.setTextSize(30.0f);
}
}
}
Android
Build.VERSION.SDK_INT
ApplicationInfo.targetSdkVersion
the library doesn’t know where it’s run
24
Android
usually interface for loading pictures from to web to Widget looks like this:
pictureLoader.load(“url_to_resource”, imageView);
passing arguments extending from View, Activity etc.
often lead to Memory leak
queue is flooded with requests holding all references
25
Android
Android Studio is bundled with great profilers
Use memory usage graph to monitor you cache logic
Use cpu usage graph to monitor your custom views behaviour.
Use network traffic graph to check if your code doesn’t call web for stuff which
suppose to be in cache
26
Android
ProGuard is outstanding tool to shrink code and inject bytecode optimizations
While shipping your code you must either provide:
copy&paste configuration to ProGuard (latest plugin supports auto-configuration)
be transparent to ProGuard.
Configuration vs Transparency?
Transparency!
27
Android
http://www.methodscount.com/
28
Product Method count
com.squareup.okhttp3:okhttp:3.0.1 2704
io.relayr:android-sdk:1.0.2 5413
io.reactivex:rxjava:1.1.0 4605
com.google.code.gson:gson:2. 1341
com.applause:applause-sdk:3.4.0 5041
com.fasterxml.jackson.core:jackson-databind:2.7.0 10732
com.parse:parse-android:1.13.0 4543
The End
29
License
30
Licence
31
by default you own the copyright
no licence doesn’t conclue you can use it in your project
open code (found online) != open source movement
transferring code goes along with transferring the ownership
Check the licence
Check if it infects yours
(Apache, MIT vs GPL v2, LGPL, BSD)
Thank you
32
A guide to make crashproof libraries
It's always your fault
33

Mais conteúdo relacionado

Mais procurados

html5 & phonegap
html5 & phonegaphtml5 & phonegap
html5 & phonegapCaesar Chi
 
How QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsHow QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsQing-Cheng Li
 
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie..."How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...Fwdays
 
Bye Bye Charles, Welcome Odo, Android Meetup Berlin May 2014
Bye Bye Charles, Welcome Odo, Android Meetup Berlin May 2014Bye Bye Charles, Welcome Odo, Android Meetup Berlin May 2014
Bye Bye Charles, Welcome Odo, Android Meetup Berlin May 2014Danny Preussler
 
Redux at scale
Redux at scaleRedux at scale
Redux at scaleinovia
 
10 tips for Redux at scale
10 tips for Redux at scale10 tips for Redux at scale
10 tips for Redux at scaleinovia
 
前端網頁自動測試
前端網頁自動測試 前端網頁自動測試
前端網頁自動測試 政億 林
 
How do I write Testable Javascript so I can Test my CF API on Server and Client
How do I write Testable Javascript so I can Test my CF API on Server and ClientHow do I write Testable Javascript so I can Test my CF API on Server and Client
How do I write Testable Javascript so I can Test my CF API on Server and ClientGavin Pickin
 
5 Reasons Why Maven Sux
5 Reasons Why Maven Sux5 Reasons Why Maven Sux
5 Reasons Why Maven SuxCarlos Sanchez
 
Continuous integration with Git & CI Joe
Continuous integration with Git & CI JoeContinuous integration with Git & CI Joe
Continuous integration with Git & CI JoeShawn Price
 
軟體測試是在測試什麼?
軟體測試是在測試什麼?軟體測試是在測試什麼?
軟體測試是在測試什麼?Yao Nien Chung
 
MCE^3 - Jorge D. Ortiz - Fuentes - Escape From Mars
MCE^3 - Jorge D. Ortiz - Fuentes - Escape From Mars MCE^3 - Jorge D. Ortiz - Fuentes - Escape From Mars
MCE^3 - Jorge D. Ortiz - Fuentes - Escape From Mars PROIDEA
 
Getting Started with Titanium & Alloy
Getting Started with Titanium & AlloyGetting Started with Titanium & Alloy
Getting Started with Titanium & AlloyFokke Zandbergen
 
うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-kyon mm
 
Test code that will not slow you down
Test code that will not slow you downTest code that will not slow you down
Test code that will not slow you downKostadin Golev
 

Mais procurados (20)

html5 & phonegap
html5 & phonegaphtml5 & phonegap
html5 & phonegap
 
Auto Build
Auto BuildAuto Build
Auto Build
 
How QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsHow QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser Extensions
 
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie..."How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
 
Bye Bye Charles, Welcome Odo, Android Meetup Berlin May 2014
Bye Bye Charles, Welcome Odo, Android Meetup Berlin May 2014Bye Bye Charles, Welcome Odo, Android Meetup Berlin May 2014
Bye Bye Charles, Welcome Odo, Android Meetup Berlin May 2014
 
Redux at scale
Redux at scaleRedux at scale
Redux at scale
 
10 tips for Redux at scale
10 tips for Redux at scale10 tips for Redux at scale
10 tips for Redux at scale
 
前端網頁自動測試
前端網頁自動測試 前端網頁自動測試
前端網頁自動測試
 
How do I write Testable Javascript so I can Test my CF API on Server and Client
How do I write Testable Javascript so I can Test my CF API on Server and ClientHow do I write Testable Javascript so I can Test my CF API on Server and Client
How do I write Testable Javascript so I can Test my CF API on Server and Client
 
5 Reasons Why Maven Sux
5 Reasons Why Maven Sux5 Reasons Why Maven Sux
5 Reasons Why Maven Sux
 
Continuous integration with Git & CI Joe
Continuous integration with Git & CI JoeContinuous integration with Git & CI Joe
Continuous integration with Git & CI Joe
 
軟體測試是在測試什麼?
軟體測試是在測試什麼?軟體測試是在測試什麼?
軟體測試是在測試什麼?
 
MCE^3 - Jorge D. Ortiz - Fuentes - Escape From Mars
MCE^3 - Jorge D. Ortiz - Fuentes - Escape From Mars MCE^3 - Jorge D. Ortiz - Fuentes - Escape From Mars
MCE^3 - Jorge D. Ortiz - Fuentes - Escape From Mars
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Getting Started with Titanium & Alloy
Getting Started with Titanium & AlloyGetting Started with Titanium & Alloy
Getting Started with Titanium & Alloy
 
うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-
 
Swt J Face 3/3
Swt J Face 3/3Swt J Face 3/3
Swt J Face 3/3
 
Take a Stroll in the Bazaar
Take a Stroll in the BazaarTake a Stroll in the Bazaar
Take a Stroll in the Bazaar
 
Appcelerator Alloy MVC
Appcelerator Alloy MVCAppcelerator Alloy MVC
Appcelerator Alloy MVC
 
Test code that will not slow you down
Test code that will not slow you downTest code that will not slow you down
Test code that will not slow you down
 

Semelhante a It's always your fault. Poznań ADG 2016

Droidcon Berlin Barcamp 2016
Droidcon Berlin Barcamp 2016Droidcon Berlin Barcamp 2016
Droidcon Berlin Barcamp 2016Przemek Jakubczyk
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Enginecatherinewall
 
Hacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdfHacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdfShaiAlmog1
 
Integration of java ee applications on c – based implementations
Integration of java ee applications on c – based implementationsIntegration of java ee applications on c – based implementations
Integration of java ee applications on c – based implementationsAlexander Decker
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011YoungSu Son
 
Mastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental pluginMastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental pluginXavier Hallade
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedLecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedFabian Jakobs
 
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleSkills Matter
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگوrailsbootcamp
 
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexusMicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexusEmily Jiang
 
Features java9
Features java9Features java9
Features java9srmohan06
 
Getting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with ThymeleafGetting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with ThymeleafMasatoshi Tada
 
Cloud nativemicroservices jax-london2020
Cloud nativemicroservices   jax-london2020Cloud nativemicroservices   jax-london2020
Cloud nativemicroservices jax-london2020Emily Jiang
 
Cloud nativemicroservices jax-london2020
Cloud nativemicroservices   jax-london2020Cloud nativemicroservices   jax-london2020
Cloud nativemicroservices jax-london2020Emily Jiang
 
Visage Android Hands-on Lab
Visage Android Hands-on LabVisage Android Hands-on Lab
Visage Android Hands-on LabStephen Chin
 
Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDKKirill Kounik
 

Semelhante a It's always your fault. Poznań ADG 2016 (20)

It's always your fault
It's always your faultIt's always your fault
It's always your fault
 
Droidcon Berlin Barcamp 2016
Droidcon Berlin Barcamp 2016Droidcon Berlin Barcamp 2016
Droidcon Berlin Barcamp 2016
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Hacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdfHacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdf
 
Integration of java ee applications on c – based implementations
Integration of java ee applications on c – based implementationsIntegration of java ee applications on c – based implementations
Integration of java ee applications on c – based implementations
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17
 
Mastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental pluginMastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
Mastering the NDK with Android Studio 2.0 and the gradle-experimental plugin
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedLecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
 
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: Gradle
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
 
بررسی چارچوب جنگو
بررسی چارچوب جنگوبررسی چارچوب جنگو
بررسی چارچوب جنگو
 
Need 4 Speed FI
Need 4 Speed FINeed 4 Speed FI
Need 4 Speed FI
 
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexusMicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
MicroProfile, Docker, Kubernetes, Istio and Open Shift lab @dev nexus
 
Features java9
Features java9Features java9
Features java9
 
Getting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with ThymeleafGetting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with Thymeleaf
 
Cloud nativemicroservices jax-london2020
Cloud nativemicroservices   jax-london2020Cloud nativemicroservices   jax-london2020
Cloud nativemicroservices jax-london2020
 
Cloud nativemicroservices jax-london2020
Cloud nativemicroservices   jax-london2020Cloud nativemicroservices   jax-london2020
Cloud nativemicroservices jax-london2020
 
Visage Android Hands-on Lab
Visage Android Hands-on LabVisage Android Hands-on Lab
Visage Android Hands-on Lab
 
Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDK
 

Mais de Przemek Jakubczyk

Android Auto instrumentation
Android Auto instrumentationAndroid Auto instrumentation
Android Auto instrumentationPrzemek Jakubczyk
 
How to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android appHow to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android appPrzemek Jakubczyk
 
How to recognise that the user has just uninstalled your android app droidc...
How to recognise that the user has just uninstalled your android app   droidc...How to recognise that the user has just uninstalled your android app   droidc...
How to recognise that the user has just uninstalled your android app droidc...Przemek Jakubczyk
 

Mais de Przemek Jakubczyk (6)

Android Auto instrumentation
Android Auto instrumentationAndroid Auto instrumentation
Android Auto instrumentation
 
How to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android appHow to recognise that the user has just uninstalled your android app
How to recognise that the user has just uninstalled your android app
 
How to recognise that the user has just uninstalled your android app droidc...
How to recognise that the user has just uninstalled your android app   droidc...How to recognise that the user has just uninstalled your android app   droidc...
How to recognise that the user has just uninstalled your android app droidc...
 
Uninstall opera
Uninstall operaUninstall opera
Uninstall opera
 
Android accounts & sync
Android accounts & syncAndroid accounts & sync
Android accounts & sync
 
Robospock droidcon '14
Robospock   droidcon '14Robospock   droidcon '14
Robospock droidcon '14
 

Último

BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Servicenishacall1
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRnishacall1
 
Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfCWS Technology
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPsychicRuben LoveSpells
 

Último (6)

BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
 
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 
Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdf
 
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 

It's always your fault. Poznań ADG 2016

  • 1. Android Technical Lead Applause Inc. Przemek Jakubczyk pjakubczyk @pjakubczyk 1
  • 2. A guide to make crashproof libraries It's always your fault 2
  • 3. Background At Applause I am responsible for quality Applause SDK is crash and bug reporting library shipped to over 1000 customers SDK works with apps around the world 3
  • 4. History Joined 2 years ago to project with no QA Today ~1800 unit tests covering 3k methods 82% lines covered Last major problem was support for Marshmallow 4 Other than that over 6 months of no customer complain
  • 5. How your SDK should look like Be universal Work in every provided configuration Be robust Work in any environment Be defensive 5
  • 7. Just use it. 7 because it’s the base for Android build system
  • 8. Gradle use simple tricks to protect your styling 8 android { resourcePrefix 'applause_' } or pass custom values to source code via DSL defaultConfig { resValue "string", "applause_library_version”, "$version" }
  • 9. Gradle easier integration with your Groovy scripts for example create own distribution task task buildAll ( dependsOn: 'assembleRelease', type: Copy) { from “build/outputs/” into “another_path” } 9
  • 10. Gradle 10 Not possible :) Often heard question. How to pass arguments to tasks?
  • 11. Create new task for each configuration. Gradle 11 task buildAll ( dependsOn: ["assembleFreeRelease, assemblePaidRelease"] )
  • 12. Gradle With great power comes great responsibility Mind the execution time Common trick is to use VCS for versionNumber, each run takes time If possible (please!) don’t make http calls - huge delay, timeout, offline? Use only in tasks, not in build script evaluation. 12
  • 14. Java catching Exception doesn’t solve problem often hides real cause tempting but dangerous 14 try { network.getClients(); } catch (Exception e) { // handle exception }
  • 15. Java Null Object Pattern instead constantly checking for not null value 15 public interface Api { void post(String action); Api NULL = new Api() { void post(String action){} }; } getApi().post(“Works”)
  • 16. Java NPE Null Pointer Exception is the most popular exception thrown in runtime. NullObject pattern partially solves the problem. Use empty objects, collections etc; 16 List<User> fetchUsers(){ try { return api.getAllUsers(); } catch (IOException e){ return new ArrayList<Users>(); } }
  • 17. Java Usually library is started by one static method … and next versions provide more functionality Init interface becomes complex 17
  • 18. Java public static void start( String baseUrl, String defaultUser, String defaultPassword, boolean cacheRequests, boolean forceHttps, int timeout ) 18 Conf conf = new Conf.Builder() .withUrl(“http://api.github.com”) .withUser(“pjakubczyk”) .withPassword(“droidcon2015Krakow”) .withCache(false) .withHttps(true) .withTimeout(15) .build(); Library.start(conf);
  • 19. Java Builder pattern organize configuration Easier data validation Pass only parameters user wants Handling default values 19
  • 20. Java methods, fields, constructors default, private, protected, public Might sound a bit controversial I use default or public A.Reflection B.Allow developers to override, it’s their responsibility 20
  • 22. Android View.inEditMode() determines if view is drawn in Android Studio Usually to disable other components Let’s invert the usage 22
  • 23. 23 public void onFinishInflate(){ TextView title = findViewById(R.id.title); if(inEditMode()) { int count = title.getText().length(); if(count > 30){ title.setTextSize(24.0f); } else { title.setTextSize(30.0f); } } }
  • 25. Android usually interface for loading pictures from to web to Widget looks like this: pictureLoader.load(“url_to_resource”, imageView); passing arguments extending from View, Activity etc. often lead to Memory leak queue is flooded with requests holding all references 25
  • 26. Android Android Studio is bundled with great profilers Use memory usage graph to monitor you cache logic Use cpu usage graph to monitor your custom views behaviour. Use network traffic graph to check if your code doesn’t call web for stuff which suppose to be in cache 26
  • 27. Android ProGuard is outstanding tool to shrink code and inject bytecode optimizations While shipping your code you must either provide: copy&paste configuration to ProGuard (latest plugin supports auto-configuration) be transparent to ProGuard. Configuration vs Transparency? Transparency! 27
  • 28. Android http://www.methodscount.com/ 28 Product Method count com.squareup.okhttp3:okhttp:3.0.1 2704 io.relayr:android-sdk:1.0.2 5413 io.reactivex:rxjava:1.1.0 4605 com.google.code.gson:gson:2. 1341 com.applause:applause-sdk:3.4.0 5041 com.fasterxml.jackson.core:jackson-databind:2.7.0 10732 com.parse:parse-android:1.13.0 4543
  • 31. Licence 31 by default you own the copyright no licence doesn’t conclue you can use it in your project open code (found online) != open source movement transferring code goes along with transferring the ownership Check the licence Check if it infects yours (Apache, MIT vs GPL v2, LGPL, BSD)
  • 33. A guide to make crashproof libraries It's always your fault 33

Notas do Editor

  1. Mind that previous part will guard second one
  2. Good that we are talking about tasks