You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maven无法解析play-services-location AAR依赖问题求助

解决Maven优先查找AAR而非JAR的配置问题

你的问题核心在于Maven默认会优先检索JAR格式的依赖,但Google Play Services组件均以AAR格式发布。要让Maven正确识别并加载AAR依赖,你可以按照以下步骤调整配置:

1. 引入Android Maven插件(关键前提)

Maven原生不支持AAR格式,必须借助android-maven-plugin扩展Maven的构件处理能力。在pom.xml的build/plugins节点下添加该插件:

<build>
  <plugins>
    <plugin>
      <groupId>com.simpligility.maven.plugins</groupId>
      <artifactId>android-maven-plugin</artifactId>
      <version>4.6.0</version>
      <extensions>true</extensions>
      <configuration>
        <sdk>
          <platform>29</platform> <!-- 根据你的项目实际SDK版本调整 -->
        </sdk>
      </configuration>
    </plugin>
  </plugins>
</build>

2. 明确指定依赖类型为AAR

在play-services-location的依赖配置中,添加<type>aar</type>,告诉Maven该依赖的格式是AAR而非默认的JAR:

<dependency>
  <groupId>com.google.android.gms</groupId>
  <artifactId>play-services-location</artifactId>
  <version>17.0.0</version>
  <type>aar</type>
  <scope>compile</scope>
</dependency>

3. 优化仓库配置(可选但推荐)

你当前配置的https://maven.google.com已永久重定向到https://dl.google.com/dl/android/maven2/,可以直接更新仓库URL以避免重定向带来的潜在问题:

<repositories>
  <repository>
    <id>google-remote-repo</id>
    <name>Google Maven Repository</name>
    <url>https://dl.google.com/dl/android/maven2/</url>
  </repository>
</repositories>

4. 清理缓存并重新构建

本地仓库可能缓存了之前失败的依赖解析记录,执行以下命令强制更新并重新构建:

mvn clean install -U

完成以上操作后,Maven就会主动检索并下载play-services-location的AAR文件,解决构建失败的问题。

补充:AAR是Android专属的构件格式,包含代码、资源、清单等Android库所需的完整内容,这也是Google Play Services组件选择该格式的原因,必须通过Android Maven插件让Maven支持这种格式。

内容的提问来源于stack exchange,提问作者morpheus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:38:25