dipu
dipu

Reputation: 1340

How to build apk in Android Studio for both amazon app store and google play store with corresponding in-App purchase API

I would like to build for both Google play store and Amazon app store from the same project created in Android Studio. Since the in-App purchase API is different I will some adjustment right before creating APK for a target store. How can I save time while I switch from one target to another. Some manual process is ok. Following is by gradle source set for google app store.

sourceSets {
    main {
        manifest.srcFile 'app/src/main/AndroidManifest.xml'
        java.srcDirs = ['app/src/main/java']
        resources.srcDirs = ['app/src']
        aidl.srcDirs = ['app/src/main/aidl']
        res.srcDirs = ['app/src/main/res']
        assets.srcDirs = ['app/src/assets']
    }

Upvotes: 3

Views: 943

Answers (1)

ashakirov
ashakirov

Reputation: 12350

Declare two gradle flavours for example googleplay and amazon.

   productFlavors {
        googleplay {
            applicationId = '...'
        }
        amazon {
            applicationId = '...'
        }
   }

Gradle library dependencies should be different for each flavour.

googleplayImplementation "...gp_library..."
amazonImplementation "...amazon_dependency..."

This way store specific build will not contain another store dependency classes, resources etc.

Then declare interface for example StoreProvider which will be enter point for all store specific api calls. In googleplay flavour sourceset provide implementation of StoreProvider which will call GooglePlay store methods. In amazon flavour provide implementation of StoreProvider which will call Amazon store methods. Use link to StoreProvider interface everywhere in application. If you organize app this way your application will not know anything about what store it uses. Plus it will be easy to add another stores support in the future.

Upvotes: 1

Related Questions