group = "com.yunqiinnovation.location_service" version = "1.0-SNAPSHOT" buildscript { ext.kotlin_version = "2.1.0" repositories { google() mavenCentral() } dependencies { classpath("com.android.tools.build:gradle:8.7.3") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") } } allprojects { repositories { google() mavenCentral() } } apply plugin: "com.android.library" apply plugin: "kotlin-android" // 搜索 SDK 和导航 SDK 各带一份 AMapUtilCoreApi,导航那份是超集。 // 直接 implementation search 会在打包时 Duplicate class。这里先剥掉那两个类,运行时用导航 SDK 的。 configurations { amapSearch } dependencies { amapSearch('com.amap.api:search:9.7.1') } def stripAmapSearchJar = tasks.register("stripAmapSearchJar") { def cfg = configurations.amapSearch inputs.files(cfg) def out = layout.buildDirectory.file("amap/search-stripped.jar") outputs.file(out) doLast { def jar = cfg.singleFile def dest = out.get().asFile dest.parentFile.mkdirs() def drop = [ "com/amap/apis/utils/core/api/AMapUtilCoreApi.class", "com/amap/apis/utils/core/api/NetProxy.class", ] as Set def zin = new java.util.zip.ZipFile(jar) dest.withOutputStream { os -> def zout = new java.util.zip.ZipOutputStream(os) zin.entries().each { entry -> if (drop.contains(entry.name)) return zout.putNextEntry(new java.util.zip.ZipEntry(entry.name)) if (!entry.isDirectory()) { zin.getInputStream(entry).withCloseable { ins -> byte[] buf = new byte[8192] int n while ((n = ins.read(buf)) > 0) { zout.write(buf, 0, n) } } } zout.closeEntry() } zout.close() } zin.close() } } android { namespace = "com.yunqiinnovation.location_service" compileSdk = 35 compileOptions { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 } kotlinOptions { jvmTarget = JavaVersion.VERSION_11 } sourceSets { main.java.srcDirs += "src/main/kotlin" test.java.srcDirs += "src/test/kotlin" } defaultConfig { minSdk = 21 } // ✅ dependencies 应该写在这里(android {} 外面) dependencies { implementation('com.amap.api:navi-3dmap:latest.integration') // 定位 SDK 在部分机型(华为无 GMS)只回坐标和市名,路名要单独走搜索 SDK 的逆地理。 implementation(files(stripAmapSearchJar)) testImplementation("org.jetbrains.kotlin:kotlin-test") testImplementation("org.mockito:mockito-core:5.0.0") } testOptions { unitTests.all { useJUnitPlatform() testLogging { events "passed", "skipped", "failed", "standardOut", "standardError" outputs.upToDateWhen {false} showStandardStreams = true } } } }