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
Compose CameraX on Android
Compose CameraX on Android

By Peng Jiang

Android new UI toolkit Jetpack compose is in beta now, which has all the features you need to build production-ready apps. CameraX is another Jetpack support library, which let you control the camera easier. As compose is still under development, lots of the views are still not available the compose way.

By ProAndroidDev -
Android News
Getting… your BottomSheetScaffold working on Jetpack Compose Beta 03
Getting… your BottomSheetScaffold working on Jetpack Compose Beta 03

By Carlos Mota

It’s Monday, no releases this week, and… there’s a new version of Jetpack Compose — beta 03—available. What a perfect time to just increment 02 to 03 and see what’s new. The API is (almost) final so after updating from alpha to beta there weren’t any big changes to do. However, and remember that’s still in development, there’s always something that I need to update. 

By ProAndroidDev -
Android News
Noisy Code With Kotlin Scopes
Noisy Code With Kotlin Scopes

By Chetan Gupta

Scopes make your code more readable? think again... You are going to encounter these scope functions namely let, run, apply, also, within every Kotlin codebase, along with all the mischievous ways developers exploit their usage from the way they were intended for. Let see how popular opinion on those ends up just as a code noise.

By ProAndroidDev -
Android News
Improving Android DataBinding with Bindables library
Improving Android DataBinding with Bindables library

By Jaewoong Eum

DataBinding is one of the most important factors for MVVM architecture. The basic concept of DataBinding is to link the view and view model via observer patterns, properties, event callbacks, etc. Linking and automating communication between the view via the bound properties or something in the view model has a lot of benefits in the MVVM architecture concept.

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