Log.v(“ThreeTips”, “#17”)

Kotlin is new trend and I see everyone is switching to Kotlin language in Android Development. So In my next tips, I will use more Kotlin.

1 — Operator Overloading in Kotlin

Kotlin allows us to provide implementations for a predefined set of operators on our types. These operators have symbolic representation like *,-,+ etc. Lets examine it with a little snippet.

val disposables = CompositeDisposable()
val observable1 = your_observable
operator fun CompositeDisposable.plusAssign(disposable: Disposable){
disposables += observable1

2 — Using font in Support Library (As of 26.0.0)

As of Android Support Library 26.0, you must declare both sets of attributes to ensure your fonts load on devices running Android 8.0 (API level 26) or lower. Otherwise your app crashes with following error.

Caused by: java.lang.NullPointerException
at android.graphics.FontFamily.nAddFontFromAssetManager

app:fontWeight="400" />

3 — Gradle 3.0: “api” vs “implementations”

If you upgraded your gradle plugin to 3.0, you might have seen “compile” is deprecated. You can also see that some documentations are already updated with “implementation”.

//before gradle 3.0
//After gradle 3.0

Basically you can use “api” instead of “compile”.

But if you want faster build time in your app, you can do following.

Software Engineer at Storytel

Software Engineer at Storytel