/*
 * Copyright 2019 ACINQ SAS
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
  compileSdkVersion 30
  ndkVersion "22.1.7171670"
  defaultConfig {
    applicationId "fr.acinq.eclair.wallet"
    minSdkVersion 21
    targetSdkVersion 30
    versionCode 59
    versionName "0.4.18"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
  }
  buildTypes {
    release {
      resValue "string", "CHAIN", CHAIN_TESTNET
      buildConfigField "String", "CHAIN", CHAIN_TESTNET
      debuggable false
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
      resValue "string", "CHAIN", CHAIN_TESTNET
      buildConfigField "String", "CHAIN", CHAIN_TESTNET
      debuggable true
    }
    applicationVariants.all { variant ->
      variant.outputs.all { output ->
        def abi = output.getFilter(com.android.build.OutputFile.ABI)
        final String architecture = abi == null ? "universal" : abi
        final String chain = variant.buildType.resValues.get("CHAIN").value // careful, contains " characters...
        outputFileName = "${defaultConfig.versionCode}-v${defaultConfig.versionName}-${chain.substring(1, chain.length() - 1)}-$architecture-${variant.buildType.name}.apk"
      }
    }
  }
  splits {
    abi {
      enable true
      reset() // reset abi list to none
      include "x86", "x86_64", "arm64-v8a", "armeabi-v7a"
      universalApk true
    }
  }
  configurations.all {
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'
    exclude group: "org.apache.httpcomponents", module: "httpclient"
  }
  buildFeatures {
    dataBinding true
    viewBinding true
  }
  packagingOptions {
    exclude 'META-INF/LICENSE*'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/DEPENDENCIES'
    merge 'reference.conf'
  }
  externalNativeBuild {
    cmake {
      path 'CMakeLists.txt'
    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

greendao {
  // increment when changing DB structure
  schemaVersion 8
}

dependencies {
  implementation fileTree(include: ['*.jar'], dir: 'libs')
  androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
    exclude group: 'com.android.support', module: 'support-annotations'
  })
  implementation 'com.google.android.material:material:1.3.0'
  implementation 'androidx.preference:preference:1.1.1'
  implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
  implementation 'androidx.media:media:1.3.0'
  implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  implementation 'com.google.code.findbugs:jsr305:3.0.2'

  // gdrive api rest v3 + google auth
  def google_drive_rest_version = "v3-rev197-1.25.0"
  def google_play_auth_version = "19.0.0"
  def google_http_client_gson = "1.39.2"
  def google_api_client_version = "1.31.4"
  implementation "com.google.apis:google-api-services-drive:$google_drive_rest_version"
  implementation "com.google.android.gms:play-services-auth:$google_play_auth_version"
  implementation "com.google.http-client:google-http-client-gson:$google_http_client_gson"
  implementation "com.google.api-client:google-api-client-android:$google_api_client_version"

  // ANDROIDX - biometric
  def biometric_version = "1.1.0"
  implementation "androidx.biometric:biometric:$biometric_version"

  implementation('androidx.work:work-runtime:2.5.0') {
    exclude group: 'com.google.guava', module: 'listenablefuture'
  }
  // logging
  implementation 'org.slf4j:slf4j-api:1.7.30'
  implementation 'com.github.tony19:logback-android:2.0.0'
  // eclair core
  implementation 'fr.acinq.secp256k1:secp256k1-kmp-jni-android:0.5.1'
  implementation 'fr.acinq.eclair:eclair-core_2.11:0.4.13-android'
  // database orm
  implementation 'org.greenrobot:greendao:3.2.2'
  // required for greendao encryption, disabled for now
  implementation 'net.zetetic:android-database-sqlcipher:3.5.6'
  // qr codes
  implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
  // events
  implementation 'org.greenrobot:eventbus:3.1.1'
  // http client
  testImplementation 'junit:junit:4.13.2'
  androidTestImplementation('com.typesafe.akka:akka-testkit_2.11:2.3.14') {
    exclude group: 'org.scala-lang', module: 'scala-library'
  }
  implementation "androidx.core:core-ktx:1.3.2"
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
