apply plugin: 'com.android.application'

//!!QiyuApi
project.ext.QiyuNativeSDK   = '../../../QiyuNativeSDK/Lib'

android {
    compileSdkVersion 30
    buildToolsVersion '30.0.0'
    ndkVersion '22.1.7171670'

    defaultConfig {
        applicationId  'com.sample.moreteapots'
        minSdkVersion   26//21
        targetSdkVersion 28
        ndk {
            abiFilters 'arm64-v8a'//abiFilters 'armeabi-v7a', 'arm64-v8a','x86', 'x86_64'
        }
        externalNativeBuild {
            cmake {
                arguments '-DANDROID_TOOLCHAIN=clang',
                          '-DANDROID_STL=c++_static'
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled = false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                          'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            version '3.18.1'
            path 'src/main/cpp/CMakeLists.txt'
        }
    }

    //!!QiyuApi
    repositories {
        flatDir {
            dirs project.ext.QiyuNativeSDK
        }
    }
    packagingOptions {
        //resources.excludes.add("META-INF/*")
        jniLibs.useLegacyPackaging = true//PackagingOptions.jniLibs.useLegacyPackaging should be set to true because android:extractNativeLibs is set to "true" in AndroidManifest.xml.
    }
    signingConfigs{
        release {
            storeFile file("more-teapots.jks")
            storePassword "mmmmmm"
            keyAlias "more-teapots"
            keyPassword "mmmmmm"
        }
     }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    
    //!!QiyuApi
    debugImplementation(name: 'sxrApi-v8a-debug', ext: 'aar')
    releaseImplementation(name: 'sxrApi-v8a-release', ext: 'aar')
    //
    debugImplementation(name: 'qiyivrsdkcore-v8a-debug', ext: 'aar')
    releaseImplementation(name: 'qiyivrsdkcore-v8a-release', ext: 'aar')
    //
    debugImplementation(name: 'qiyuapi-v8a-debug', ext: 'aar')
    releaseImplementation(name: 'qiyuapi-v8a-release', ext: 'aar')
}

//!!QiyuApi //! all .so are in .QiyuNativeSDK
android.buildTypes.all { theBuildType ->
    task ("extractSxrSo${theBuildType.name}") {
        tasks.whenTaskAdded { task ->
            if( task.name.startsWith("externalNativeBuild") && task.name.endsWith(theBuildType.name.substring(1))) {
                task.dependsOn 'extractSxrSo' + theBuildType.name
            }
        }
        doLast {
            copy {
                from zipTree(project.ext.QiyuNativeSDK + "/sxrApi-v8a-" + theBuildType.name + ".aar")
                into ".QiyuNativeSDK/" + theBuildType.name
                include "jni/**/*.so"
            }
            copy {
                from zipTree(project.ext.QiyuNativeSDK + "/qiyivrsdkcore-v8a-" + theBuildType.name + ".aar")
                into ".QiyuNativeSDK/" + theBuildType.name
                include "jni/**/*.so"
            }
            copy {
                from zipTree(project.ext.QiyuNativeSDK + "/qiyuapi-v8a-" + theBuildType.name + ".aar")
                into ".QiyuNativeSDK/" + theBuildType.name
                include "jni/**/*.so"
            }
        }
    }
}