$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Developing an Android library
Search
Dino Kovač
September 17, 2016
Programming
0
130
Developing an Android library
Slides from my barcamp talk at Droidcon Vienna 2016.
Dino Kovač
September 17, 2016
Tweet
Share
More Decks by Dino Kovač
See All by Dino Kovač
Continuous integration and deployment on Android (plus some sweets)
reisub
1
590
Kickstart your Android development
reisub
1
79
Continuous integration and deployment on Android
reisub
0
230
Other Decks in Programming
See All in Programming
Navigation 3: 적응형 UI를 위한 앱 탐색
fornewid
1
440
堅牢なフロントエンドテスト基盤を構築するために行った取り組み
shogo4131
8
2.5k
メルカリのリーダビリティチームが取り組む、AI時代のスケーラブルな品質文化
cloverrose
2
340
Socio-Technical Evolution: Growing an Architecture and Its Organization for Fast Flow
cer
PRO
0
390
Jetpack XR SDKから紐解くAndroid XR開発と技術選定のヒント / about-androidxr-and-jetpack-xr-sdk
drumath2237
1
180
Python札幌 LT資料
t3tra
6
1k
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
0
250
宅宅自以為的浪漫:跟 AI 一起為自己辦的研討會寫一個售票系統
eddie
0
520
Context is King? 〜Verifiability時代とコンテキスト設計 / Beyond "Context is King"
rkaga
10
1.4k
まだ間に合う!Claude Code元年をふりかえる
nogu66
5
880
AIコーディングエージェント(NotebookLM)
kondai24
0
220
愛される翻訳の秘訣
kishikawakatsumi
3
340
Featured
See All Featured
New Earth Scene 8
popppiees
0
1.2k
The Pragmatic Product Professional
lauravandoore
37
7.1k
We Are The Robots
honzajavorek
0
120
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
26
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
79
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
99
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
96
How STYLIGHT went responsive
nonsquared
100
6k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Transcript
Developing an Android library DINO KOVAČ
01 WHY?
WHY A LIBRARY? • DRY - don’t repeat yourself •
easier than copy/pasting classes
WHY AN OPEN SOURCE LIBRARY? • saving others time •
useful contributions from community • eternal fame!
02 WHAT?
DOES IT MAKES SENSE TO BUILD IT? • is there
a real need? • any existing libraries?
PICK A GOOD NAME • one that doesn’t already exist
• should make sense • bonus points if it’s amusing • example: • HTTParty - Makes http fun again!
03 HOW?
MIND THE API • primary way users interact with your
lib • make it easy to use • make it robust (avoid footguns!)
None
HTTPURLCONNECTION HttpURLConnection urlConnection = null; try { URL url =
new URL("https://api.github.com/markdown/raw"); connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setChunkedStreamingMode(0); OutputStream out = new BufferedOutputStream(connection.getOutputStream()); writeStream(out); InputStream in = new BufferedInputStream(connection.getInputStream()); readStream(in); } catch (IOException e) { // handle this } finally { if (connection != null) { connection.disconnect(); } }
HTTPURLCONNECTION
OKHTTP Request request = new Request.Builder() .url("https://api.github.com/markdown/raw") .post(RequestBody.create(MediaType.parse("text/plain"), "post body"))
.build(); try { Response response = client.newCall(request).execute(); } catch (IOException e) { // handle this }
FAIL FAST • as much validation as reasonably possible •
fail as fast as possible
FAIL FAST public Builder post(RequestBody body) { return method("POST", body);
} public Builder method(String method, RequestBody body) { if (method == null || method.length() == 0) { throw new IllegalArgumentException("method == null || method.length() == 0"); } if (body != null && !HttpMethod.permitsRequestBody(method)) { throw new IllegalArgumentException("method " + method + " must not have a request body."); } if (body == null && HttpMethod.requiresRequestBody(method)) { throw new IllegalArgumentException("method " + method + " must have a request body."); } this.method = method; this.body = body; return this; }
DON’T EXPOSE THE INTERNALS • package-protected classes • private or
protected methods
APP RESOURCES LIBRARY RESOURCES MERGED RESOURCES
APP RESOURCES LIBRARY RESOURCES MERGED RESOURCES @string/app_name @string/app_name @string/app_name
APP RESOURCES LIBRARY RESOURCES MERGED RESOURCES @string/app_name (en) @string/app_name (fr)
@string/app_name (de) @string/app_name (en) @string/app_name (fr) @string/app_name (de) @string/app_name
ANDROID SPECIFICS • build.gradle • resourcePrefix 'dbinspector_'
WRITE THE DOCS • what does it do? • how
do I use it? • maybe an example app?
DISTRIBUTE • don’t use maven central, use jcenter • automate
deployment
SHAMELESS SELF-PROMOTION • https://github.com/infinum/android_dbinspector • https://github.com/reisub/HttPizza
Any questions?
[email protected]
@DINO_BLACKSMITH Visit infinum.co or find us on
social networks: infinum.co infinumco infinumco infinum