Bug 1052889 - Make Android Eclipse generate R.java. r=bnicholson
authorNick Alexander <nalexander@mozilla.com>
Thu, 14 Aug 2014 11:28:27 -0700
changeset 199582 ebba69aab4e2c1d6d961ac7d2a38b7687d752b47
parent 199581 0fd0a2566a51b82b41dbb2dcb762005bf4f2148b
child 199583 f8fb26b28dea244901beb81b4fa71bdbc4b6c539
push id27310
push userryanvm@gmail.com
push dateThu, 14 Aug 2014 21:12:03 +0000
treeherdermozilla-central@9eb591a1a203 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs1052889
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1052889 - Make Android Eclipse generate R.java. r=bnicholson This patch does two things. First, it adds the Search Activity sources to the main Fennec Eclipse project (when enabled). There's no reason for a separate project for these, since they are built as part of the main Fennec package by moz.build. Second, it arranges for Eclipse to generate the R.java and Manifest.java files for all Android libraries and ignores the files generated by moz.build. (The relevant classes are org.mozilla.{gecko,search}.R.) This means renaming the FennecResources Eclipse project's package to org.mozilla.gecko, and renaming the FennecResourcesSearch project's package to org.mozilla.search. To be consistent, I switched org.mozilla.fennec.resources to org.mozilla.gecko throughout. To accommodate the crash reporter resources, which depend on the static and generated resources, I added a layer of indirection. By moving the main resources into project FennecResourcesStatic, we can have (reading indentation as "depends on"): FennecResources FennecResourcesCrashReporter FennecResourcesStatic FennecResourcesGenerated FennecResourcesBranding This lets us break the bidirectional dependency between FennecResources and FennecResourcesCrashReporter.
mobile/android/base/moz.build
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -618,25 +618,33 @@ if CONFIG['MOZ_ANDROID_SEARCH_ACTIVITY']
         'gecko-mozglue.jar',
         'gecko-util.jar',
         'nineoldandroids.jar'
     ]
 
 generated_recursive_make_targets = ['.aapt.deps', '.locales.deps'] # Captures dependencies on Android manifest and all resources.
 
 generated = add_android_eclipse_library_project('FennecResourcesGenerated')
-generated.package_name = 'org.mozilla.fennec.resources.generated'
+generated.package_name = 'org.mozilla.gecko.generated'
 generated.res = OBJDIR + '/res'
 generated.recursive_make_targets += generated_recursive_make_targets
 
 branding = add_android_eclipse_library_project('FennecResourcesBranding')
-branding.package_name = 'org.mozilla.fennec.resources.branding'
+branding.package_name = 'org.mozilla.gecko.branding'
 branding.res = TOPSRCDIR + '/' + CONFIG['MOZ_BRANDING_DIRECTORY'] + '/res'
 branding.recursive_make_targets += generated_recursive_make_targets
 
