Simon Hutton
Simon Hutton

Reputation: 1787

How can I include a library project in only the Premium build of my app and not the Free build?

I have an App which uses the same code base for the Paid and Free versions..

The cut-down build.gradle below gives an idea of the structure

android {
....
defaultConfig {
    applicationId "com.myco.myapp"
    ....
}

buildTypes {
....
    release {
    ....
    }
}

productFlavors {
    free {
        applicationIdSuffix ".free"
        buildConfigField "boolean", "PREMIUM", "false"
        buildConfigField "boolean", "FREE", "true"
    }
    premium {
        applicationIdSuffix ".premium"
        buildConfigField "boolean", "PREMIUM", "true"
        buildConfigField "boolean", "FREE", "false"
    }
}

dependencies {
    ....
    compile project(path: ':LVL')
}

I am calling the LVL licencing in onCreate as follows :-

        if (BuildConfig.PREMIUM) {
        String deviceId = Settings.Secure.ANDROID_ID;
        Log.i(TAG, "Device Id: " + deviceId);
        mHandler = new Handler();
        mLicenseCheckerCallback = new MyLicenseCheckerCallback();
        // Construct the LicenseChecker with a Policy.
        mChecker = new LicenseChecker(
                getApplicationContext(), new ServerManagedPolicy(this,
                new AESObfuscator(SALT, getPackageName(), deviceId)),
                BASE64_PUBLIC_KEY  // Your public licensing key.
        );
        doCheck();
    }

The LVL library isn't called or required in the 'free' version of myapp. My question is :- how should I structure my project / build.gradle so that the LVL library isn't included in the APK of the Free version (but is included in the Premium version?

Upvotes: 1

Views: 64

Answers (1)

Qamar
Qamar

Reputation: 5137

try

dependencies {
   premiumCompile project(':LVL')
}

ref to similar question

Upvotes: 1

Related Questions