summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authornewt@chromium.org <newt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-16 20:39:20 +0000
committernewt@chromium.org <newt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-16 20:39:20 +0000
commit3ac50367e1d974176aba1b4e6d9d81e73e3d7280 (patch)
tree694ee46c9ce650184778806d47986ad111811395 /build
parente13284d0688fd1113c9e8cd51304df3b81d2b395 (diff)
downloadchromium_src-3ac50367e1d974176aba1b4e6d9d81e73e3d7280.zip
chromium_src-3ac50367e1d974176aba1b4e6d9d81e73e3d7280.tar.gz
chromium_src-3ac50367e1d974176aba1b4e6d9d81e73e3d7280.tar.bz2
Support Java resources within content.
This provides support for android-style resource folders in content and other non-apk Java targets. The AppResource hack can then be removed shortly. Details: while building a non-apk target (e.g. chromium_content.jar), we generate an R.java file with non-final constants and in the appropriate Java package (e.g. org.chromium.content.R) using the resources in the target (e.g. content/public/android/java/res). This R.java is used to produce the jar, but is not included in the jar itself. When we later build an apk, we merge the resources from the apk (e.g. org/chromium/content_shell/res) with the resources from the non-apk targets it depends on (e.g. content/public/android/java/res). A new R.java is generated using the merged resources with the correct mapping from resources to integer IDs. This R.java file is copied into each needed package (e.g. org.chromium.content.R and org.chromium.content_shell.R) and included in the apk. This is the first of three CLs to replace AppResource with R: 1. http://codereview.chromium.org/11363150 - Support Java resources within content 2. http://codereview.chromium.org/11360207 - Add Java resources to content and chrome 3. http://codereview.chromium.org/11377117 - Remove AppResource and unneeded resources BUG=136704 Review URL: https://codereview.chromium.org/11363150 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168283 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rw-r--r--build/android/AndroidManifest.xml13
-rw-r--r--build/android/ant/chromium-apk.xml15
-rw-r--r--build/android/ant/chromium-jars.xml5
-rw-r--r--build/android/findbugs_filter/findbugs_exclude.xml7
-rw-r--r--build/android/findbugs_filter/findbugs_known_bugs.txt32
-rw-r--r--build/java.gypi67
-rw-r--r--build/java_apk.gypi20
7 files changed, 122 insertions, 37 deletions
diff --git a/build/android/AndroidManifest.xml b/build/android/AndroidManifest.xml
new file mode 100644
index 0000000..0822e36
--- /dev/null
+++ b/build/android/AndroidManifest.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (c) 2012 The Chromium Authors. All rights reserved. Use of this
+ source code is governed by a BSD-style license that can be found in the
+ LICENSE file.
+-->
+
+<!--
+ This dummy manifest is passed to aapt when generating R.java in java.gypi.
+ Nothing in the manifest is used, but it is still required by aapt.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="dummy.package" />
diff --git a/build/android/ant/chromium-apk.xml b/build/android/ant/chromium-apk.xml
index 6ff1ebc..4fce8e9 100644
--- a/build/android/ant/chromium-apk.xml
+++ b/build/android/ant/chromium-apk.xml
@@ -31,6 +31,21 @@
<filelist files="${GENERATED_SRC_DIRS}"/>
</path>
+ <!--
+ Include additional resource folders in the apk, e.g. content/.../res. We
+ list the res folders in project.library.res.folder.path and the
+ corresponding java packages in project.library.packages, which must be
+ semicolon-delimited while ADDITIONAL_RES_PACKAGES is space-delimited, hence
+ the javascript task.
+ -->
+ <path id="project.library.res.folder.path">
+ <filelist files="${ADDITIONAL_RES_DIRS}"/>
+ </path>
+ <script language="javascript">
+ var before = project.getProperty("ADDITIONAL_RES_PACKAGES");
+ project.setProperty("project.library.packages", before.replaceAll(" ", ";"));
+ </script>
+
<property-value name="target.abi" value="${APP_ABI}"/>
<property name="resource.absolute.dir" value="${RESOURCE_DIR}"/>
<property-value name="gen.absolute.dir" value="${out.dir}/gen"/>
diff --git a/build/android/ant/chromium-jars.xml b/build/android/ant/chromium-jars.xml
index 07110cf..cd9839d 100644
--- a/build/android/ant/chromium-jars.xml
+++ b/build/android/ant/chromium-jars.xml
@@ -85,9 +85,12 @@
<target name="dist" depends="compile"
description="Generate chromium_${PACKAGE_NAME}.jar.">
- <!-- Create the distribution directory -->
+ <!-- Create the distribution directory. We exclude R.class and R$*.class
+ files since new versions of these files with the correct resource -> ID
+ mapping will be provided when we build each individual apk. -->
<jar
jarfile="${lib.java.dir}/chromium_${PACKAGE_NAME}.jar"
+ excludes="**/R.class **/R$*.class"
basedir="${dest.dir}"
/>
diff --git a/build/android/findbugs_filter/findbugs_exclude.xml b/build/android/findbugs_filter/findbugs_exclude.xml
index e0e5f2a..49fa811 100644
--- a/build/android/findbugs_filter/findbugs_exclude.xml
+++ b/build/android/findbugs_filter/findbugs_exclude.xml
@@ -10,6 +10,13 @@ Documentation: http://findbugs.sourceforge.net/manual/filter.html
In particular, ~ at the start of a string means it's a regex.
-->
<FindBugsFilter>
+ <!-- Skip the generated resource classes (including nested classes). -->
+ <Match>
+ <Class name="~org\.chromium\..*\.R(\$\w+)?" />
+ </Match>
+ <Match>
+ <Class name="~org\.chromium\..*\.Manifest(\$\w+)?" />
+ </Match>
<!-- Ignore "reliance on default String encoding" warnings, as we're not multi-platform -->
<Bug pattern="DM_DEFAULT_ENCODING" />
</FindBugsFilter>
diff --git a/build/android/findbugs_filter/findbugs_known_bugs.txt b/build/android/findbugs_filter/findbugs_known_bugs.txt
index 8579fe1..20d9994 100644
--- a/build/android/findbugs_filter/findbugs_known_bugs.txt
+++ b/build/android/findbugs_filter/findbugs_known_bugs.txt
@@ -46,39 +46,7 @@ H V MS: org.chromium.content.browser.ContentViewTestBase.WAIT_TIMEOUT_SECONDS is
H V MS: org.chromium.content.browser.test.util.CallbackHelper.WAIT_TIMEOUT_SECONDS isn't final but should be At CallbackHelper.java
H V MS: org.chromium.content.browser.test.util.HistoryUtils.WAIT_TIMEOUT_SECONDS isn't final but should be At HistoryUtils.java
M B FS: Format string should use %n rather than \n in org.chromium.android_webview.test.AwSettingsTest.testUserAgentStringDefault() At AwSettingsTest.java
-M B Nm: The class name org.chromium.android_webview.test.R$attr doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.android_webview.test.R$drawable doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.android_webview.test.R$raw doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.android_webview.test.R$string doesn't start with an upper case letter At R.java
M B Nm: The class name org.chromium.chrome.browser.component.navigation_interception.InterceptNavigationDelegate shadows the simple name of implemented interface org.chromium.content.components.navigation_interception.InterceptNavigationDelegate In InterceptNavigationDelegate.java
-M B Nm: The class name org.chromium.chrome.testshell.Manifest$permission doesn't start with an upper case letter At Manifest.java
-M B Nm: The class name org.chromium.chrome.testshell.R$attr doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.chrome.testshell.R$dimen doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.chrome.testshell.R$drawable doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.chrome.testshell.R$id doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.chrome.testshell.R$layout doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.chrome.testshell.R$string doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.chrome.testshell.tests.R$attr doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.chrome.testshell.tests.R$dimen doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.chrome.testshell.tests.R$drawable doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.chrome.testshell.tests.R$id doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.chrome.testshell.tests.R$layout doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.chrome.testshell.tests.R$string doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.content_shell.Manifest$permission doesn't start with an upper case letter At Manifest.java
-M B Nm: The class name org.chromium.content_shell.R$attr doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.content_shell.R$dimen doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.content_shell.R$drawable doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.content_shell.R$id doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.content_shell.R$layout doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.content_shell.R$string doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.content_shell.tests.R$attr doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.content_shell.tests.R$dimen doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.content_shell.tests.R$drawable doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.content_shell.tests.R$id doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.content_shell.tests.R$layout doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.content_shell.tests.R$string doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.native_test.R$attr doesn't start with an upper case letter At R.java
-M B Nm: The class name org.chromium.native_test.R$string doesn't start with an upper case letter At R.java
M B Nm: The method name org.chromium.base.test.util.ScalableTimeout.ScaleTimeout(long) doesn't start with a lower case letter At ScalableTimeout.java
M B RV: exceptional return value of java.io.File.delete() ignored in org.chromium.android_webview.test.ArchiveTest.doArchiveTest(AwContents, String, boolean, String) At ArchiveTest.java
M B RV: exceptional return value of java.io.File.delete() ignored in org.chromium.android_webview.test.ArchiveTest.testAutoBadPath() At ArchiveTest.java
diff --git a/build/java.gypi b/build/java.gypi
index e434206..215b562 100644
--- a/build/java.gypi
+++ b/build/java.gypi
@@ -38,6 +38,12 @@
# empty, which leads to inclusion of all files specified. May include
# wildcard, and supports '**/' for recursive path wildcards, ie.:
# '**/MyFileRegardlessOfDirectory.java', '**/IncludedPrefix*.java'.
+# has_java_resources - Set to 1 if the java target contains an
+# Android-compatible resources folder named res. If 1, R_package and
+# R_package_relpath must also be set.
+# R_package - The java package in which the R class (which maps resources to
+# integer IDs) should be generated, e.g. org.chromium.content.
+# R_package_relpath - Same as R_package, but replace each '.' with '/'.
{
'dependencies': [
@@ -53,10 +59,67 @@
'variables': {
'input_jars_paths': [],
'additional_src_dirs': [],
- 'additional_input_paths': [],
- 'generated_src_dirs': [],
'javac_includes': [],
+ 'additional_input_paths': ['>@(additional_R_files)'],
+ 'generated_src_dirs': ['>@(generated_R_dirs)'],
+ 'generated_R_dirs': [],
+ 'additional_R_files': [],
+ 'has_java_resources%': 0,
},
+ 'conditions': [
+ ['has_java_resources == 1', {
+ 'variables': {
+ 'R_dir': '<(SHARED_INTERMEDIATE_DIR)/<(package_name)/java_R',
+ 'R_file': '<(R_dir)/<(R_package_relpath)/R.java',
+ 'generated_src_dirs': ['<(R_dir)'],
+ 'additional_input_paths': ['<(R_file)'],
+ },
+ 'all_dependent_settings': {
+ 'variables': {
+ # Dependent jars include this target's R.java file via
+ # generated_R_dirs and additional_R_files.
+ 'generated_R_dirs': ['<(R_dir)'],
+ 'additional_R_files': ['<(R_file)'],
+
+ # Dependent APKs include this target's resources via
+ # additional_res_dirs and additional_res_packages.
+ 'additional_res_dirs': ['<(java_in_dir)/res'],
+ 'additional_res_packages': ['<(R_package)'],
+ },
+ },
+ 'actions': [
+ # Generate R.java for the library. This R.java contains non-final
+ # constants and is used only while compiling the library jar (e.g.
+ # chromium_content.jar). When building an apk, a new R.java file with
+ # the correct resource -> ID mappings will be generated by merging the
+ # resources from all libraries and the main apk project.
+ {
+ 'action_name': 'generate_r_java',
+ 'message': 'generating R.java for <(package_name)',
+ 'inputs': [
+ '<(android_sdk_tools)/aapt',
+ '<(android_sdk)/android.jar',
+ '<(DEPTH)/build/android/AndroidManifest.xml',
+ '<!@(find <(java_in_dir)/res -type f)',
+ ],
+ 'outputs': [
+ '<(R_file)',
+ ],
+ 'action': [
+ '<(android_sdk_tools)/aapt',
+ 'package',
+ '-m',
+ '--non-constant-id',
+ '--custom-package', '<(R_package)',
+ '-M', '<(DEPTH)/build/android/AndroidManifest.xml',
+ '-S', '<(java_in_dir)/res',
+ '-I', '<(android_sdk)/android.jar',
+ '-J', '<(R_dir)',
+ ],
+ },
+ ],
+ }],
+ ],
'actions': [
{
'action_name': 'ant_<(package_name)',
diff --git a/build/java_apk.gypi b/build/java_apk.gypi
index edd87a3..7aa0738 100644
--- a/build/java_apk.gypi
+++ b/build/java_apk.gypi
@@ -24,8 +24,8 @@
# like:
#
# content/shell/android/java/content_shell_apk.xml
-# content/shell/android/java/src/chromium/base/Foo.java
-# content/shell/android/java/src/chromium/base/Bar.java
+# content/shell/android/java/src/org/chromium/base/Foo.java
+# content/shell/android/java/src/org/chromium/base/Bar.java
#
# Required variables:
# package_name - Used to name the intermediate output directory and in the
@@ -36,6 +36,9 @@
# Optional/automatic variables:
# additional_input_paths - These paths will be included in the 'inputs' list to
# ensure that this target is rebuilt when one of these paths changes.
+# additional_res_dirs - Additional directories containing Android resources.
+# additional_res_packages - Package names of the R.java files corresponding to
+# each directory in additional_res_dirs.
# additional_src_dirs - Additional directories with .java files to be compiled
# and included in the output of this target.
# asset_location - The directory where assets are located (default:
@@ -46,6 +49,8 @@
# included in the 'inputs' list (unlike additional_src_dirs).
# input_jars_paths - The path to jars to be included in the classpath. This
# should be filled automatically by depending on the appropriate targets.
+# is_test_apk - Set to 1 if building a test apk. This prevents resources from
+# dependencies from being re-included.
# native_libs_paths - The path to any native library to be included in this
# target. This should be a path in <(SHARED_LIB_DIR). A stripped copy of
# the library will be included in the apk and symbolic links to the
@@ -68,6 +73,9 @@
'manifest_package_name%': 'unknown.package.name',
'resource_dir%':'',
'jar_name%': 'chromium_apk_<(package_name).jar',
+ 'additional_res_dirs': [],
+ 'additional_res_packages': [],
+ 'is_test_apk%': 0,
},
'sources': [
'<@(native_libs_paths)'
@@ -121,6 +129,12 @@
['resource_dir!=""', {
'inputs': ['<!@(find <(java_in_dir)/<(resource_dir) -name "*")']
}],
+ ['is_test_apk == 1', {
+ 'variables': {
+ 'additional_res_dirs=': [],
+ 'additional_res_packages=': [],
+ }
+ }],
],
'outputs': [
'<(PRODUCT_DIR)/apks/<(apk_name).apk',
@@ -146,6 +160,8 @@
'-DJAR_NAME=<(jar_name)',
'-DPACKAGE_NAME=<(package_name)',
'-DRESOURCE_DIR=<(resource_dir)',
+ '-DADDITIONAL_RES_DIRS=>(additional_res_dirs)',
+ '-DADDITIONAL_RES_PACKAGES=>(additional_res_packages)',
'-DAPP_MANIFEST_VERSION_NAME=<(app_manifest_version_name)',
'-DAPP_MANIFEST_VERSION_CODE=<(app_manifest_version_code)',
'-DPROGUARD_FLAGS=>(proguard_flags)',