遇到这个问题我也是比较纳闷、为什么纳闷呢、我来说说我的场景~
本人开发的是多人项目、也算是个老项目、各种SDK、buildTool 相对都比较低,
今天突然接到一个新的任务、单独做个小工具
于是新开了一个工程、此时在引用库的时候都把版本号调到最大(Android Studio 3.3.1 当某些引入库有新版本时会标黄,对于有洁癖的我习惯升级版本)
因为是新项目嘛、倒是顺风顺水非常happy 的完成了~
当我要回归老项目开发时、打开工程编译时出现以下问题:
error: resource style/TextAppearance.Compat.Notification.Info (aka{packageId}.test:style/TextAppearance.Compat.Notification.Info) not found.
error: resource style/TextAppearance.Compat.Notification.Info(aka{packageId}.test:style/TextAppearance.Compat.Notification.Info) not found.
error: resource style/TextAppearance.Compat.Notification.Info(aka{packageId}.test:style/TextAppearance.Compat.Notification.Info) not found.
error: resource
style/TextAppearance.Compat.Notification (aka {packageId}.test:style/TextAppearance.Compat.Notification) not found.
error: resource
style/TextAppearance.Compat.Notification (aka {packageId}.test:style/TextAppearance.Compat.Notification) not found.
error: resource
style/TextAppearance.Compat.Notification (aka {packageId}.test:style/TextAppearance.Compat.Notification) not found.
error: resource
style/TextAppearance.Compat.Notification.Time (aka{packageId}.test:style/TextAppearance.Compat.Notification.Time) not found.
error: resource
style/TextAppearance.Compat.Notification.Time (aka {packageId}.test:style/TextAppearance.Compat.Notification.Time) not found.
error: resource
style/TextAppearance.Compat.Notification.Time (aka {packageId}.test:style/TextAppearance.Compat.Notification.Time) not found.
error: resource
style/TextAppearance.Compat.Notification.Title (aka {packageId}.test:style/TextAppearance.Compat.Notification.Title) not found.
error: resource
style/TextAppearance.Compat.Notification.Title (aka {packageId}.test:style/TextAppearance.Compat.Notification.Title) not found.
error: resource
style/TextAppearance.Compat.Notification.Title (aka {packageId}.test:style/TextAppearance.Compat.Notification.Title) not found.
error: failed linking references.
AAPT2 error: check logs for details
报的是:style/TextAppearance.Compat.Notification.Info not found.
更奇怪的是我的项目里面没有引用到这个sytle呀!!!
经过各种搜索、查找后发现、这个style是sdk里面的、而且是 sdk 27版本以后才有的
27版本之前:
android:textAppearance="@style/TextAppearance.AppCompat.Notification"
27版本之后(包含):
android:textAppearance="@style/TextAppearance.Compat.Notification"
我的工程没用到27版本、他却报了27版本之后的错误、经过一番思考后可能是因为制作新项目引入27版本导致的
于是我到 C:\Users\用户名.gradle\caches 清空、重新打开项目、问题完美的解决了!!
总结:一般报错AAPT2 error: check logs for details,其实问题根源并是不AAPT2、而是你的项目中有某些资源ID找不到引用了,一定要仔细查看错误日志、找到问题根本、如果你的查找方向是AAPT2、那你就入坑了~