plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
}

android {
    namespace = "com.github.fv2ray.fv2ray"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.github.fv2ray.fv2ray"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = flutter.minSdkVersion
        // targetSdk = flutter.targetSdkVersion
        // targetSdk = 28
        versionCode = flutter.versionCode
        versionName = flutter.versionName

        ndk {
			abiFilters "armeabi-v7a", "arm64-v8a",'x86','x86_64'
		}
		externalNativeBuild {
			ndkBuild {
				arguments "APP_CFLAGS+=-DPKGNAME=com/github/fv2ray/fv2ray -ffile-prefix-map=${rootDir}=."
				arguments "APP_LDFLAGS+=-Wl,--build-id=none"
			}
		}
    }

    flavorDimensions "target"
    productFlavors {
        apilatest {
            dimension "target"
            targetSdk = flutter.targetSdkVersion
        }

        api28 {
            dimension "target"
            targetSdk = 28
        }
    }

    def keystorePropertiesFile = rootProject.file('key.properties')
    def keystoreProperties = new Properties()

    if (keystorePropertiesFile.exists()) {
        keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
    } else {
        println "No key.properties file found."
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.release
        }
        release {
            signingConfig signingConfigs.release
            // minifyEnabled false
            // shrinkResources false
            // Specify the ProGuard rules file
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    externalNativeBuild {
		ndkBuild {
			path "src/main/jni/Android.mk"
		}
	}

    lintOptions {
        disable 'ExpiredTargetSdkVersion'
    }
}

flutter {
    source = "../.."
}

dependencies {
    implementation (name:'libv2raymobile', ext:'aar')
}
