Building software for cattle farmers. Part 2. Production errors
Tags: mobile, android, kotlin, tristan
Published: 2023-02-07 20:46:11

### Introduction
- In this series I take you along, week by week as I release my app and update you on all of the challenges I have faced from the previous week.
- The app I have built is an app that allows cattle farmers to track their calves during calving season

### My app on the Google play store
[HERE](https://play.google.com/store/apps/details?id=com.elliottsoftware.calftracker)

###GitHub code
- [HERE](https://github.com/thePlebDev/CalfTracker)

### Table of contents
1. [Production errors](#introduction)
2. [Fixing the errors](#paragraph1)
3. [New features](#feature)
4. [This weeks goals](#goals)




### Production Errors <a name="introduction"></a>
- Immediately after I published my app it would crash on opening, which was really weird since it worked perfectly on my own test device.
- To try and fix this problem fast I knew I needed some sort of logging and that is when I discovered [Timber](https://github.com/JakeWharton/timber) and [Firebase Crashlynics](https://firebase.google.com/docs/crashlytics). I then used [THIS](https://www.youtube.com/watch?v=RWEs985q7qM&t=181s) video to set both of them up and to create a decent crash reporting system.

- After coming across [THIS](https://stackoverflow.com/questions/60719791/firebase-firestore-variable-name-changed/75277383#75277383) Stackoverflow question, I realized the crash was caused by a obfuscation error initiated by proguard. By default, proguard runs in production mode but not in debug mode( the reason my app only worked on my test device).
- If you are unfamiliar with `obfuscation`, it shortens the name of classes and the members, which results in reduced DEX file sizes. This is fine but it becomes a problem when working with Firebase database models. Before obfuscation my code would look like this:

```
data class FireBaseCalf(var calftag: String? = null,
                        var cowtag:String? = null,
                        var ccianumber: String? = null,
                        var sex:String? = null,
                        var details:String?=null,
                        var date: Date? = null,
                        var birthweight:String? = null,
                        var id: String? = null,

                        )

```
- But after obfuscation my code would look like this:
```
data class FireBaseCalf(var a: String? = null,
                        var b? = null,
                        var c: String? = null,
                        var d? = null,
                        var e?=null,
                        var f: Date? = null,
                        var g? = null,
                        var h: String? = null,

                        )

```
- Which was causing the crash when my app would fetch data

### How to fix obfuscation errors? <a name="paragraph1"></a>
- As it turns out, if we read the documentation, [HERE](https://firebase.google.com/docs/database/android/start#proguard), firebase states that this sort of error will happen if the `toObject()` method is used. [THIS](https://stackoverflow.com/questions/60719791/firebase-firestore-variable-name-changed/75277383#75277383) is how I fixed the problem



### New Features <a name="feature"></a>
- Some of my users ( my dad) requested the feature of being able to choose the birth date of a calf. To implement this feature I used the combination of [THIS](https://www.youtube.com/watch?v=uAw87DdUnxg&t=436s) YouTube video and [THIS](https://maxkeppeler.notion.site/Samples-5a324f41ee904a0bbbb963407ec7e0c3) documentation, which created a very nice looking date picker:



![Android date picker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4u7afqeu1fq8pjgvbp3x.png)



### This weeks goals <a name="goals"></a>
- looking forward to this week I have two main goals I want to accomplish:

**1) code refactoring**
**2) open source contribution**

- I will keep working and create keep everyone updated next week

###Conclusion
- Thank you for taking the time out of your day to read this blog post of mine. If you have any questions or concerns please comment below or reach out to me on [Twitter](https://twitter.com/AndroidTristan).