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

移除华为SDK依赖后出现Android资源链接失败问题求助

移除所有华为依赖后出现Android资源链接错误(dimen/margin_m未找到)

问题背景

已完成以下操作:

  • 删除项目类文件中所有华为相关代码
  • 禁用华为相关插件及仓库

保留至少一个华为依赖时编译无报错,完全移除所有华为依赖后,触发AAPT资源链接错误:

AGPBI: {"kind":"error","text":"Android resource linking failed","sources":[{"file":"/Users/mihail/1.Projects/demo/app/src/main/res/layout/filter_checked_card.xml","position":{"startLine":1}}],"original":"/Users/mihail/1.Projects/demo/app/src/main/res/layout/filter_checked_card.xml:2: AAPT: error: resource dimen/margin_m (aka demo.ua:dimen/margin_m) not found.\n    ","tool":"AAPT"}

涉及的华为依赖列表(已全部注释禁用):

//Huawei SDK
//    implementation 'com.huawei.agconnect:agconnect-core:1.3.2.301'
//    implementation 'com.huawei.hms:push:4.0.1.300'
//    implementation 'com.huawei.hms:maps:4.0.0.301'
//    implementation 'com.huawei.hms:location:4.0.2.300'
//    implementation 'com.huawei.hms:hianalytics:4.0.3.300'
//    implementation 'com.huawei.agconnect:agconnect-crash:1.2.1.300'
//    implementation 'com.huawei.agconnect:agconnect-remoteconfig:1.3.2.301'

解决方案

  • 手动添加缺失的维度资源
    打开项目app/src/main/res/values/dimens.xml(无此文件则新建),添加margin_m的定义,数值可根据项目设计规范调整:

    <dimen name="margin_m">16dp</dimen>
    
  • 替换布局中的资源引用
    打开filter_checked_card.xml文件,找到引用@dimen/margin_m的位置,直接替换为项目中已存在的同类型维度资源(比如@dimen/margin_medium),无需新增资源。

  • 清理缓存后重新构建
    执行Gradle清理命令:

    ./gradlew clean
    

    之后重新编译项目,消除缓存导致的资源识别问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 04:18:13