問題 module之間無法直接引用R文件袱蜡。
android 不能直接引用module資源
例如
A module com.test.a
B module com.test.b
a module 已經(jīng)引用Bmodule
但是代碼中不能直接調(diào)用 R.layout.B
需要 com.test.b.R.layout.B
主要原因是Android Studio Arctic Fox 新版本新建工程,gradle.properties默認(rèn)會加一行參數(shù)
···
android.nonTransitiveRClass=true
···
這是官方說明
Enables namespacing of each library's R class so that its R class includes only the
resources declared in the library itself and none from the library's dependencies,
thereby reducing the size of the R class for that library
啟用每個庫的R類的名稱空間,以便其R類僅包含
在庫本身中聲明的資源邮丰,而沒有來自庫依賴項的資源拆挥,
從而減少了該庫的R類的大小
郭霖
Android Studio 新特性詳解
https://mp.weixin.qq.com/s/ouI2wD2hjmd02w3DQCgm7Q
支持非傳遞 R 類
另一個與構(gòu)建相關(guān)的功能范嘱,是對非傳遞 R 類的支持趣效。為了演示這一功能,我切換到了一個更大的項目——k-9 郵件應(yīng)用。我們首先點擊 "Refactor"乌叶,然后選擇 "Migrate to Non-Transitive R Classes"盆偿。此操作將分析整個項目,找到所有引用資源的源文件准浴,并將它們重新編寫為項目本地文件事扭,與此同時還會在 gradle.properties 中添加 android.nonTransitiveRClass=true 來開啟構(gòu)建系統(tǒng)中的特定設(shè)置。這將使構(gòu)建能夠跳過大量的資源合并乐横,從而有助于提高性能求橄。如果您的項目中包含大量的模塊和資源,強烈建議您嘗試這一功能葡公。