apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

repositories {
    mavenLocal()
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def djiKey = properties.getProperty('DJI_SDK_API_KEY')
def hereKey = properties.getProperty('HERE_KEY_APPID')
def hereToken = properties.getProperty('HERE_KEY_APPTOKEN')
def hereLic = properties.getProperty('HERE_KEY_LICENSE')
def keystorePW = properties.getProperty('KEYSTORE_PASSWD')
def keystorePath = properties.getProperty('KEYSTORE_PATH')
def keystoreAlias = properties.getProperty('KEYSTORE_ALIAS')
def mapboxKey = properties.getProperty('MAPBOX_DOWNLOADS_TOKEN')
def ftsIP = properties.getProperty('FTSIP')
def ftsAPIKey = properties.getProperty('FTSAPIKEY')
def rtmpIP = properties.getProperty('RTMPIP')
def droneName = properties.getProperty('DRONENAME')

def versionMajor = 1
def versionMinor = 4
def versionPatch = 14
def version_code = versionMajor * 10000 + versionMinor * 100 + versionPatch


android {
    compileSdkVersion 30
    buildToolsVersion '30.0.2'
    defaultConfig {
        applicationId "org.FreeTak.FreeTAKUAS"
        versionCode version_code
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"
        manifestPlaceholders = [djiKey: djiKey, hereKey: hereKey, hereToken: hereToken, hereLic: hereLic]
        buildConfigField "String", "FTSIP", ftsIP
        buildConfigField "String", "FTSAPIKEY", ftsAPIKey
        buildConfigField "String", "RTMPIP", rtmpIP
        buildConfigField "String", "DRONENAME", droneName
        buildConfigField "boolean", "RELEASE", "true" // true when making Play Store APK
        minSdkVersion 26
        targetSdkVersion 30
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        ndk {
            // On x86 devices that run Android API 23 or above, if the application is targeted with API 23 or
            // above, FFmpeg lib might lead to runtime crashes or warnings.
            abiFilters 'arm64-v8a', 'armeabi-v7a' //,'x86'
        }
    }
    signingConfigs {
        release {
            storeFile file(keystorePath)
            storePassword keystorePW
            keyAlias keystoreAlias
            keyPassword keystorePW
        }
    }
    buildTypes {
        release {
            resValue "string", "app_version", "${defaultConfig.versionName}"
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
    dexOptions {
        javaMaxHeapSize "3g"
    }
    lintOptions{
        abortOnError false
    }
    packagingOptions{
        doNotStrip "*/*/libdjivideo.so"
        doNotStrip "*/*/libSDKRelativeJNI.so"
        doNotStrip "*/*/libFlyForbid.so"
        doNotStrip "*/*/libduml_vision_bokeh.so"
        doNotStrip "*/*/libyuv2.so"
        doNotStrip "*/*/libGroudStation.so"
        doNotStrip "*/*/libFRCorkscrew.so"
        doNotStrip "*/*/libUpgradeVerify.so"
        doNotStrip "*/*/libFR.so"
        doNotStrip "*/*/libDJIFlySafeCore.so"
        doNotStrip "*/*/libdjifs_jni.so"
        doNotStrip "*/*/libsfjni.so"
        doNotStrip "*/*/libDJICommonJNI.so"
        doNotStrip "*/*/libDJICSDKCommon.so"
        doNotStrip "*/*/libDJIUpgradeCore.so"
        doNotStrip "*/*/libDJIUpgradeJNI.so"
        doNotStrip "*/*/libDJIWaypointV2Core.so"
        doNotStrip "*/*/libAMapSDK_MAP_v6_9_2.so"
        doNotStrip "*/*/libDJIMOP.so"
        doNotStrip "*/*/libDJISDKLOGJNI.so"

        pickFirst 'lib/*/libstlport_shared.so'
        pickFirst 'lib/*/libRoadLineRebuildAPI.so'
        pickFirst 'lib/*/libGNaviUtils.so'
        pickFirst 'lib/*/libGNaviMapex.so'
        pickFirst 'lib/*/libGNaviData.so'
        pickFirst 'lib/*/libGNaviMap.so'
        pickFirst 'lib/*/libGNaviSearch.so'
        pickFirst 'lib/*/libDJIFlySafeCore.so'
        pickFirst 'lib/*/libdjifs_jni.so'
        pickFirst 'lib/*/libsfjni.so'
        exclude 'META-INF/proguard/okhttp3.pro'
        exclude 'META-INF/rxjava.properties'
        exclude 'assets/location_map_gps_locked.png'
        exclude 'assets/location_map_gps_3d.png'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    aaptOptions {
        noCompress "tflite"
    }
}

project.ext.ASSET_DIR = projectDir.toString() + '/src/main/assets'

dependencies {
    implementation ('com.dji:dji-sdk:4.16', {
        /**
         * Uncomment the "library-anti-distortion" if your app does not need Anti Distortion for Mavic 2 Pro and Mavic 2 Zoom.
         * Uncomment the "fly-safe-database" if you need database for release, or we will download it when DJISDKManager.getInstance().registerApp
         * is called.
         * Both will greatly reduce the size of the APK.
         */
        exclude module: 'library-anti-distortion'
        exclude module: 'fly-safe-database'
    })

    compileOnly ('com.dji:dji-sdk-provided:4.16')

    implementation ('com.dji:dji-uxsdk:4.16', {
        exclude module: 'library-anti-distortion'
        exclude module: 'dji-sdk'
        exclude module: 'fly-safe-database'

        /**
         * Uncomment the following line to exclude amap from the app.
         * Note that Google Play Store does not allow APKs that include this library.
         */
        exclude group: 'com.amap.api'
        exclude group: 'com.mapbox.mapboxsdk'
    })

    implementation 'org.greenrobot:eventbus:3.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.annotation:annotation:1.2.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.core:core:1.3.2'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    //HERE maps
    implementation files('libs/HERE-sdk-3.15.0.aar') {

    }

    // TensorFlow Lite
    implementation 'org.tensorflow:tensorflow-lite-task-vision:0.2.0'
}
