OSDN Git Service

Cherrypick 78c89f from master. do not merge.
authorXavier Ducrohet <xav@android.com>
Thu, 29 Sep 2011 01:26:54 +0000 (18:26 -0700)
committerXavier Ducrohet <xav@android.com>
Thu, 29 Sep 2011 18:38:25 +0000 (11:38 -0700)
Also process and cache the png files in libraries.

The png in the libraries were not processed by the crunch step.
Because aapt never processes png files anymore (relying on the crunch
step to do it), the png files in libraries were never processed.

While this is less a problem for standard png files, this completely
breaks 9-patches that must be processed to actually behaves as 9-patch.

Change-Id: I1d9e32e2c0409ec779150de0ad897e210a9be524

anttasks/src/com/android/ant/NewSetupTask.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/LibraryClasspathContainerInitializer.java
files/ant/build.xml

index f6ba986..165ea08 100644 (file)
@@ -465,7 +465,10 @@ public class NewSetupTask extends Task {
                 PathElement element = rootPath.createPathElement();
                 element.setPath(libRootPath);
 
-                // get the res path. Always $PROJECT/res
+                // get the res path. Always $PROJECT/res as well as the crunch cache.
+                element = resPath.createPathElement();
+                element.setPath(libRootPath + "/" + SdkConstants.FD_OUTPUT +
+                        "/" + SdkConstants.FD_RES);
                 element = resPath.createPathElement();
                 element.setPath(libRootPath + "/" + SdkConstants.FD_RESOURCES);
 
index 3e96a8f..3209ec1 100644 (file)
@@ -227,7 +227,11 @@ public class BuildHelper {
             // libraries?
             if (libProjects != null) {
                 for (IProject lib : libProjects) {
-                    IFolder libResFolder = lib.getFolder(SdkConstants.FD_RES);
+                    IFolder libCacheFolder = lib.getFolder(AdtConstants.WS_CRUNCHCACHE);
+                    if (libCacheFolder.exists()) {
+                        osResPaths.add(libCacheFolder.getLocation().toOSString());
+                    }
+                    IFolder libResFolder = lib.getFolder(AdtConstants.WS_RESOURCES);
                     if (libResFolder.exists()) {
                         osResPaths.add(libResFolder.getLocation().toOSString());
                     }
index 47215cc..7f75c4f 100644 (file)
@@ -23,10 +23,10 @@ import com.android.ide.eclipse.adt.internal.build.AaptExecException;
 import com.android.ide.eclipse.adt.internal.build.AaptParser;
 import com.android.ide.eclipse.adt.internal.build.AaptResultException;
 import com.android.ide.eclipse.adt.internal.build.BuildHelper;
-import com.android.ide.eclipse.adt.internal.build.BuildHelper.ResourceMarker;
 import com.android.ide.eclipse.adt.internal.build.DexException;
 import com.android.ide.eclipse.adt.internal.build.Messages;
 import com.android.ide.eclipse.adt.internal.build.NativeLibInJarException;
+import com.android.ide.eclipse.adt.internal.build.BuildHelper.ResourceMarker;
 import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs;
 import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs.BuildVerbosity;
 import com.android.ide.eclipse.adt.internal.project.ApkInstallManager;
@@ -410,7 +410,8 @@ public class PostCompilerBuilder extends BaseBuilder {
                     mConvertToDex = true;
                 }
 
-                if (mConvertToDex) {
+                if (mConvertToDex) { // in this case this means some class files changed and
+                                     // we need to update the jar file.
                     IFolder javaOutputFolder = BaseProjectHelper.getJavaOutputFolder(project);
 
                     writeLibraryPackage(jarIFile, project, javaOutputFolder,
@@ -418,6 +419,15 @@ public class PostCompilerBuilder extends BaseBuilder {
                     saveProjectBooleanProperty(PROPERTY_CONVERT_TO_DEX, mConvertToDex = false);
                 }
 
+                // also update the crunch cache if needed.
+                if (mUpdateCrunchCache) {
+                    BuildHelper helper = new BuildHelper(project,
+                            mOutStream, mErrStream,
+                            true /*debugMode*/,
+                            AdtPrefs.getPrefs().getBuildVerbosity() == BuildVerbosity.VERBOSE);
+                    updateCrunchCache(project, helper);
+                }
+
                 return allRefProjects;
             }
 
@@ -536,27 +546,9 @@ public class PostCompilerBuilder extends BaseBuilder {
 
                 // Check if we need to update the PNG cache
                 if (mUpdateCrunchCache) {
-                    try {
-                        helper.updateCrunchCache();
-                    } catch (AaptExecException e) {
-                        BaseProjectHelper.markResource(project, AdtConstants.MARKER_PACKAGING,
-                                e.getMessage(), IMarker.SEVERITY_ERROR);
+                    if (updateCrunchCache(project, helper) == false) {
                         return allRefProjects;
-                    } catch (AaptResultException e) {
-                        // attempt to parse the error output
-                        String[] aaptOutput = e.getOutput();
-                        boolean parsingError = AaptParser.parseOutput(aaptOutput, project);
-                        // if we couldn't parse the output we display it in the console.
-                        if (parsingError) {
-                            AdtPlugin.printErrorToConsole(project, (Object[]) aaptOutput);
-                        }
                     }
-
-                    // crunch has been done. Reset state
-                    mUpdateCrunchCache = false;
-
-                    // and store it
-                    saveProjectBooleanProperty(PROPERTY_UPDATE_CRUNCH_CACHE, mUpdateCrunchCache);
                 }
 
                 // Check if we need to package the resources.
@@ -826,6 +818,35 @@ public class PostCompilerBuilder extends BaseBuilder {
         }
     }
 
+    /**
+     * Updates the crunch cache if needed and return true if the build must continue.
+     */
+    private boolean updateCrunchCache(IProject project, BuildHelper helper) {
+        try {
+            helper.updateCrunchCache();
+        } catch (AaptExecException e) {
+            BaseProjectHelper.markResource(project, AdtConstants.MARKER_PACKAGING,
+                    e.getMessage(), IMarker.SEVERITY_ERROR);
+            return false;
+        } catch (AaptResultException e) {
+            // attempt to parse the error output
+            String[] aaptOutput = e.getOutput();
+            boolean parsingError = AaptParser.parseOutput(aaptOutput, project);
+            // if we couldn't parse the output we display it in the console.
+            if (parsingError) {
+                AdtPlugin.printErrorToConsole(project, (Object[]) aaptOutput);
+            }
+        }
+
+        // crunch has been done. Reset state
+        mUpdateCrunchCache = false;
+
+        // and store it
+        saveProjectBooleanProperty(PROPERTY_UPDATE_CRUNCH_CACHE, mUpdateCrunchCache);
+
+        return true;
+    }
+
     private void writeLibraryPackage(IFile jarIFile, IProject project, IFolder javaOutputFolder,
             List<IJavaProject> referencedJavaProjects) {
 
index 6d0ed5a..6540038 100644 (file)
@@ -137,15 +137,17 @@ public class LibraryClasspathContainerInitializer extends ClasspathContainerInit
             // get the project output
             IFolder outputFolder = BaseProjectHelper.getAndroidOutputFolder(libProject);
 
-            IFile jarIFile = outputFolder.getFile(libProject.getName().toLowerCase() +
-                    AdtConstants.DOT_JAR);
+            if (outputFolder != null) { // can happen when closing/deleting a library)
+                IFile jarIFile = outputFolder.getFile(libProject.getName().toLowerCase() +
+                        AdtConstants.DOT_JAR);
 
-            IClasspathEntry entry = JavaCore.newLibraryEntry(
-                    jarIFile.getLocation(),
-                    libProject.getLocation(), // source attachment path
-                    null);                    // default source attachment root path.
+                IClasspathEntry entry = JavaCore.newLibraryEntry(
+                        jarIFile.getLocation(),
+                        libProject.getLocation(), // source attachment path
+                        null);                    // default source attachment root path.
 
-            entries.add(entry);
+                entries.add(entry);
+            }
         }
 
         return new AndroidClasspathContainer(
index 9387ff2..134a0a3 100644 (file)
 
 <!-- Updates the pre-processed PNG cache -->
     <target name="-crunch">
-        <!-- only crunch if *not* a library project -->
-        <do-only-if-not-library elseText="Library project: do not optimize PNGs..." >
-            <exec executable="${aapt}" taskName="crunch">
-                <arg value="crunch" />
-                <arg value="-v" />
-                <arg value="-S" />
-                <arg path="${resource.absolute.dir}" />
-                <arg value="-C" />
-                <arg path="${out.res.absolute.dir}" />
-            </exec>
-        </do-only-if-not-library>
+        <exec executable="${aapt}" taskName="crunch">
+            <arg value="crunch" />
+            <arg value="-v" />
+            <arg value="-S" />
+            <arg path="${resource.absolute.dir}" />
+            <arg value="-C" />
+            <arg path="${out.res.absolute.dir}" />
+        </exec>
     </target>
 
     <!-- Puts the project's resources into the output package file