plugins {
  id 'com.android.application'
  id 'kotlin-android'
  id 'kotlin-kapt'
}

kotlin {
  kotlinDaemonJvmArgs = [
    "-Dfile.encoding=UTF-8",
    "--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
    "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
    "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
    "--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
    "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
    "--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
    "--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
    "--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
    "--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
    "--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
  ]

  jvmToolchain(17)
}

android {
  namespace 'com.audiobookshelf.app'
  buildFeatures {
    viewBinding true
    buildConfig true
  }
  kotlinOptions {
    freeCompilerArgs = ['-Xjvm-default=all']
  }
  compileSdk rootProject.ext.compileSdkVersion
  defaultConfig {
    applicationId "com.audiobookshelf.app"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 114
    versionName "0.10.1-beta"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    manifestPlaceholders = [
      "appAuthRedirectScheme": "com.audiobookshelf.app"
    ]
    aaptOptions {
      // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
      // Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
      ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
    }
  }
  buildTypes {
    debug {
      applicationIdSuffix ".debug"
      versionNameSuffix "-debug"
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

repositories {
  flatDir {
    dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
  }
  mavenCentral()
}

configurations.configureEach {
  resolutionStrategy {
    force("com.google.android.gms:play-services-base:18.0.1")
    force("androidx.appcompat:appcompat:$androidxAppCompatVersion")
    force("androidx.core:core-ktx:$androidx_core_ktx_version")
    force("androidx.media:media:$androidx_media_version")
    force("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version")
    force("org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version")
  }
}

dependencies {
  implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
  implementation fileTree(include: ['*.jar'], dir: 'libs')
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
  implementation project(':capacitor-android')

  implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
  implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"

  implementation project(':capacitor-cordova-android-plugins')

  implementation "androidx.core:core-ktx:$androidx_core_ktx_version"

  implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
  implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"

  implementation "androidx.media:media:$androidx_media_version"

  // Exo Player
  if (findProject(':exoplayer-library-core') != null) {
    implementation project(':exoplayer-library-core')
    implementation project(':exoplayer-library-ui')
    implementation project(':exoplayer-extension-mediasession')
    implementation project(':exoplayer-extension-cast')
    implementation project(':exoplayer-hls')
  } else {
    implementation "com.google.android.exoplayer:exoplayer-core:$exoplayer_version"
    implementation "com.google.android.exoplayer:exoplayer-ui:$exoplayer_version"
    implementation "com.google.android.exoplayer:extension-mediasession:$exoplayer_version"
    implementation "com.google.android.exoplayer:extension-cast:$exoplayer_version"
    implementation "com.google.android.exoplayer:exoplayer-hls:$exoplayer_version"
  }

  // Glide for images
  implementation "com.github.bumptech.glide:glide:$glide_version"

  // Paper NoSQL Db
  implementation 'io.github.pilgr:paperdb:2.7.2'

  // Simple Storage
  implementation "com.anggrayudi:storage:1.5.6"

  // OK HTTP
  implementation 'com.squareup.okhttp3:okhttp:4.9.2'

  // Jackson for JSON
  implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.12.2'
}

apply from: 'capacitor.build.gradle'
