// Top-level build file where you can add configuration options common to all sub-projects/modules.

ext.signedRelease = project.findProperty("RELEASE_SIGN") ?: false
ext.minSdkV = project.findProperty("MIN_SDK").toInteger() ?: 29
ext.targetSdkV = project.findProperty("TARGET_SDK").toInteger() ?: 34

ext.versionCode = project.findProperty("VERSION_CODE") ?: 1
ext.versionName = project.findProperty("VERSION_NAME") ?: "1.0"
ext.namespaceV = project.findProperty("NAMESPACE")

def hasProjectGradle = project.hasProperty("PROJECT_FILE") ?: false

if (hasProjectGradle == true)
{
  apply from: "${PROJECT_FILE}"
}

println "generating ${signedRelease ? "signed" : "unsigned"} apk(aab) (sdk ${ext.targetSdkV}) ${signedRelease ? "(key: " + RELEASE_KEY_ALIAS + ")" : ""}"

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.7.3'
        //classpath 'com.google.gms:google-services:4.4.2'
        //classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }

    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:deprecation"
        }
    }
}

apply plugin: 'com.android.application'
//apply plugin: 'com.google.gms.google-services'
//apply plugin: 'com.google.firebase.crashlytics'

android {
  namespace("${namespaceV}")
  compileSdk targetSdkV

  buildFeatures.prefab true

  lint {
    checkReleaseBuilds false
  }

  packagingOptions {
    jniLibs {
      useLegacyPackaging = true
    }
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    coreLibraryDesugaringEnabled true
  }

  sourceSets {
    main {
      java.srcDirs = ['src']
      res.srcDirs = ['res']
      jniLibs.srcDirs = ['libs']
      assets.srcDirs = ['assets']
      manifest.srcFile 'AndroidManifest.xml'
    }
  }

  defaultConfig {
      minSdk minSdkV
      targetSdk targetSdkV
      versionCode versionCode
      versionName versionName
      ndk {
        abiFilters 'arm64-v8a'
      }
  }

  buildTypes {
    release {
      // Add this extension
      //firebaseCrashlytics {

          // Enable processing and uploading of native symbols to Firebase servers.
          // By default, this is disabled to improve build speeds.
          // This flag must be enabled to see properly-symbolicated native
          // stack traces in the Crashlytics dashboard.

          //nativeSymbolUploadEnabled true
          //unstrippedNativeLibsDir file("unstripped_libs")
          //upload obfuscate file to crashlytics if proguard file is present
          //if (project.file("project.proguard").exists()) {
            //mappingFileUploadEnabled true
          //}
      // }

      if (signedRelease == "true") {
        if (project.file("project.proguard").exists()) {
          minifyEnabled true
          println("Obfuscating java code")
        } else {
          minifyEnabled false
        }
        signingConfig = android.signingConfigs.create("release") {
          it.storeFile rootProject.file(RELEASE_STORE_FILE)
          it.storePassword RELEASE_STORE_PASSWORD
          it.keyAlias RELEASE_KEY_ALIAS
          it.keyPassword RELEASE_KEY_PASSWORD
        }
      } else {
       minifyEnabled false
       signingConfig = null
      }
    }

    debug {
      minifyEnabled false
    }
  }
}


dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation 'androidx.appcompat:appcompat:1.2.0'
  coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'
}
