diff --git a/.gitignore b/.gitignore index 567fae84..ad255a4a 100644 --- a/.gitignore +++ b/.gitignore @@ -64,9 +64,11 @@ captures/ .idea/deploymentTargetSelector.xml # Keystore files -# Uncomment the following lines if you do not want to check your keystore files in. -#*.jks -#*.keystore +*.jks +*.keystore +*.p12 +*.pem +*.key # External native build folder generated in Android Studio 2.2 and later .externalNativeBuild diff --git a/app/build.gradle b/app/build.gradle index 1fcc1224..69bc2b50 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,6 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import java.util.Locale +import java.util.Properties plugins { id 'com.android.application' @@ -13,6 +15,27 @@ plugins { id 'com.google.firebase.crashlytics' } +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withInputStream { stream -> + localProperties.load(stream) + } +} + +def releaseSigningPropertyKeys = [ + 'RELEASE_STORE_FILE', + 'RELEASE_STORE_PASSWORD', + 'RELEASE_KEY_ALIAS', + 'RELEASE_KEY_PASSWORD' +] +def releaseSigningProperty = { key -> + localProperties.getProperty(key)?.trim() +} +def missingReleaseSigningProperties = { + releaseSigningPropertyKeys.findAll { key -> !releaseSigningProperty(key) } +} + android { namespace 'kr.co.vividnext.sodalive' compileSdk = 35 @@ -68,8 +91,25 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } + signingConfigs { + release { + def releaseStoreFile = releaseSigningProperty('RELEASE_STORE_FILE') + def releaseStorePassword = releaseSigningProperty('RELEASE_STORE_PASSWORD') + def releaseKeyAlias = releaseSigningProperty('RELEASE_KEY_ALIAS') + def releaseKeyPassword = releaseSigningProperty('RELEASE_KEY_PASSWORD') + + if (missingReleaseSigningProperties().isEmpty()) { + storeFile rootProject.file(releaseStoreFile) + storePassword releaseStorePassword + keyAlias releaseKeyAlias + keyPassword releaseKeyPassword + } + } + } + buildTypes { release { + signingConfig signingConfigs.release minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' @@ -172,6 +212,36 @@ android { } } +gradle.taskGraph.whenReady { taskGraph -> + def requiresReleaseSigning = taskGraph.allTasks.any { task -> + def taskName = task.name.toLowerCase(Locale.US) + taskName.contains('release') && ( + taskName.startsWith('assemble') || + taskName.startsWith('bundle') || + taskName.startsWith('install') || + taskName.startsWith('package') + ) + } + + if (!requiresReleaseSigning) { + return + } + + def missingProperties = missingReleaseSigningProperties() + if (!missingProperties.isEmpty()) { + throw new GradleException( + "Release signing properties are missing in local.properties: ${missingProperties.join(', ')}" + ) + } + + def releaseStoreFile = rootProject.file(releaseSigningProperty('RELEASE_STORE_FILE')) + if (!releaseStoreFile.exists()) { + throw new GradleException( + "Release signing store file does not exist: ${releaseStoreFile}" + ) + } +} + dependencies { implementation "androidx.media:media:1.7.1" implementation 'androidx.core:core-ktx:1.16.0'