Loading...
Home
  • Tech Blogs
  • Videos
  • Conferences
    • Droidcon News
    • Upcoming Conferences
    • Become a Partner
    • Past Events
    • Keep Me Informed
    • Diversity Scholarships
  • Community
    • droidcon Team
    • How to Hold a Droidcon
  • Android Careers
Sign In

Global CSS

 

Android Library Development: Resource Declaration (Part 1)

 

 
Gökhan Alıcı
Software Engineer @onfido
Published: November 25, 2020
Tweet
Share
 

 

After some years of application development experience, I started working on the Android library development side. This article is the first article on my library development experience series which is about resources file usage that could be useful for library developers and integrators.

 

TL;DR

  • Add your library-specific prefix in your library’s resources ie. strings, filename…
  • Use the External Libraries section to dig into external libraries
  • Don’t define required hardware features using uses-feature property in the manifest file

Library resources could be overridden by integrators whether intentionally or inadvertently. Let’s assume we have a string template that we use to show some instructions

 

Image for post

 

If an integrator overrides the session_expire string resource with a new string that not contains %1$d, it will cause an exception in runtime. To prevent this kind of problem we could separate the string into two parts and use the library name as a prefix before the actual string key to make unintentional string override harder.

 

Image for post

 

To ensure each resource key has a library prefix you could define prefix in your build.gradle which warns if there is a resource not has a prefix.

 

Image for post

 

Even though resource override seems a pain for library developers, it tremendously eases UI customization for library developers without additional effort after properly used styles. For example, the text color used in the library might not be compatible with the host app in terms of accessibility or text color, at this point, the library’s documentation should be clear about which style/color used for a specific UI element. After an integrator overrides the specific resource on the app’s resource folder, UI customization will be applied.

What about If the library not documented how to change a specific UI element? Even it seems daunting we could dig into the library's resource with help of Android Studio.

 

Image for post

 

When you click the External Libraries section, your project’s external libraries will be listed then you need to find the related library that you would like to make some changes, but the tricky step is how to find the UI element from the resource files, I follow these steps;
* Pick a string from a screen
* Search that string text in the res/values/values.xml to find the key of the string
* Find a layout file under the res/layout folder using the string key

After you find the layout file you’re free to apply your changes easily following the resource override approach in your app’s res folder. But don’t forget in the next version of the library your changes might be invalid.

Some libraries heavily depend on hardware features such as camera, microphone, etc. due to that reason library developers tend to declare that features as required features in the manifest file.

 

Image for post

 

But when a feature declared in the manifest file, Google play filters to prevent the application from being installed to devices that do not include the features or do not support the features specified in the manifest. So the library developer’s user-feature declaration impacts an application’s downloads even there is no guarantee the library will be used by each user of the application

Instead of uses-feature declaration, the required features should be checked at the runtime using PackageManager’s hasSystemFeature function to check whether the device supports the features or not

 

Image for post

 

Thanks for reading, feel free to reach out to me on LinkedIn and Twitter.

 

 

 

Tags: Android, Android Libraries, Android App Development, AndroidDev, Android Resources

 

View original article at: 


 

Originally published: November 08, 2020

Android News
Evolution of Android Update SystemEvolution of Android Update System
Evolution of Android Update SystemEvolution of Android Update System

By Ivan Kuten

So, how can you update Android on mobile devices? While developing software for Smart TVs and Android-based set-top boxes, we’ve narrowed it down to four ways, discarding some very exotic options:

By ProAndroidDev -
Android News
Happy Railway
Happy Railway

By Hadi Lashkari Ghouchani

This post is on the tail of Railway Oriented Programming in Kotlin by Antony Harfield. So you need to read it first and continue here. As it’s obvious I really liked it and tried it out. It needs every process have a result like

By ProAndroidDev -
Android News
Unit Tests and Concurrency
Unit Tests and Concurrency

By Stojan Anastasov

Once Retrofit added RxJava support, RxJava became my go-to concurrency framework for writing Android apps. One of the great things about RxJava is the excellent testing support. It includes TestObserver, TestScheduler, RxJavaPlugins so you can switch your schedulers in tests.

By ProAndroidDev -
Android News
When Compat libraries will not save you
When Compat libraries will not save you

By Danny Preussler

And why you should avoid using the “NewApi” suppression! The idea of “Compat” libraries was probably one of the key aspects of Android dominating the mobile space. Other than with iOS, Android users often could not update their operating system after a new version launch, simply as their phones won’t allow them to, the Android problem of fragmentation.

 

By ProAndroidDev -
droidcon News

Tech Showcases,

Developer Resources &

Partners

/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/home-details/EmployerBrandingHeader
EmployerBrandingHeader
https://jobs.droidcon.com/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/jobs-droidcon/jobs.droidcon.com
jobs.droidcon.com

Latest Android Jobs

http://www.kotlinweekly.net/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/kotlin-weekly/Kotlin Weekly
Kotlin Weekly

Your weekly dose of Kotlin

https://proandroiddev.com/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/pad/ProAndroidDev
ProAndroidDev

Android Tech Blogs, Case Studies and Step-by-Step Coding

/detail?content-id=/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Zalando/Zalando
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Zalando/Zalando
Zalando

Meet one of Berlin's top employers

/detail?content-id=/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Academy for App Success/Academy for App Success
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Academy for App Success/Academy for App Success
Academy for App Success

Google Play resources tailored for the global droidcon community

Follow us

Team droidcon

Get in touch with us

Write us an Email

 

 

Quicklinks

> Code of Conduct

> Terms and Conditions

> How to hold a conference

> FAQs

> Imprint

Droidcon is a registered trademark of Mobile Seasons GmbH Copyright © 2020. All rights reserved.

powered by Breakpoint One