How to manage Synthetic property in common android module

127 views Asked by At

In our Android project, we are having 3 flavours named ‘A’, ‘B’ and ‘C’. In android, We are always keeping common code in ‘main’ folder for avoiding code duplication. As like we created ‘ABMain’, ‘ACMain’ and ‘BCMain’ for avoiding code duplications in modules. (We configured sourceset in build.gradle).

sourceSets {
    A {
     res.srcDirs += [‘src/ABMain/res’, ‘src/ACMain/res’]
     java.srcDirs += [‘src/ABMain/java’, ‘src/ACMain/java’]
     resources.srcDirs += [‘src/ABMain/assets’, ‘src/ACMain/assets’]
    }
}

We moved many of the classes to the common modules. But we are facing a challenge when we try to move a class which has synthetic import statements.

For Example, In ‘ABMain’ we are having MainActivity.kt with layout_main. The problem is synthetic property having flavour name in the import statement. It cause a problem.

    import kotlinx.android.synthetic.A.layout_main.view.*
    import kotlinx.android.synthetic.B.layout_main.view.*
    //This one is not working
    import kotlinx.android.synthetic.AB.layout_main.view.*

How to use synthetic property import in common android module???

0

There are 0 answers