Skip to content

Setting up your MainActivity.kt

Jahir Fiquitiva edited this page Mar 18, 2020 · 8 revisions

After you have imported your project successfully, go to the java files and edit MainActivity.kt, which is located at app/src/main/kotlin/your/package/name/

You will find these lines there:

class MainActivity : KuperActivity() {
    /**
     * These things here have the default values. You can delete the ones you don't want to change
     * and/or modify the ones you want to.
     */
    override val billingEnabled = true
    
    override fun amazonInstallsEnabled():Boolean = false
    override fun checkLPF():Boolean = true
    override fun checkStores():Boolean = true
    
    /**
     * This is your app's license key. Get yours on Google Play Dev Console.
     * Default one isn't valid and could cause issues in your app.
     */
    override fun getLicKey():String? = "MIIBIjANBgkqhkiGgKglYGYGihLuihUuhhuBlouBkuiuBIyvYV"
    
    /**
     * This is the license checker code. Feel free to create your own implementation or
     * leave it as it is.
     * Anyways, keep the 'destroyChecker()' as the very first line of this code block
     * Return null to disable license check
     */
    override fun getLicenseChecker():PiracyChecker? {
        destroyChecker() // Important
        return if (BuildConfig.DEBUG) null else super.getLicenseChecker()
    }

What does every line do?

override val billingEnabled = true

If you plan to provide in-app purchases, keep this function unchanged, otherwise set it to false. If it is set to true, be sure that you enable the required permission in AndroidManifest.xml

Also, if you want to enable donations, you must add your license key too, otherwise they won't work.

override fun amazonInstallsEnabled():Boolean = false

If you plan to distribute your app in the Amazon's Appstore, change this function to true, instead of false.

override fun checkLPF():Boolean = true

If you want the License Checker to check whether user has Lucky Patcher installed and prevent him from using your app until he uninstalls it, keep this function unchanged, otherwise set it to false.

override fun checkStores():Boolean = true

If you want the License Checker to check whether user has installed 3rd party stores that let people download pirated apps (such as Aptoide or BlackMarket) and prevent him from using your app until he uninstalls it, keep this function unchanged, otherwise set it to false.

override fun getLicKey():String? = "MIIBIjANBgkqhkiGgKglYGYGihLuihUuhhuBlouBkuiuBIyvYV"

If your app is going to be paid, you may want to enable the License Checker. In order to make it work, you need to paste an API key into this function. The API key gets generated by Dev Console right after creating app page. You can find it by going to your app's page (in Dev Console), then click Development tools tab and you should see a link to Services and APIs. You can find your API key in this page, then copy it and replace "MIIBIjANBgkqhkiGgKglYGYGihLuihUuhhuBlouBkuiuBIyvYV" with your key. Don't forget to put it in quotes.

Fixing wrong import

Android Studio may wrongly import a BuildConfig class from Kuper's default package which will cause a Build Error. This bad import would look like this

import dev.jahir.kuper.app.BuildConfig

Where it will have a red color. All you have to do to fix this error is change the line above to:

import your.package.name.BuildConfig

and Rebuild your project.