apply plugin: 'com.android.application'

android {
    ndkVersion "22.0.7026061"

    compileSdkVersion 30

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 30

        versionName "9.8.3"
        versionCode = 254
    }

    flavorDimensions "root"

    productFlavors {
        root {
            // Android O has native mouse capture, so don't show the rooted
            // version to devices running O on the Play Store.
            maxSdkVersion 25

            externalNativeBuild {
                ndkBuild {
                    arguments "PRODUCT_FLAVOR=root"
                }
            }

            applicationId "com.limelight.root"
            dimension "root"
        }

        nonRoot {
            externalNativeBuild {
                ndkBuild {
                    arguments "PRODUCT_FLAVOR=nonRoot"
                }
            }

            applicationId "com.limelight"
            dimension "root"
        }
    }

    lintOptions {
        disable 'MissingTranslation'
        lintConfig file("lint.xml")
    }

    bundle {
        language {
            // Avoid splitting by language, since we allow users
            // to manually switch language in settings.
            enableSplit = false
        }
        density {
            // FIXME: This should not be neccessary but we get
            // weird crashes due to missing drawable resources
            // when this split is enabled.
            enableSplit = false
        }
    }

    buildTypes {
        debug {
            applicationIdSuffix ".debug"

            minifyEnabled true
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            // To whomever is releasing/using an APK in release mode with
            // Moonlight's official application ID, please stop. I see every
            // single one of your crashes in my Play Console and it makes
            // Moonlight's reliability look worse and makes it more difficult
            // to distinguish real crashes from your crashy VR app. Seriously,
            // 44 of the *same* native crash in 72 hours and a few each of
            // several other crashes.
            //
            // This is technically not your fault. I would have hoped Google
            // would validate the signature of the APK before attributing
            // the crash to it. I asked their Play Store support about this
            // and they said they don't and don't have plans to, so that sucks.
            //
            // In any case, it's bad form to release an APK using someone
            // else's application ID. There is no legitimate reason, that
            // anyone would need to comment out the following line, except me
            // when I release an official signed Moonlight build. If you feel
            // like doing so would solve something, I can tell you it will not.
            // You can't upgrade an app while retaining data without having the
            // same signature as the official version. Nor can you post it on
            // the Play Store, since that application ID is already taken.
            // Reputable APK hosting websites similarly validate the signature
            // is consistent with the Play Store and won't allow an APK that
            // isn't signed the same as the original.
            //
            // I wish any and all people using Moonlight as the basis of other
            // cool projects the best of luck with their efforts. All I ask
            // is to please change the applicationId before you publish.
            //
            // TL;DR: Leave the following line alone!
            applicationIdSuffix ".unofficial"

            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    externalNativeBuild {
        ndkBuild {
            path "src/main/jni/Android.mk"
        }
    }
}

dependencies {
    implementation 'org.bouncycastle:bcprov-jdk15on:1.66'
    implementation 'org.bouncycastle:bcpkix-jdk15on:1.66'
    implementation 'org.jcodec:jcodec:0.2.3'
    implementation 'com.squareup.okhttp3:okhttp:3.12.12'
    implementation 'com.squareup.okio:okio:1.17.5'
    implementation 'org.jmdns:jmdns:3.5.5'
}
