Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build and publish your own android custom component as library

Patrick
August 08, 2019

Build and publish your own android custom component as library

Patrick

August 08, 2019
Tweet

Other Decks in Technology

Transcript

  1. Who I am • Senior Consultant, Software Engineer • Write

    code for Gov & NGO • Trainer • Java Ecosystem mainly • Android Developer & Advocate since 2011 • GDG Kinshasa Lead • Frenchie...but can speak swahili and a bit of English
  2. 1. How to create an Android custom view library 2.

    How to publish your Android library 3. How to use your Android library 4. Best practices around building Android libraries Summary
  3. APK vs AAR Same structure but : • Android App

    Module compiles to APK • Android Library compiles to AAR
  4. Why building / using Libraries ? • Code reuse •

    Innovation • Performance • Open source contribution
  5. So Why custom components ( View ) ? • Performance.

    If you have a lots of views in your layout and you want to optimize it by drawing a single custom view to make it lighter. • A big view hierarchy that is complex to operate and support. • A complete custom view that requires manually drawing.
  6. Your need ? - A special Button, Textview, ImageView ?

    - A special LinearLayout, RelativeLayout ? - A custom View from scratch ? - A custom ViewGroup from Scratch?
  7. Building our custom View : MoodySmiley 1. Create Android Project

    with git integration 2. Create a Library Module 3. Extends android.view.View or ViewGroup 4. Declare variables / attributes 5. Override @OnDraw( ) 6. Override @OnLayout, @OnMesure ( If needed ) 7. Manage styling attributes
  8. Some Best Practices (1/6) • Intuitive: It should do what

    a user of the library expects it to do without having to look up the documentation. • Consistent: The code for the Android library should be well thought out and should not change drastically between versions. Follows semantic versioning. • Easy to use, hard to misuse: It should be easily understandable in terms of implementation and its usage.
  9. Some Best Practices (3/6) • Minimize permissions Remember : Every

    permission you add to your Android library’s AndroidManifest.xml file will get merged into the app that adds the Android library as a dependency ! Do not let your code crash just because you do not have a particular permission. Use this method to check if a particular permission granted or not:
  10. Some Best Practices (4/6) • Minimize requisites This will hide

    the app in the Play Store for devices that do not have Bluetooth ! Just because the app added your library !
  11. Some Best Practices (5/6) Instead use the following code snippet

    to detect the feature from your library during runtime and enable/disable feature accordingly
  12. Some Best Practices (6/6) • Support different versions : minSdkVersion

    ${theLowestPossible} • Provide documentation : README, Wiki, JavaDoc, etc • Bundle a simplistic app sample to showcase how to use your library
  13. Where to Go From Here? Android Custom View deep dive

    : Huyen Tue Dao https://academy.realm.io/posts/360andev-huyen-tue-dao-measure-layout-draw-repeat-custom-views-and-viewgroups-and roid/ Chiu-Ki-Chan http://chiuki.github.com/deep-dive-android-custom-components Best Practices https://blog.octo.com/en/android-library-development-best-practices-guide/