Android: How to override properties files from jar dependency

March 04, 2016
2 min read

Often times when writing a library to be used by many clients (servers, mobile apps), the programmer is faced with the following feature: making it configurable by implementing an intermediate layer which alters its
functionallity. This is a small tutorial about how to override properties files from jar dependency
Let's take for example a library for http calls which consumes an api. The programmer using this sdk may want to change the url of the api, the port, client validation tokens, or default credentials.

One way of implementing the before mentioned layer is through properties files. Create a file named config.properties and place it under resources directory.

You can put in it the options to be overridden. Example:


application.auth.appid=<generated_app_id>

application.auth.appkey=<generated_app_key>

application.auth.useragent=App Java Client

application.auth.serverurl=<api_url>

The file must be placed in the classpath. Make sure the resources directory is present in maven file. If not add under resources tag the following:


<resource>

  <directory>relative_path_to_file_here</directory>

</resource>

This will include the file when building the jar which means you now have some default properties.

Reading the properties file is done through:


Properties prop = new Properties();

String propFileName = "config.properties";

try{

 

 InputStream inputStream = Config.class.getClassLoader().getResourceAsStream(propFileName);

 if (inputStream != null) {

   prop.load(inputStream);

 } else {

   throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");

 }

 appId = prop.getProperty("application.auth.appid");

 appKey = prop.getProperty("application.auth.appkey");

 userAgent = prop.getProperty("application.auth.useragent");

 serverUrl = prop.getProperty("application.auth.serverurl");

 inputStream.close();

}

catch(IOException e){

 e.printStackTrace();

}

In android studio you can include the library as usual with gradle: compile 'groupId:artifactId-version' (the variables can be extracted from the maven build file).

If you try to create a file with the same name: config.properties, which will contain the new configuration and place it under assets, res or raw, it will be included in the apk under folders with same name. Since the apk is just an archive you can open it with a zip client to explore the contents and check where the file is placed.
What we want is to include it in the root path of the apk. To do that, create a directory named "resources" under /src/main path and place the new file there. You have now a fully configurable sdk. Congratulations.

To understand more about class loaders and how resources are loaded, read the following:

android-how-to-override-properties-files-from-jar-dependency-ASSIST-Software

Photo source: https://www.flickr.com/photos/uncalno/8538679708

Share on:

Want to stay on top of everything?

Get updates on industry developments and the software solutions we can now create for a smooth digital transformation.

* I read and understood the ASSIST Software website's terms of use and privacy policy.

Frequently Asked Questions

1. What is ASSIST Software's development process?  

The Software Development Life Cycle (SDLC) we employ defines the following stages for a software project. Our SDLC phases include planning, requirement gathering, product design, development, testing, deployment, and maintenance.

2. What software development methodology does ASSIST Software use?  

ASSIST Software primarily leverages Agile principles for flexibility and adaptability. This means we break down projects into smaller, manageable sprints, allowing continuous feedback and iteration throughout the development cycle. We also incorporate elements from other methodologies to increase efficiency as needed. For example, we use Scrum for project roles and collaboration, and Kanban boards to see workflow and manage tasks. As per the Waterfall approach, we emphasize precise planning and documentation during the initial stages.

3. I'm considering a custom application. Should I focus on a desktop, mobile or web app?  

We can offer software consultancy services to determine the type of software you need based on your specific requirements. Please explore what type of app development would suit your custom build product.   

  • A web application runs on a web browser and is accessible from any device with an internet connection. (e.g., online store, social media platform)   
  • Mobile app developers design applications mainly for smartphones and tablets, such as games and productivity tools. However, they can be extended to other devices, such as smartwatches.    
  • Desktop applications are installed directly on a computer (e.g., photo editing software, word processors).   
  • Enterprise software manages complex business functions within an organization (e.g., Customer Relationship Management (CRM), Enterprise Resource Planning (ERP)).

4. My software product is complex. Are you familiar with the Scaled Agile methodology?

We have been in the software engineering industry for 30 years. During this time, we have worked on bespoke software that needed creative thinking, innovation, and customized solutions. 

Scaled Agile refers to frameworks and practices that help large organizations adopt Agile methodologies. Traditional Agile is designed for small, self-organizing teams. Scaled Agile addresses the challenges of implementing Agile across multiple teams working on complex projects.  

SAFe provides a structured approach for aligning teams, coordinating work, and delivering value at scale. It focuses on collaboration, communication, and continuous delivery for optimal custom software development services. 

5. How do I choose the best collaboration model with ASSIST Software?  

We offer flexible models. Think about your project and see which models would be right for you.   

  • Dedicated Team: Ideal for complex, long-term projects requiring high continuity and collaboration.   
  • Team Augmentation: Perfect for short-term projects or existing teams needing additional expertise.   
  • Project-Based Model: Best for well-defined projects with clear deliverables and a fixed budget.   

Contact us to discuss the advantages and disadvantages of each model. 

ASSIST Software Team Members

See the past, present and future of tech through the eyes of an experienced Romanian custom software company. The ASSIST Insider newsletter highlights your path to digital transformation.

* I read and understood the ASSIST Software website's terms of use and privacy policy.

Follow us

© 2025 ASSIST Software. All rights reserved. Designed with love.