Woony
Woony

Reputation: 41

How to build multiple APKs from a single source project

I wanna get multiple APKs from a single source project. Just the application's title, icon, and package name are different with the others.

The project is on gradle(1.12), as below.

.
└── my_project
    ├── build.gradle
    ├── settings.gradle
    └── module
        ├── build.gradle
        └── src

How can I do that?

Upvotes: 3

Views: 233

Answers (2)

Tommaso Resti
Tommaso Resti

Reputation: 5950

  • All the common files like java code, manifest and base resources are under "src/main"
  • Move your applications specific folders into "src/projects"
  • declare two productFlavor (one per applications) specifying applicationId and versionName
  • create two sourceSet (one per project) indicating the specific res, java, etc.. folders (i just needed res folder)

enter image description here

Full project's structure

enter image description here

Now, use Build Variants (bottom-left of Android Studio) to select the application to run

enter image description here

Upvotes: 0

Mostafa Gazar
Mostafa Gazar

Reputation: 2527

You can use productFlavors for that, and the under the promo and full folders (for example) create strings file (promo/res/values/strings.xml) with the update title value, same approach goes for the icon.

productFlavors {

    promo {
        packageName "com.woony.promo"
        versionCode 1
        versionName "v1.0.0_promo"
    }

    full {
        packageName "com.woony"
        versionCode 1
        versionName "v1.0.0"
    }

}

The updated project structure should be like the following

.
└── my_project
    ├── build.gradle
    ├── settings.gradle
    └── module
        ├── build.gradle
        └── src
            ├── main
            ├── promo
            └── full

And to generate the release apks just call the following once (just make sure you added signingConfigs and linked it in your release buildTypes)

gradle assembleRelease

Upvotes: 2

Related Questions