apply plugin: 'com.android.library'

String[] ABIFILTERS = [
	"arm64-v8a",
        "armeabi-v7a",
        /*, "armeabi", "x86", "x86_64"*/
]

String PRODUCT_FLAVOR = "github" // github fdroid

String[] CMAKE_ARGUMENTS = [
        "-DANDROID_ARM_NEON=TRUE", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_PLATFORM=android-21", "-DDIII4A_PRODUCT_FLAVOR=" + PRODUCT_FLAVOR/*, "-DANDROID_STL=c++_shared"*/
]

// filter ABI
def abifilters = ABIFILTERS
if(project.properties.abifilters != null && !project.properties.abifilters.isEmpty()) {
    println "[Q3E]: Using gradle.properties ABI filters = ${project.properties.abifilters}"
    abifilters = project.properties.abifilters.split(",")
} else {
    println "[Q3E]: Using built-in ABI filters = ${Arrays.toString(abifilters)}"
}
println "[Q3E]: Build arch = " + Arrays.toString(abifilters)

// CMake options
def cmake_arguments = CMAKE_ARGUMENTS
if(project.properties.cmake_options != null && !project.properties.cmake_options.isEmpty()) {
    println "[Q3E]: Add gradle.properties CMake options = ${project.properties.cmake_options}"
    def add_options = project.properties.cmake_options.split(",")
    cmake_arguments = new String[CMAKE_ARGUMENTS.length + add_options.length]
    System.arraycopy(CMAKE_ARGUMENTS, 0, cmake_arguments, 0, CMAKE_ARGUMENTS.length)
    System.arraycopy(add_options, 0, cmake_arguments, CMAKE_ARGUMENTS.length, add_options.length)
}
println "[Q3E]: CMake arguments = " + Arrays.toString(cmake_arguments)

android {
    compileSdk project.properties.compileSdkVersion.toInteger()
    buildToolsVersion project.properties.buildToolsVersion
    ndkVersion project.properties.ndkVersion
    //compileOptions.encoding "gbk"

    defaultConfig {
        minSdkVersion project.properties.minSdkVersion.toInteger()
        targetSdkVersion project.properties.targetSdkVersion.toInteger()

        /*ndk {
            moduleName "q3eloader"
            abiFilters abifilters
        }*/
        externalNativeBuild {
            cmake {
                abiFilters abifilters
                arguments cmake_arguments
                cppFlags "-fexceptions", "-frtti"
            }
        }
        versionCode 131130411
        versionName '1.3.1.1304.12' // {DOOM3's ENGINE_VERSION}.{BUILD_NUMBER}.{Q3E's Version}

        buildConfigField "String", "PRODUCT_FLAVOR", "\"" + PRODUCT_FLAVOR + "\""
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        /*customDebugType {
            debuggable true
        }*/
    }
    sourceSets {
        main {
            jniLibs.srcDirs=['libs']
            //jni.srcDirs('src/main/jni')
            //jniLibs.srcDirs=[]
        }
    }
    externalNativeBuild {
        cmake {
            path "src/main/jni/CMakeLists.txt"
        }
        /*ndkBuild {
            path file('src/main/jni/Android.mk')
        }*/
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
//    packagingOptions {
//        doNotStrip "*/armeabi-v7a/*.so"
//        doNotStrip "*/arm64-v8a/*.so"
//    }
    buildFeatures {
        prefab true
    }
}

dependencies {
    //compile 'com.android.support:support-v4:18.+'
    // F-Droid free version comment 2 lines
    implementation files('libs/ouya-sdk.jar')
    implementation files('libs/RootTools-2.4.jar')
    // Using LTS version for lower min SDK version
    //implementation('com.arthenica:mobile-ffmpeg-min:4.4.LTS') // downed
    //implementation('com.arthenica:ffmpeg-kit-min:6.0-2.LTS') // downed
    // implementation("io.github.maitrungduc1410:ffmpeg-kit-min:6.0.0")
    // Using local ffmpeg libraries
    //api(name: 'mobile-ffmpeg-min_4_4_LTS', ext: 'aar')
    //implementation 'com.arthenica:mobile-ffmpeg-full:4.4.LTS'
    //implementation 'com.arthenica:mobile-ffmpeg-video:4.4.LTS'
    implementation 'io.github.hexhacking:xunwind:2.0.0'
}
