group 'com.example.ai_chat_assistant'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '2.1.20'
    repositories {
        maven { url file("mavenLocal") }
        google()
        mavenCentral()
         maven {
            url "https://storage.googleapis.com/download.flutter.io"
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.11.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        maven { url file("mavenLocal") }
        google()
        mavenCentral()
         maven {
            url "https://storage.googleapis.com/download.flutter.io"
        }
    }
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
    namespace 'com.example.ai_chat_assistant'


    compileSdk 33

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = "17"
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
        test.java.srcDirs += 'src/test/kotlin'
    }

    defaultConfig {
        minSdkVersion 21
        ndk {
            abiFilters "armeabi-v7a", "arm64-v8a"
        }
    }

    buildFeatures {
        dataBinding true
        viewBinding = true
    }

    // 获取配置文件
    def localProperties = new Properties()
    def localPropertiesFile = rootProject.file('local.properties')
    if (localPropertiesFile.exists()) {
        localPropertiesFile.withReader('UTF-8') {
            localProperties.load(it)
        }
    }

    // 获取flutter sdk 路径
    def flutterRoot = localProperties.getProperty('flutter.sdk')
    if (flutterRoot == null) {
        throw new GradleException("Flutter SDK not found. Define location with flutter.")
    }

    // 找到 flutter.jar 文件
    def flutterJar = new File(flutterRoot, "bin/cache/artifacts/engine/android-arm/flutter.jar")
    if (!flutterJar.exists()) {
        // 尝试其他路径
        flutterJar = new File(flutterRoot, "bin/cache/artifacts/engine/android-arm-release/flutter.jar")
    }
    if (!flutterJar.exists()) {
        // Windows 上可能在这个位置
        flutterJar = new File(flutterRoot, "bin/cache/artifacts/engine/android-x64/flutter.jar")
    }

    repositories {
        flatDir {
            dirs("libs")
        }
    }

    dependencies {
        implementation 'com.alibaba.idst:nui-release:1.0.0'
        implementation 'com.alibaba:fastjson:1.2.83'
        // 使用Flutter的官方Maven依赖
        // compileOnly 'io.flutter:flutter_embedding_debug:1.0.0-3.27.4'
        // 或者使用release版本
        // compileOnly '"io.flutter:flutter_embedding_release:1.0.0-de555ebd6cfe3e606a101b9ae45bbf5e62d4e4e1"'
//        compileOnly files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar")
        compileOnly files(files("libs/flutter.jar"))
//        implementation(files("libs/fastjson-1.1.46.android.jar"))
        // implementation(files("libs/nui-release-1.0.0.aar"))
    }
}
