Java Resources on Android

Overview

Chrome 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.
  • content/public/android/java/res - Java resources available within content and anything that depends on content
  • chrome/android/java/res - Java resources available within chrome and anything that depends on chrome
  • ui/android/java/res - Java resources available within ui and anything that depends on ui
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 packaged

While 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 gyp

To 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' ],
},

Android chromium 1的更多相关文章

  1. Android Chromium WebView学习启动篇

    Android从4.4起提供基于Chromium实现的WebView.此前WebView基于WebKit实现.WebKit提供网页解析.布局和绘制以及JS执行等基础功能.Chromium在WebKit ...

  2. Android chromium 2

    Overview JNI (Java Native Interface) is the mechanism that enables Java code to call native function ...

  3. 35 Top Open Source Companies

    https://www.datamation.com/open-source/35-top-open-source-companies-1.html If you think of open sour ...

  4. DevTools 实现原理与性能分析实战

    一.引言 从 2008 年 Google 释放出第一版的 Chrome 后,整个 Web 开发领域仿佛被注入了一股新鲜血液,渐渐打破了 IE 一家独大的时代.Chrome 和 Firefox 是 W3 ...

  5. Ubuntu下编译Chromium for Android

    转自:http://blog.csdn.net/fsz521/article/details/18036835 下源码git clone https://chromium.googlesource.c ...

  6. 理解WebKit和Chromium: 调试Android系统上的Chromium

    转载请注明原文地址:http://blog.csdn.net/milado_nju 1. Android上的调试技术 在Android系统上,开发人员能够使用两种不同的语言来开发应用程序,一种是Jav ...

  7. chromium for android v34 2dcanvas硬件渲染实现分析

    这篇接着上一篇2dcanvas硬件绘制,分析保存绘制结果的texture被合成到on screen framebuffer上的过程. 1.webkit为canvas元素相应的render树节点Rend ...

  8. Chromium on Android: Android在系统Chromium为了实现主消息循环分析

    总结:刚开始接触一个Chromium on Android时间.很好奇Chromium主消息循环是如何整合Android应用. 为Android计划,一旦启动,主线程将具有Java消息层循环处理系统事 ...

  9. 理解WebKit和Chromium: Android 4.4 上的Chromium WebView

    转载请注明原文地址:http://blog.csdn.net/milado_nju ## 概述 相信读者已经注意到了,在最新的Android 4.4 Kitkat版本中,原本基于Android Web ...

随机推荐

  1. bzoj4519: [Cqoi2016]不同的最小割(分治最小割)

    4519: [Cqoi2016]不同的最小割 题目:传送门 题解: 同BZOJ 2229 基本一样的题目啊,就最后用set记录一下就ok 代码: #include<cstdio> #inc ...

  2. 去除iframe滚动条1

    主页面的IFRAME中添加:scrolling="yes" 子页面程序代码: 让竖条消失: <body style='overflow:scroll;overflow-x:a ...

  3. poj--3984--迷宫问题(bfs+路径记录)

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status D ...

  4. BZOJ 3166 set+可持久化trie树(OR 莫队)

    思路: 1.找次大值 我们不妨设当前点是次大的 那这段区间为 左边第二个比它大的点的坐标+1 和右边第二个比它大的点的坐标-1 2.用可持久化trie树找异或最大值 也可以用莫队 //By Siriu ...

  5. ECharts 在winform中使用(访问JS)

    ECharts 是百度的一个开源chart 数据统计库,采用html5 + js 编程方式. 有比较好的动态效果,功能很强大.能做出酷弦的效果. ECharts 一般用于web 开发.但winform ...

  6. SVN Commit报错 svn: E155037: Previous operation has not finished; run 'cleanup' if it was interrupted

    svn commit 文件出错 svn: E155037: Commit failed (details follow): svn: E155037: Previous operation has n ...

  7. 你不知道的JavaScript(九)switch语句

    在c/c++.java这些强类型的语言中switch语句的表达式和case分支中的条件值都只能是char类型或整数.JS的switch语句有些不同,它可以是JS中的任意一种类型,这一点有些朋友可能并没 ...

  8. JavaScript学习——使用JS完成省市二级联动

    1.我们希望在注册页面中添加一个字段(籍贯),当用户选择一个具体的省份,在后面的下拉列表中动态加载该省份下所有的城市.显示的效果如下: 2.步骤分析: 第一步:确定事件(onchange)并为其绑定一 ...

  9. CDR都特价了,你还用破解版?

    目前,CDR X6特价活动,从18的年的元旦一直持续到现在,真可谓是痛快淋漓,大喜若狂,但是,似乎好像是....这么强有力的活动马上就要告一段落了,因为限量1000 套的抢购要卖!完!了!难不难过,痛 ...

  10. ICA(独立成分分析)笔记

    ICA又称盲源分离(Blind source separation, BSS) 它假设观察到的随机信号x服从模型,其中s为未知源信号,其分量相互独立,A为一未知混合矩阵. ICA的目的是通过且仅通过观 ...