apply plugin: 'com.android.library'

group = 'expo.modules.gaodemap'
version = '2.2.34'

def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
apply from: expoModulesCorePlugin
applyKotlinExpoModulesCorePlugin()
useCoreDependencies()
useExpoPublishing()

// If you want to use the managed Android SDK versions from expo-modules-core, set this to true.
// The Android SDK versions will be bumped from time to time in SDK releases and may introduce breaking changes in your module code.
// Most of the time, you may like to manage the Android SDK versions yourself.
def useManagedAndroidSdkVersions = false
if (useManagedAndroidSdkVersions) {
  useDefaultAndroidSdkVersions()
} else {
  buildscript {
    // Simple helper that allows the root project to override versions declared by this library.
    ext.safeExtGet = { prop, fallback ->
      rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
    }
  }
  project.android {
    compileSdkVersion safeExtGet("compileSdkVersion", 36)
    defaultConfig {
      minSdkVersion safeExtGet("minSdkVersion", 24)
      targetSdkVersion safeExtGet("targetSdkVersion", 36)
    }
  }
}

logger.warn("[expo-gaode-map] Thank you for using expo-gaode-map ❤️")
logger.warn("[expo-gaode-map] If you enjoy using expo-gaode-map, please consider sponsoring this project: https://github.com/TomWq")

android {
  namespace "expo.modules.gaodemap"
  defaultConfig {
    versionCode 1
    versionName "2.2.34"
    externalNativeBuild {
      cmake {
        cppFlags "-std=c++17"
      }
    }
  }
  externalNativeBuild {
    cmake {
      path "src/main/cpp/CMakeLists.txt"
    }
  }
  lintOptions {
    abortOnError false
  }
}



dependencies {
    // 高德地图组合 SDK：地图 + 定位 + 搜索。
    def customSdkPath = null
    println "ExpoGaodeMap: Checking for custom SDK property in rootProject: ${rootProject.name}"
    if (rootProject.hasProperty("EXPO_GAODE_MAP_CUSTOM_SDK_PATH")) {
        customSdkPath = rootProject.property("EXPO_GAODE_MAP_CUSTOM_SDK_PATH")
        println "ExpoGaodeMap: Found custom SDK path property: ${customSdkPath}"
    } else {
        println "ExpoGaodeMap: No custom SDK path property found."
    }

    if (customSdkPath) {
        def sdkFile = rootProject.file(customSdkPath)
        if (!sdkFile.exists()) {
            // Try to find the file relative to the project root (parent of android folder)
            sdkFile = new File(rootProject.projectDir.parentFile, customSdkPath)
        }

        if (sdkFile.exists()) {
            println "ExpoGaodeMap: Using custom Map SDK from ${sdkFile.absolutePath}"
            implementation files(sdkFile)
        } else {
            throw new FileNotFoundException("ExpoGaodeMap: Could not find custom SDK at ${customSdkPath}. Please check your customMapSdkPath configuration.")
        }
    } else {
        // 10.1.600 is the last Android 3D map SDK line that supports offline
        // map downloads without the separate 11.x offline-download permission.
        implementation('com.amap.api:3dmap-location-search:10.1.700_loc6.5.1_sea9.7.4')
    }
}
