Kotlin Kotlin Android Extensions Product flavors


Example

Android extensions also work with multiple Android Product Flavors. For example if we have flavors in build.gradle like so:

android {
    productFlavors {
        paid {
            ...
        }
        free {
            ...
        }
    }
}

And for example, only the free flavor has a buy button:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/buy_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Buy full version"/>
</LinearLayout>

We can bind to the flavor specifically:

import kotlinx.android.synthetic.free.main_activity.buy_button