OSDN Git Service

Add ia32-libs hint on Linux when aapt fails to run
authorTor Norbye <tnorbye@google.com>
Wed, 24 Aug 2011 14:24:49 +0000 (07:24 -0700)
committerTor Norbye <tnorbye@google.com>
Thu, 25 Aug 2011 00:58:58 +0000 (17:58 -0700)
I had difficulties getting ADT to work when I tried running it on a 64
bit Linux system.  Aapt couldn't run, even though I verified that it
was there. After searching a bit, I not only found a bunch of forums
talking about this error (and offering pretty complex solutions), it
turns out this is even discussed in the SDK Installation
Troubleshooting guide. The solution is simple: Install 32-bit
libraries using

   sudo apt-get install ia32-libs

This changeset looks for this specific scenario in the aapt error
handler and emits a second error line which suggests that this
solution might be needed.

Change-Id: I453f99df61a198352f2cea4fe5cb7c517eeaf8c8

eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PreCompilerBuilder.java

index 11a7385..8f31b33 100644 (file)
@@ -54,6 +54,7 @@ import org.eclipse.core.runtime.Path;
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
@@ -669,7 +670,8 @@ public class PreCompilerBuilder extends BaseBuilder {
 
         // launch aapt: create the command line
         ArrayList<String> array = new ArrayList<String>();
-        array.add(projectTarget.getPath(IAndroidTarget.AAPT));
+        String aaptPath = projectTarget.getPath(IAndroidTarget.AAPT);
+        array.add(aaptPath);
         array.add("package"); //$NON-NLS-1$
         array.add("-m"); //$NON-NLS-1$
         if (AdtPrefs.getPrefs().getBuildVerbosity() == BuildVerbosity.VERBOSE) {
@@ -760,6 +762,24 @@ public class PreCompilerBuilder extends BaseBuilder {
             String msg = String.format(Messages.AAPT_Exec_Error, array.get(0));
             markProject(AdtConstants.MARKER_ADT, msg, IMarker.SEVERITY_ERROR);
 
+            // Add workaround for the Linux problem described here:
+            //    http://developer.android.com/sdk/installing.html#troubleshooting
+            // There are various posts on StackOverflow elsewhere where people are asking
+            // about aapt failing to run, so even though this is documented in the
+            // Troubleshooting section add an error message to help with this
+            // scenario.
+            if (SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_LINUX
+                    && System.getProperty("os.arch").endsWith("64") //$NON-NLS-1$ //$NON-NLS-2$
+                    && new File(aaptPath).exists()
+                    && new File("/usr/bin/apt-get").exists()) {     //$NON-NLS-1$
+                markProject(AdtConstants.MARKER_ADT,
+                        "Hint: On 64-bit systems, make sure the 32-bit libraries are installed: sudo apt-get install ia32-libs",
+                        IMarker.SEVERITY_ERROR);
+                // Note - this uses SEVERITY_ERROR even though it's really SEVERITY_INFO because
+                // we want this error message to show up adjacent to the aapt error message
+                // (and Eclipse sorts by priority)
+            }
+
             // This interrupts the build.
             throw new AbortBuildException();
         } catch (InterruptedException e) {