+static = add_android_eclipse_library_project('FennecResourcesStatic')
+# 'org.mozilla.gecko.static' is not a valid Java package name, so we use a different one.
+static.package_name = 'org.mozilla.gecko.resources'
+static.res = SRCDIR + '/resources'
+static.recursive_make_targets += generated_recursive_make_targets
+static.included_projects += ['../' + generated.name, '../' + branding.name]
+static.referenced_projects += ['../' + generated.name, '../' + branding.name]
+
 main = add_android_eclipse_project('Fennec', OBJDIR + '/AndroidManifest.xml')
 main.package_name = 'org.mozilla.gecko'
 
 # These values were extracted from an existing Eclipse project.  Use
 # Project > Resource > Resource Filters and inspect the resulting
 # .project file to modify this list.
 main.filtered_resources += [
     '1.0-projectRelativePath-matches-false-false-*org/mozilla/gecko/resources/**',
@@ -649,64 +657,101 @@ main.recursive_make_targets += ['generat
 
 main.extra_jars += [CONFIG['ANDROID_COMPAT_LIB']]
 main.assets = TOPOBJDIR + '/dist/' + CONFIG['MOZ_APP_NAME'] + '/assets'
 main.libs = TOPOBJDIR + '/dist/' + CONFIG['MOZ_APP_NAME'] + '/lib'
 main.res = None
 
 cpe = main.add_classpathentry('src', SRCDIR,
     dstdir='src/org/mozilla/gecko',
-    exclude_patterns=['org/mozilla/gecko/tests/**',
+    exclude_patterns=[
+        'org/mozilla/gecko/tests/**',
         'org/mozilla/gecko/resources/**'])
 if not CONFIG['MOZ_CRASHREPORTER']:
     cpe.exclude_patterns += ['org/mozilla/gecko/CrashReporter.java']
 if not CONFIG['MOZ_NATIVE_DEVICES']:
     cpe.exclude_patterns += ['org/mozilla/gecko/ChromeCast.java']
     cpe.exclude_patterns += ['org/mozilla/gecko/MediaPlayerManager.java']
+# The generated/ directory includes both files generated by aapt (R.java and
+# Manifest.java for all packages) but also preprocessed files. In the past, the
+# generated R.java files were used by the Eclipse build, but now Eclipse
+# generates these files itself. Therefore, we exclude those generated sources.
 main.add_classpathentry('generated', OBJDIR + '/generated',
-    dstdir='generated')
+    dstdir='generated',
+    exclude_patterns=[
+        '**/R.java',
+        '**/Manifest.java'])
 main.add_classpathentry('thirdparty', TOPSRCDIR + '/mobile/android/thirdparty',
     dstdir='thirdparty',
     ignore_warnings=True)
 
+# Eclipse generates org.mozilla.gecko.R for this project, which is referenced by
+# all the Java code. The reason that this is not generated in the main Fennec
+# project is that you cannot specify a custom package to the Eclipse Android
+# builder; that is, the Eclipse Android builder always builds the
+# org.mozilla.fennec_*.R class. This approach works because Eclipse shares
+# resources and some code across projects implicitly, which lets us provide
+# org.mozilla.gecko.R to the main Fennec project from the FennecResources
+# project.
+#
+# Previously, the static resources were in the FennecResources project. To let
+# the FennecResources Eclipse project produce org.mozilla.gecko.R, however, the
+# project must depend on all the resource projects.  But the crash reporter
+# resources depend on some of the static resources, and that causes a cycle.
+# This layer of indirection lets us break the cycle.
+
 resources = add_android_eclipse_library_project('FennecResources')
-resources.package_name = 'org.mozilla.fennec.resources'
-resources.res = SRCDIR + '/resources'
-resources.included_projects += ['../' + generated.name, '../' + branding.name]
+resources.package_name = 'org.mozilla.gecko'
+resources.res = None
+resources.included_projects += ['../' + static.name, '../' + generated.name, '../' + branding.name]
 resources.recursive_make_targets += generated_recursive_make_targets
 
 # The resources are included in the Fennec APK.
 main.included_projects += ['../' + resources.name]
 
 omnijar = add_android_eclipse_library_project('FennecOmnijar')
-omnijar.package_name = 'org.mozilla.fennec.omnijar'
+omnijar.package_name = 'org.mozilla.gecko.omnijar'
 # This is delicate.  We write into OBJDIR, and write triggers a new build of the
 # Fennec project, because the omni.ja timestamp is always updated. (The target
 # is FORCE and the installer does not track dependencies.) However, Eclipse only
 # triggers a new build (of FennecOmnijar) when something actually changes, so
 # we're not constantly rebuilding the FennecOmnijar (or Fennec) project.
 omnijar.recursive_make_targets += [TOPOBJDIR + '/dist/fennec/assets/omni.ja']
 for d in ['app', 'chrome', 'components', 'locales', 'modules', 'themes']:
     omnijar.add_classpathentry(d, TOPSRCDIR + '/mobile/android/' + d, dstdir=d)
 
 # The omnijar is included in the Fennec APK (although it's empty,
 # having no resources, assets, or Java code).
 main.included_projects += ['../' + omnijar.name]
 
 if CONFIG['MOZ_CRASHREPORTER']:
     crashreporter = add_android_eclipse_library_project('FennecResourcesCrashReporter')
-    crashreporter.package_name = 'org.mozilla.fennec.resources.crashreporter'
+    crashreporter.package_name = 'org.mozilla.gecko.crashreporter'
     crashreporter.res = SRCDIR + '/crashreporter/res'
-    crashreporter.included_projects += ['../' + resources.name]
+    crashreporter.recursive_make_targets += generated_recursive_make_targets
 
-    main.included_projects += ['../' + crashreporter.name]
+    # layout/crash_reporter.xml references strings and other resources, and
+    # therefore depends on other resource projects.
+    crashreporter.included_projects += ['../' + static.name, '../' + generated.name]
+    crashreporter.referenced_projects += ['../' + static.name, '../' + generated.name]
+
+    resources.included_projects += ['../' + crashreporter.name]
+    resources.referenced_projects += ['../' + crashreporter.name]
 
 if CONFIG['MOZ_ANDROID_MLS_STUMBLER']:
     main.included_projects += ['../FennecStumbler']
     main.referenced_projects += ['../FennecStumbler']
 
 if CONFIG['MOZ_ANDROID_SEARCH_ACTIVITY']:
-    searchactivity = add_android_eclipse_library_project('FennecResourcesSearch')
-    searchactivity.package_name = 'org.mozilla.fennec.resources.search'
-    searchactivity.res = SRCDIR + '/../search/res'
-    searchactivity.included_projects += ['../' + resources.name]
+    searchres = add_android_eclipse_library_project('FennecResourcesSearch')
+    # Eclipse generates org.mozilla.search.R for this project, which is
+    # referenced by the search/**/*.java code.
+    searchres.package_name = 'org.mozilla.search'
+    searchres.res = SRCDIR + '/../search/res'
 
-    main.included_projects += ['../' + searchactivity.name]
+    searchres.included_projects += ['../' + static.name, '../' + generated.name, '../' + branding.name]
+    searchres.referenced_projects += ['../' + static.name, '../' + generated.name, '../' + branding.name]
+
+    resources.included_projects += ['../' + searchres.name]
+    resources.referenced_projects += ['../' + searchres.name]
+
+    # The Search Activity code is built as part of Fennec, so we follow suit in Eclipse.
+    main.add_classpathentry('search', TOPSRCDIR + '/mobile/android/search/java', dstdir='search')