apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'

android {
    compileSdkVersion 35
    buildToolsVersion "33.0.3"
    namespace "com.driver.igotrip"
    packagingOptions {
        jniLibs {
            useLegacyPackaging true
        }
        exclude 'META-INF/*'
        exclude 'META-INF/NOTICE' // will not include NOTICE file
        exclude 'META-INF/LICENSE' // will not include LICENSE file
        exclude 'META-INF/INDEX.LIST' // will not include INDEX.LIST file
    }

    signingConfigs {
        config {
            keyAlias 'igotrip'
            keyPassword 'igotrip'
            storeFile file('igotrip.jks')
            storePassword 'igotrip'
        }
    }

    defaultConfig {
        applicationId "com.driver.goposttrip"
        minSdkVersion 23
        targetSdkVersion 35
        versionCode 54
        versionName "1.7.5"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        manifestPlaceholders = [
                JPUSH_PKGNAME : applicationId,
                JPUSH_APPKEY : "1e5708b2168543a15bfb72ef", //JPush 上注册的包名对应的 Appkey.
                JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
                MAPS_API_KEY: "AIzaSyBOlo_xsCKz78o1B869fvRfasSX3B4okEU"  // 替换为实际的API Key
        ]
    }
    //别名 okTripDriver 密码 111111

    buildTypes {
        release {
            minifyEnabled false
            zipAlignEnabled true
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            zipAlignEnabled true
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true
        // Sets Java compatibility to Java 8
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"  // 与上面保持一致
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

// 关键：添加分辨率策略，强制优先使用 play-services-maps 的类
    configurations.all {
        resolutionStrategy {
            // 强制所有依赖中，com.google.android.gms:play-services-maps 优先使用 18.0.2 版本
            force 'com.google.android.gms:play-services-maps:18.0.2'
            // 强制地图模型类优先使用 play-services-maps-model:18.0.2
            force 'com.google.android.gms:play-services-maps-model:18.0.2'
        }
    }
// 关键1：过滤 navigation 中重复的地图类文件（核心去重）
    packagingOptions {
        // 排除 navigation 中 com/google/android/gms/maps 包下的所有类文件
        exclude 'com/google/android/gms/maps/**/*.class'
        exclude 'com/google/android/gms/maps/model/**/*.class'
        exclude 'com/google/android/gms/maps/internal/**/*.class'
        // 排除重复的资源文件（若有）
        exclude 'com/google/android/gms/maps/mapbox/**/*.png'
        exclude 'com/google/android/gms/maps/mapbox/**/*.xml'
    }

    buildFeatures {
        buildConfig = true  // 显式启用 BuildConfig
    }

}
// 在文件末尾添加
afterEvaluate {
    android.applicationVariants.all { variant ->
        def variantName = variant.name
        // 找到对应变体的bundle任务
        def bundleTask = tasks.findByName("bundle${variantName.capitalize()}")
        if (bundleTask != null) {
            bundleTask.doLast {
                // 输出目录
                def outputDir = file("${rootDir}/app/${variantName}/")
                if (outputDir.exists()) {
                    outputDir.listFiles().each { file ->
                        if (file.name.endsWith('.aab')) {
                            // 获取当前时间戳
                            def timestamp = new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("GMT+08"))

                            // 构建新的文件名
                            def newName = file.name.replace("app-${variantName}", "GoPost-driver-${variant.versionName}-${variant.buildType.name}-${timestamp}")

                            // 重命名文件
                            def newFile = new File(file.parentFile, newName)

                            if (file.renameTo(newFile)) {
                                println "✅ 文件重命名成功: ${file.name} -> ${newFile.name}"
                                println "📁 文件路径: ${newFile.absolutePath}"
                            } else {
                                println "❌ 文件重命名失败: ${file.name}"
                            }
                        }
                    }
                } else {
                    println "⚠️ 目录不存在: ${outputDir.absolutePath}"
                }
            }
        }
        // 找到对应变体的package任务
        def packageTask = tasks.findByName("package${variantName.capitalize()}")
        if (packageTask != null) {
            packageTask.doLast {
                // 输出目录
                def outputDir = file("${rootDir}/app/${variantName}/")
                if (outputDir.exists()) {
                    outputDir.listFiles().each { file ->
                        if (file.name.endsWith('.apk')) {
                            // 获取当前时间戳
                            def timestamp = new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("GMT+08"))

                            // 构建新的文件名
                            def newName = file.name.replace("app-${variantName}", "GoPost-driver-${variant.versionName}-${variant.buildType.name}-${timestamp}")

                            // 重命名文件
                            def newFile = new File(file.parentFile, newName)

                            if (file.renameTo(newFile)) {
                                println "✅ 文件重命名成功: ${file.name} -> ${newFile.name}"
                                println "📁 文件路径: ${newFile.absolutePath}"
                            } else {
                                println "❌ 文件重命名失败: ${file.name}"
                            }
                        }
                    }
                } else {
                    println "⚠️ 目录不存在: ${outputDir.absolutePath}"
                }
            }
        }
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
}
// 强制统一 play-services-maps 版本
configurations.all {
    resolutionStrategy {
        force 'com.google.android.gms:play-services-maps:18.0.2'
    }
}

dependencies {
    implementation 'androidx.activity:activity-ktx:1.8.0'
    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
    implementation "com.facebook.soloader:soloader:0.12.1"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.0"
    implementation 'com.tencent.mm.opensdk:wechat-sdk-android:6.8.34'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.activity:activity:1.8.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    implementation project(path: ':xldUtils')
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'com.mobsandgeeks:android-saripaar:2.0.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'com.github.zackratos.ultimatebar:ultimatebar3:3.1.1'

    implementation 'org.greenrobot:eventbus:3.1.1'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
    implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.github.xuexiangjys:XUI:1.1.3'
    implementation 'pub.devrel:easypermissions:1.3.0'
    implementation 'liji.library.dev:citypickerview:5.2.1'
    implementation 'com.ypx.yimagepicker:androidx:3.1.4'
    implementation project(path: ':rxnetty')
    implementation 'com.wang.avi:library:2.1.3'
    implementation 'com.google.zxing:core:3.3.0'
//    implementation 'cn.jiguang.sdk:jpush:6.0.2'  // 此处以JPush 3.6.6 版本为例。
//    implementation 'cn.jiguang.sdk:jcore:5.3.1'  // 此处以JCore 2.3.8 版本为例。
//    implementation 'com.tencent.bugly:crashreport:latest.release'
//    implementation ('com.google.android.gms:play-services-maps:18.0.2')
//    {
//        exclude group: 'com.google.android.gms.maps.CameraUpdate', module: 'play-services-basement'
//    }
//    implementation 'com.google.android.libraries.places:places:2.6.0'
    implementation 'com.facebook.android:facebook-share:12.2.0' //脸书分享
    implementation 'com.twitter.sdk.android:twitter:3.1.1'

    //implementation 'com.google.android.libraries.navigation:navigation:6.0.0'
   // implementation 'com.google.android.libraries.mapsplatform.transportation:transportation-driver:6.0.0'
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_nio:2.0.3'


    implementation 'com.google.auth:google-auth-library-oauth2-http:1.19.0'
    implementation 'com.google.cloud:google-cloud-texttospeech:2.46.0'

    // 保留单独的地图库
  //  implementation 'com.google.android.gms:play-services-maps:18.0.2'
    // 导航相关依赖
    implementation 'com.google.android.libraries.navigation:navigation:6.0.0'
    implementation 'com.google.android.libraries.mapsplatform.transportation:transportation-driver:6.0.0'


    //implementation ('com.google.android.gms:play-services-maps:18.0.2')
    // 导航SDK（核心依赖）
   // implementation 'com.google.android.libraries.navigation:navigation:6.0.0'
    // 可选：导航语音播报依赖
   // implementation 'com.google.android.libraries.navigation:navigation-voice:6.0.0'

    // 可选：定位服务（如需显示用户位置）
  //  implementation 'com.google.android.gms:play-services-location:21.0.1'

    // 2. 导航SDK核心依赖（关键！之前可能只加了这行，缺少其他）
   /* implementation ('com.google.android.gms:play-services-maps:18.0.2')
    {
        // 排除 com.google.android.gms.maps 包下的所有类（覆盖所有重复类）
        exclude group: 'com.google.android.gms', module: 'play-services-maps'
        // 额外排除内置的重复地图模型类（兜底，避免漏网之鱼）
        exclude group: 'com.google.android.gms', module: 'play-services-maps-model'
    }
    implementation 'com.google.android.libraries.navigation:navigation:6.0.0'
    implementation 'com.google.android.libraries.mapsplatform.transportation:transportation-driver:6.0.0'*/
    // 4. 可选：导航语音播报（如果需要语音引导）
   // implementation 'com.google.android.libraries.navigation:navigation-voice:6.1.0'


    //cameraX
    implementation "androidx.camera:camera-core:1.4.2"
    implementation "androidx.camera:camera-camera2:1.4.2"
    implementation "androidx.camera:camera-lifecycle:1.4.2"
    implementation "androidx.camera:camera-view:1.4.2"

    implementation 'top.zibin:Luban:1.1.8'


    implementation project(path: ':easyfloat')

    //友盟
//    implementation 'com.umeng.umsdk:share-core:7.3.7'
//    implementation 'com.umeng.umsdk:common:9.8.9'//必选
//    implementation 'com.umeng.umsdk:asms:1.8.7.2' //必选
    //微信
//    implementation 'com.umeng.umsdk:share-wx:7.3.7'
}
