Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2bb3871a authored by Jonathan Klee's avatar Jonathan Klee
Browse files

feat: add generic build type

parent 2720e174
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ gen/

# Local configuration file (sdk path, etc)
local.properties
app/keystore/generic.jks

# Proguard folder generated by Eclipse
proguard/
+58 −1
Original line number Diff line number Diff line
@@ -162,6 +162,39 @@ android {
            keyAlias = "platform"
            keyPassword = "platform"
        }

        val genericStoreFile = retrieveOptionalKey("GENERIC_STORE_FILE")
        val genericStorePassword = retrieveOptionalKey("GENERIC_STORE_PASSWORD")
        val genericKeyAlias = retrieveOptionalKey("GENERIC_KEY_ALIAS")
        val genericKeyPassword = retrieveOptionalKey("GENERIC_KEY_PASSWORD")

        val hasGenericSigning =
            !genericStoreFile.isNullOrBlank() &&
                !genericStorePassword.isNullOrBlank() &&
                !genericKeyAlias.isNullOrBlank() &&
                !genericKeyPassword.isNullOrBlank()

        if (isGenericBuildRequested() && !hasGenericSigning) {
            throw GradleException(
                "Missing generic signing configuration. " +
                    "Please define GENERIC_STORE_FILE, GENERIC_STORE_PASSWORD, " +
                    "GENERIC_KEY_ALIAS and GENERIC_KEY_PASSWORD in local.properties."
            )
        }

        if (
            !genericStoreFile.isNullOrBlank() &&
                !genericStorePassword.isNullOrBlank() &&
                !genericKeyAlias.isNullOrBlank() &&
                !genericKeyPassword.isNullOrBlank()
        ) {
            create("generic") {
                storeFile = rootProject.file(genericStoreFile)
                storePassword = genericStorePassword
                keyAlias = genericKeyAlias
                keyPassword = genericKeyPassword
            }
        }
    }

    buildTypes {
@@ -178,6 +211,12 @@ android {
        debug {
            signingConfig = signingConfigs.findByName("platform")
        }

        create("generic") {
            initWith(getByName("release"))
            signingConfig = signingConfigs.findByName("generic")
            matchingFallbacks += listOf("release")
        }
    }

    splits {
@@ -199,6 +238,24 @@ fun retrieveKey(keyName: String): String {
        ?: throw GradleException("$keyName property not found in local.properties file")
}

fun retrieveOptionalKey(keyName: String): String? {
    val localPropertiesFile = rootProject.file("local.properties")
    if (!localPropertiesFile.exists()) {
        return null
    }

    val properties = Properties().apply {
        load(localPropertiesFile.inputStream())
    }

    return properties.getProperty(keyName)
}

fun isGenericBuildRequested(): Boolean =
    gradle.startParameter.taskNames.any { taskName ->
        taskName.contains("generic", ignoreCase = true)
    }

dependencies {
    // include core subproject (manages its own dependencies itself, however from same version catalog)
    implementation(project(":core"))