一、問題描述
今天合併代碼之後,編譯的時候出現了下面的錯誤。
C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\p_babyinfo\build\intermediates\packaged_res\debug\layout\activity_talent_account_number.xml:9: AAPT: error: resource string/baby_talent_number (aka com.xtc.watch:string/baby_talent_number) not found.
C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\p_babyinfo\build\intermediates\packaged_res\debug\layout\activity_talent_account_number.xml:17: AAPT: error: resource string/baby_talent_number_tip (aka com.xtc.watch:string/baby_talent_number_tip) not found.
error: failed linking file resources.
Command: C:\Users\000\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\24e7e61be83dabe37ccdf37a941ea750\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
C:\Android\SDK\platforms\android-28\android.jar\
--manifest\
C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
-o\
C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
-R\
@C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
--auto-add-overlay\
--java\
C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
--proguard-main-dex\
C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\legacy_multidex_aapt_derived_proguard_rules\debug\processDebugResources\manifest_keep.txt\
--custom-package\
com.xtc.watch\
-0\
apk\
--preferred-density\
xhdpi\
--output-text-symbols\
C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\symbols\debug\R.txt\
--no-version-vectors
Daemon: AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 23s
但是我找到這個佈局文件,去查看這兩個字符串資源的時候,命名都是有對應的資源的,如下所示:
二、解決問題
明明有對應的資源,爲什麼會報錯呢?
我一開始以爲是沒有clean乾淨導致的,clean了幾次都還是報這個錯。
2.1 原因
後來我發現,好像還是少了一個默認的資源。
2.2 解決問題
既然發現少了 默認的 values資源,把這個默認資源的字符串加上,即可。如下所示
再到佈局文件看 Default資源
添加好了 Default資源之後,重新編譯即可成功。
三、總結
當出現這個問題的時候,先看看有沒有添加默認的字符串資源,如果沒有添加的話,即使你添加了其他的語言的字符串資源,也是無法正常編譯的!
作者:歐陽鵬 歡迎轉載,與人分享是進步的源泉!
轉載請保留原文地址:https://blog.csdn.net/qq446282412/article/details/90758755
☞ 本人QQ: 3024665621
☞ QQ交流羣: 123133153
☞ github.com/ouyangpeng
☞ [email protected]