apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.android'

android {
    namespace 'com.hisharp.gstreamer_player'
    ndkVersion "21.3.6528147"

    compileSdk 33

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 33

        externalNativeBuild {
            ndkBuild {
                def gstRoot

                if (project.hasProperty('gstAndroidRoot'))
                    gstRoot = project.gstAndroidRoot
                else
                    gstRoot = System.env.GSTREAMER_ROOT_ANDROID

                if (gstRoot == null)
                    throw new GradleException('GSTREAMER_ROOT_ANDROID must be set, or "gstAndroidRoot" must be defined in your gradle.properties in the top level directory of the unpacked universal GStreamer Android binaries')

                arguments "NDK_APPLICATION_MK=jni/Application.mk",
                        "GSTREAMER_JAVA_SRC_DIR=src",
                        "GSTREAMER_ROOT_ANDROID=$gstRoot",
                        "GSTREAMER_ASSETS_DIR=src/assets"

                targets "gst_player"

                // All archs except MIPS and MIPS64 are supported
                abiFilters  'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            sourceSets {
                main {
                    manifest.srcFile 'AndroidManifest.xml'
                    java.srcDirs = ['src']
                    resources.srcDirs = ['src']
                    aidl.srcDirs = ['src']
                    renderscript.srcDirs = ['src']
                    res.srcDirs = ['res']
                    assets.srcDirs = ['assets']
                }
            }
        }
    }

    externalNativeBuild {
        ndkBuild {
            path 'jni/Android.mk'
        }
    }
    buildFeatures {
        renderScript true
        aidl true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = '17'
    }
}

afterEvaluate {
    if (project.hasProperty('compileDebugJavaWithJavac'))
        project.compileDebugJavaWithJavac.dependsOn 'externalNativeBuildDebug'
    if (project.hasProperty('compileReleaseJavaWithJavac'))
        project.compileReleaseJavaWithJavac.dependsOn 'externalNativeBuildRelease'
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.core:core-ktx:1.10.1'
    testImplementation 'junit:junit:4.13.2'
    //implementation 'androidx.appcompat:appcompat:1.6.0'
}
