@@ -1391,7 +1391,9 @@ int doPackage(Bundle* bundle)
13911391 assets = new AaptAssets ();
13921392
13931393 // Set up the resource gathering in assets if we're going to generate
1394- // dependency files
1394+ // dependency files. Every time we encounter a resource while slurping
1395+ // the tree, we'll add it to these stores so we have full resource paths
1396+ // to write to a dependency file.
13951397 if (bundle->getGenDependencies ()) {
13961398 sp<FilePathStore> resPathStore = new FilePathStore;
13971399 assets->setFullResPaths (resPathStore);
@@ -1422,15 +1424,20 @@ int doPackage(Bundle* bundle)
14221424 goto bail;
14231425 }
14241426
1427+ // If we've been asked to generate a dependency file, do that here
14251428 if (bundle->getGenDependencies ()) {
1429+ // If this is the packaging step, generate the dependency file next to
1430+ // the output apk (e.g. bin/resources.ap_.d)
14261431 if (outputAPKFile) {
14271432 dependencyFile = String8 (outputAPKFile);
1428- // Strip the extension and add new one
1429- dependencyFile = dependencyFile.getBasePath ();
1433+ // Add the .d extension to the dependency file.
14301434 dependencyFile.append (" .d" );
14311435 } else {
1436+ // Else if this is the R.java dependency generation step,
1437+ // generate the dependency file in the R.java package subdirectory
1438+ // e.g. gen/com/foo/app/R.java.d
14321439 dependencyFile = String8 (bundle->getRClassDir ());
1433- dependencyFile.appendPath (" R.d" );
1440+ dependencyFile.appendPath (" R.java. d" );
14341441 }
14351442 // Make sure we have a clean dependency file to start with
14361443 fp = fopen (dependencyFile, " w" );
@@ -1440,13 +1447,18 @@ int doPackage(Bundle* bundle)
14401447 // Write out R.java constants
14411448 if (assets->getPackage () == assets->getSymbolsPrivatePackage ()) {
14421449 if (bundle->getCustomPackage () == NULL ) {
1450+ // Write the R.java file into the appropriate class directory
1451+ // e.g. gen/com/foo/app/R.java
14431452 err = writeResourceSymbols (bundle, assets, assets->getPackage (), true );
1444- // Copy R.java for libraries
1453+ // If we have library files, we're going to write our R.java file into
1454+ // the appropriate class directory for those libraries as well.
1455+ // e.g. gen/com/foo/app/lib/R.java
14451456 if (bundle->getExtraPackages () != NULL ) {
14461457 // Split on colon
14471458 String8 libs (bundle->getExtraPackages ());
14481459 char * packageString = strtok (libs.lockBuffer (libs.length ()), " :" );
14491460 while (packageString != NULL ) {
1461+ // Write the R.java file out with the correct package name
14501462 err = writeResourceSymbols (bundle, assets, String8 (packageString), true );
14511463 packageString = strtok (NULL , " :" );
14521464 }
@@ -1485,14 +1497,19 @@ int doPackage(Bundle* bundle)
14851497 }
14861498 }
14871499
1500+ // If we've been asked to generate a dependency file, we need to finish up here.
1501+ // the writeResourceSymbols and writeAPK functions have already written the target
1502+ // half of the dependency file, now we need to write the prerequisites. (files that
1503+ // the R.java file or .ap_ file depend on)
14881504 if (bundle->getGenDependencies ()) {
14891505 // Now that writeResourceSymbols or writeAPK has taken care of writing
14901506 // the targets to our dependency file, we'll write the prereqs
14911507 fp = fopen (dependencyFile, " a+" );
14921508 fprintf (fp, " : " );
14931509 bool includeRaw = (outputAPKFile != NULL );
14941510 err = writeDependencyPreReqs (bundle, assets, fp, includeRaw);
1495- // Also manually add the AndroidManifeset since it's a non-asset
1511+ // Also manually add the AndroidManifeset since it's not under res/ or assets/
1512+ // and therefore was not added to our pathstores during slurping
14961513 fprintf (fp, " %s \\\n " , bundle->getAndroidManifestFile ());
14971514 fclose (fp);
14981515 }
0 commit comments