@@ -1546,7 +1546,9 @@ int doPackage(Bundle* bundle)
15461546 assets = new AaptAssets ();
15471547
15481548 // Set up the resource gathering in assets if we're going to generate
1549- // dependency files
1549+ // dependency files. Every time we encounter a resource while slurping
1550+ // the tree, we'll add it to these stores so we have full resource paths
1551+ // to write to a dependency file.
15501552 if (bundle->getGenDependencies ()) {
15511553 sp<FilePathStore> resPathStore = new FilePathStore;
15521554 assets->setFullResPaths (resPathStore);
@@ -1577,15 +1579,20 @@ int doPackage(Bundle* bundle)
15771579 goto bail;
15781580 }
15791581
1582+ // If we've been asked to generate a dependency file, do that here
15801583 if (bundle->getGenDependencies ()) {
1584+ // If this is the packaging step, generate the dependency file next to
1585+ // the output apk (e.g. bin/resources.ap_.d)
15811586 if (outputAPKFile) {
15821587 dependencyFile = String8 (outputAPKFile);
1583- // Strip the extension and add new one
1584- dependencyFile = dependencyFile.getBasePath ();
1588+ // Add the .d extension to the dependency file.
15851589 dependencyFile.append (" .d" );
15861590 } else {
1591+ // Else if this is the R.java dependency generation step,
1592+ // generate the dependency file in the R.java package subdirectory
1593+ // e.g. gen/com/foo/app/R.java.d
15871594 dependencyFile = String8 (bundle->getRClassDir ());
1588- dependencyFile.appendPath (" R.d" );
1595+ dependencyFile.appendPath (" R.java. d" );
15891596 }
15901597 // Make sure we have a clean dependency file to start with
15911598 fp = fopen (dependencyFile, " w" );
@@ -1595,13 +1602,18 @@ int doPackage(Bundle* bundle)
15951602 // Write out R.java constants
15961603 if (assets->getPackage () == assets->getSymbolsPrivatePackage ()) {
15971604 if (bundle->getCustomPackage () == NULL ) {
1605+ // Write the R.java file into the appropriate class directory
1606+ // e.g. gen/com/foo/app/R.java
15981607 err = writeResourceSymbols (bundle, assets, assets->getPackage (), true );
1599- // Copy R.java for libraries
1608+ // If we have library files, we're going to write our R.java file into
1609+ // the appropriate class directory for those libraries as well.
1610+ // e.g. gen/com/foo/app/lib/R.java
16001611 if (bundle->getExtraPackages () != NULL ) {
16011612 // Split on colon
16021613 String8 libs (bundle->getExtraPackages ());
16031614 char * packageString = strtok (libs.lockBuffer (libs.length ()), " :" );
16041615 while (packageString != NULL ) {
1616+ // Write the R.java file out with the correct package name
16051617 err = writeResourceSymbols (bundle, assets, String8 (packageString), true );
16061618 packageString = strtok (NULL , " :" );
16071619 }
@@ -1640,14 +1652,19 @@ int doPackage(Bundle* bundle)
16401652 }
16411653 }
16421654
1655+ // If we've been asked to generate a dependency file, we need to finish up here.
1656+ // the writeResourceSymbols and writeAPK functions have already written the target
1657+ // half of the dependency file, now we need to write the prerequisites. (files that
1658+ // the R.java file or .ap_ file depend on)
16431659 if (bundle->getGenDependencies ()) {
16441660 // Now that writeResourceSymbols or writeAPK has taken care of writing
16451661 // the targets to our dependency file, we'll write the prereqs
16461662 fp = fopen (dependencyFile, " a+" );
16471663 fprintf (fp, " : " );
16481664 bool includeRaw = (outputAPKFile != NULL );
16491665 err = writeDependencyPreReqs (bundle, assets, fp, includeRaw);
1650- // Also manually add the AndroidManifeset since it's a non-asset
1666+ // Also manually add the AndroidManifeset since it's not under res/ or assets/
1667+ // and therefore was not added to our pathstores during slurping
16511668 fprintf (fp, " %s \\\n " , bundle->getAndroidManifestFile ());
16521669 fclose (fp);
16531670 }
0 commit comments