fix(semi-icons): 用框架属性替代未定义的 ?attr/colorControlNormal - #35
Open
Windsland52 wants to merge 1 commit into
Open
Windsland52 wants to merge 1 commit into
Windsland52 wants to merge 1 commit into
Conversation
484 个图标 drawable 的 android:tint 引用的是应用命名空间的
colorControlNormal,但本模块既不依赖 appcompat 也没定义该属性,AGP 对库
模块单独做资源链接时必然失败:
:semi-icons:verifyReleaseResources
AAPT: error: resource attr/colorControlNormal
(aka com.aliothmoon.maafw.semiicons:attr/colorControlNormal) not found
app 层因为依赖 appcompat、主题是 Theme.AppCompat.DayNight 能解析该引用,
所以 IDE / 单模块 :app:assembleRelease 一直正常,只有根目录
./gradlew assembleRelease(会命中所有模块的 assembleRelease)才会把这个
校验带进任务图,缺陷因此长期潜伏。
改用框架属性 ?android:attr/colorControlNormal:API 21 起一直存在,
minSdk 28 安全,不引入依赖,app 侧语义不变。
注意 scripts/extract_semi_icons.py 不在本仓库中,生成器需同步改为框架属性,
否则重新生成图标会复发。
Refs Aliothmoon#34
Contributor
Author
|
顺带一个跟这次修复配套的建议(不阻塞合并):仓库现在没有 CI(没有 一条命令就够,不需要 NDK / keystore / agent 运行时: # .github/workflows/library-resources.yml
name: Verify library resources
on: [push, pull_request]
jobs:
verify:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: actions/setup-java@v5
with:
java-version: "25"
distribution: temurin
- uses: android-actions/setup-android@v4
- run: ./gradlew verifyReleaseResources几点说明:
这个 PR 修的 bug 正好是这类:把 484 个图标里的1 个改回 如果暂时不想加 CI,退一步的做法是发版前手工跑一次根目录的 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #34
问题
semi-icons的 484 个 drawable 都写着:但本模块没有
dependencies {}(不依赖 appcompat),模块内也没有任何地方定义colorControlNormal。AGP 对库模块会单独做一次资源链接,此引用在库自己的资源图里解析不到,于是:在 app 层这个引用是合法的(app 依赖 appcompat),所以只要任务图里没有库模块自己的
assembleRelease,问题就完全不可见::semi-icons:verifyReleaseResources./gradlew :app:assembleRelease(IDE Build APK / Generate Signed APK)./gradlew assembleRelease(根目录,CI 用法)改动
484 个 drawable 的 tint 换成框架属性:
android:attr/colorControlNormal自 API 21 起存在,minSdk 28 安全;不引入新依赖,保持"纯资源模块"的定位。可替代方案是给模块加implementation(libs.androidx.appcompat),但会把 appcompat 拖进一个只放图标的模块,故未采用。验证
./gradlew :semi-icons:verifyReleaseResources→BUILD SUCCESSFUL./gradlew clean assembleRelease(根目录,即 CI 的命令)→BUILD SUCCESSFUL,verifyReleaseR8Keeps通过(8 个关键类保留),arm64-v8a release APK 正常产出aapt2 dump xmltree对比同一图标:旧包 tint 解析为?0x7f03005d(appcompat 的colorControlNormal),修改后为?0x01010429(android:attr/colorControlNormal),AppCompat 主题下取值一致需要注意
semi-icons/build.gradle.kts注释里写着资源由scripts/extract_semi_icons.py生成,但该脚本不在本仓库中,生成器需要同步改为框架属性,否则重新生成图标会把这个引用写回来、问题复发。(另外建议:本问题只在根目录
assembleRelease下暴露,如果 release 校验想更早发现,可以考虑在 CI 里跑库模块的assembleRelease而不只是:app:assembleRelease。)