简体   繁体   中英

How to Organize Android App with Multiple Versions of Assets

I have an Android app that will be distributed in two (or more) brands. All java code for each distributions is exactly same , just different assets/resources (like layouts, drawables, dimensions, etc)

What is the best way to organize the project? I am using Git for version control, and trying to keep all distributions developed as a single project. So I can switch asset/resource sets easily for different branding each time needed.

Is there a good approach for it?

一种好的方法是将您的主要项目代码放入库中,然后对于其他项目(品牌),导入该库并根据需要覆盖资产。

Gradle Build Variants allow you to have a shared main codebase/resources and multiple variants with custom resources/code associated with each - you then can generate a separate APK for each variant. Of course, using Gradle for Android development requires you use Android Studio (which is currently in beta) as well.

As mentioned above, Gradle Build Variants is the best way to handle this. We have 11 variants (and counting) where the only difference are some configuration values. I organized the project as follows:

app/src/configurations/
   flavor1/
      common/res/...
      release/res/...
      stage/res/...

where the common directory holds configurations common to that build variant and the release and stage hold custom values for our release and staging versions (they have slightly different configurations as well).

All configurations common to all build variants live in the normal app/src/main/res folder.

Then in the app's build.grade, I have each product flavor defined:

productFlavors {
    flavor1 {
       applicationId = "com.example.flavor1"
    }

    flavor1stage {
        applicationId = "com.example.flavor1stage"
    }

    // etc. for each build flavor
}

android.sourceSets.flavor1 {
   res {
      srcDirs = ['src/configurations/flavor1/release/res', 'src/configurations/flavor1/common/res', 'src/res']
    }
}

android.sourceSets.flavor1stage {
    res {
       srcDirs = ['src/configurations/flavor1/stage/res', 'src/configurations/flavor1/common/res', 'src/res']
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM