Android chromium 1
For Developers > Design Documents >
Java Resources on Android
OverviewChrome for Android uses certain resources in Java code (e.g. Android layouts and associated strings or images). These resources are stored according to Android's resource directory structure within a Java root folder.
Java code can reference these resources in the normal way using a generated R class, being sure to qualify it with the correct package name.
// Use a resource from content setImageResource( org.chromium.content.R.drawable.globe_favicon); // Use a resource from chrome
setContentView( org.chromium.chrome.R.layout.month_picker ); How resources are packagedWhile compiling the Java code in content, an R.java file is generated based on the Java resources in content. This R.java contains non-final constants and is used only while compiling content (and any non-APK target that depends on content) but is not included in the content jar.
When building an APK target, such as content_shell_apk, resources are merged from content, any other dependencies, and from content shell itself. These merged resources are processed and included in the APK. Based on these resources, a new R.java is generated with the correct resource -> ID mappings. This R.java is copied into the R packages needed by each dependency (e.g. org.chromium.content.R and org.chromium.content_shell.R), and all these copies are included in the APK.
This process closely follows Android's handling of resources in library projects, where content and chrome are the "libraries", though we don't use the SDK to compile our "libraries". Hence some of the same caveats apply. In particular, two resources with the same ID cannot coexist. The resource highest in the dependency chain (e.g. in content shell) will override the others (e.g. in content).
Supporting resources in gypTo add resources to another Java root folder, add the variables has_java_resources, R_package, and R_package_relpath to the gyp target that builds that Java code. For example:
{ 'target_name': 'content_java', 'type': 'none', 'dependencies': [ ... ], 'variables': { 'package_name': 'content', 'java_in_dir': '../content/public/android/java', # Support Java resources in content 'has_java_resources': 1, 'R_package': 'org.chromium.content', 'R_package_relpath': 'org/chromium/content', }, 'includes': [ '../build/java.gypi' ], }, |
posted on 2018-11-19 19:34 huangguanyuan 阅读(169) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~