Android: Application for different requirements and features

ぐ巨炮叔叔 提交于 2019-12-12 04:37:14

问题


Using build variant in Android we can support different flavors. I need to develop an application where I am supporting different clients. Each client needs are a little different.

However, the basic data, network call class etc are same for all clients. How can I ensure partial code of my application remains same for all flavors?

This will help in maintaining one repository for all common classes.


回答1:


You need to understand how build variant works.

Each client needs are a little different is a vague statement

Imagine you have an application which has different screen's for different countries. But major functionalities are the same.

Now using build variants you can make different flavors

1) For country one : This will have screens designed specific to country one

2) For country two : This will have screens designed specific to country two

3) Common part : All the common business logic can be put under your common package

While project is build, the common part is considered and specific flavor too becomes part of flavorXX.apk

productFlavors {

        employee {
            applicationId "com.myapp.employee"
        }
        driver {
            applicationId "com.myapp.driver"
        }
        asset {
            applicationId "com.myapp.asset"
        }
        vehicle {
            applicationId "com.myapp.vehicle"
        }
    }
    sourceSets {
        asset {
            manifest.srcFile 'src/asset/AndroidManifest.xml'
        }
        driver {
            manifest.srcFile 'src/driver/AndroidManifest.xml'
        }
        employee {
            manifest.srcFile 'src/employee/AndroidManifest.xml'
        }
        vehicle {
            manifest.srcFile 'src/vehicle/AndroidManifest.xml'
        }
    }

In the above example , I am having different flavors of same application. Inorder to split accordingly you need to understand which part of your app goes into specific flavor and which can be kept common. Go through below links for more details.

Understanding Product Flavors reference link 1

Understanding Product Flavors reference link 2



来源:https://stackoverflow.com/questions/43841484/android-application-for-different-requirements-and-features

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!