Architecture and Code quality tools for better android development

In this post i will tell you about some problems i faced with coding , organizing and also collaborating with team members and also some valuable tools.

Huge activities(Spaghetti code)

in the very beginning things was good ,but when the number of lines exceed 600 problems start appears , events handling mixed with network calls and so on ,the result was a low quality code hard to maintain and almost impossible to test even a small part of it ,here is we were obliged to find a solution ,and the cure is replacing android’s particular architecture by MVP pattern .

The main benefits of MVP in our case was separation of concerns and decreasing the code quantity in the activity or the fragment and make it responsable only for events handling by doing this we get highly separated maintainable easy to understand code.

you can find more about MVP in the following resources:

Crashes

Since we are using java that means a lot of unchecked exception and most of times it will be generated in tester device where we cant access it.

Crashlytics is a powerful, light weight crash reporting solution , it comes as easy to integrate AndroidStudio plugin with a nice dashboard.

fabric analyze crashes and automatically deobfuscates stack traces, beginning with on-device exception handling. Once the crash report reaches fabric system, it process the stack frames against the application’s mapping file that was automatically uploaded to our servers at build time.

Instead of just showing the stack trace, Crashlytics performs deep analysis of each and every thread. Itde-prioritize lines that don’t matter while highlighting the interesting ones. This makes reading stack traces easier, faster, and far more useful.

Code Quality Matters!

Measuring code quality is not a matter of a single metric. Instead, software quality has many aspects, some of which can be captured in metrics. Those metrics can be nicely assembled within a single application, which gives a nice overview of the state of an application: Sonar.

Each project has a dashboard. The dashboard is an aggregation of more detailed metrics on a single page. This page gives a pretty good overview of the technical state of a project. When doing project reviews, this page is a good starting point to find items to investigate.

it really pays to set up code quality tools like SonarQube on your home development environment to get feedback on your code quality with the view to learm & improve.

Sonar uses Findbugs, Checkstyle and PMD to measure your code for bugs, ugly code and possible violation of code style policies. Sonar comes with a pretty good basic configuration, but the chance is big that you want to fiddle with the settings.

Functional Reactive Programming on Android With RxJava/RxAndroid

do you face problems dealing with AsyncTasks & unresponsive user interfaces,RxAndroid offers a fresh perspective on solving modern programming problems. Once understood, it can greatly simplify your project, especially when it comes to code dealing with asynchronous events with nested callbacks, complex list filtering/transformation or timing concerns.

you can find more about MVP in the following resources:

Dependency Injection

Many Android apps rely on instantiating objects that often require other dependencies. For instance, a Twitter API client may be built using a networking library such as Retrofit. To use this library, you might also need to add parsing libraries such as Gson. In addition, classes that implement authentication or caching may require accessing Shared preferences or other common storage, requiring instantiating them first and creating an inherent dependency chain.

Here is a great article from codepath: