DEV Community

Cover image for How to build an android app in a professional way — Set it up in a professional way
Pelumi Eniodunmo
Pelumi Eniodunmo

Posted on

How to build an android app in a professional way — Set it up in a professional way

Android developers with some hands-on experience and familiarity with the android framework usually look forward to how to write their android application in a professional way and also how to write code with the most minimum amount of bug. Here i'll be listing what an android developer should do on an android project to make it professional and with less bug.

When I say professional, I don't mean that it's the way every android developer in the industry writes their android application, but that if you write it this way, your code can be easily understood by most android developers and makes it very maintainable such that anyone can jump onto your code base and make a contribution easily without much hassle.

  1. Architectural pattern
    This is just about how you structure your project files and how you write your code. Most likely you've heard of patterns such as MVC, MVP, MVVM, MVI… You must be wondering which one is best, well there's no one that is best. The pattern you choose should depend on your team and project, however the most adopted pattern in android is the MVVM pattern.
    Here is a lab tutorial showing the use of MVVM.

  2. Follow SOLID principle
    If you are familiar with OOP concepts, then you should know the SOLID principle. It is an abbreviation for
    S - Single Responsibility Principle: A class must have one and only one responsibility.
    O - Open Closed Principle: A class should be open for extension but closed for modification.
    L - Liskov Substitution Principle: Objects in a program should be replaceable with instances of their subtypes without altering the correctness of the program.
    I - Interface Segregation Principle: An interface should fulfil only the purpose of its implementation class.
    D - Dependency Inversion Principle: High level objects should not depend on low level objects but on abstraction. Abstractions should not also depend on details but details should depend on abstraction.

    Here is a good article showing implementation examples of SOLID principles.

  3. Dependency Injection (Dagger/Koin)
    This is about providing the dependencies a class needs without having to initialize that dependency in that same class. We can implement dependency injection in our project manually, however there are libraries that have been created to help abstract away complexities of implementing dependency injection. Dagger and Koin are popular libraries that help with dependency injection in an android project.

  4. Crashlytics
    When you release an app to users on play store, there are likely chances that your app may still crash on some users device probably due to memory issues, device compatibility or some parts of the user actions not handled by a developer. In order to know about crashes that happen to your users, it is best to setup crashlytics in your project so you can track the causes of crashes from your users and know how to deal with them in your next release.
    To setup crashlytics, there are helpful libraries such as Firebase crashlytics, App center crash reporting and so on that can be setup. When a crash occurs, it will appear on your crashlytics platform dashboard with the crash information.

  5. Testing and Code coverage
    It is advisable to write tests(unit, ui and integration tests) for your project to help prove the correctness of your code. Android has as default, JUnit and Android Instrumentation Runner to help with running tests on android.
    It is important that you write tests for all cases of your functionalities and this can be confirmed by using having a good code coverage library. A library to help with code coverage in android is Jacoco. Here is a youtube tutorial on how to use jacoco in your android project.

  6. CI/CD (Continuous Integration and Continuous Deployment)
    CI/CD tools help developers maintain good code quality, successful project builds and successful delivery of their product to their users.
    Platforms such as appcenter, nevercode.io, fastlane, bitrise helps with this CI/CD processes. When we commit an android code to a repository, it helps build the project and test the application on different devices and then publishes it to play store, depending on how we setup the platform we intend to use.

  7. Logging(Timber)
    During development we usually need to log some information(e.g Log.d("imageview loaded")) on the console, however we need to take them away before releasing for production. Having to clear up every Log.d in every file in the project can be cubersome especially when the project is very large. The Timber android library is one that helps to solve this issue, you just need to add the dependency to your project then set the timber library to be used in only debug mode during the initialization of your application in your code.
    You can then log with the Timber library (e.g Timber.d("imageview loaded")) and when you build for production, the library will disable logging in production automatically.
    Here is a tutorial on how to use Timber

Top comments (2)

Collapse
 
tientuyen07 profile image
tientuyen07

Thanks for your article!
Greatly!!!

Collapse
 
andrekelvin profile image
AndreKelvin

Informative. I think Google play store takes care of Crashlytics