Merge "Fix dependency when switching between build variants with and without Proguard." into gingerbread
diff --git a/core/base_rules.mk b/core/base_rules.mk
index f372748..206c087 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -499,7 +499,7 @@
 	@echo "Install: $@"
 	$(copy-file-to-target)
 
-$(LOCAL_INSTALLED_MODULE): $(installed_odex)
+$(LOCAL_INSTALLED_MODULE) : | $(installed_odex)
 endif
 
 endif # !LOCAL_UNINSTALLABLE_MODULE
diff --git a/core/binary.mk b/core/binary.mk
index 1f55b66..5fb0e75 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -28,7 +28,7 @@
   ifndef LOCAL_SDK_VERSION
     $(error $(LOCAL_PATH): LOCAL_NDK_VERSION must be defined with LOCAL_SDK_VERSION)
   endif
-  my_ndk_version_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/android-ndk-r$(LOCAL_NDK_VERSION)/$(BUILD_OS)/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_ARCH)
+  my_ndk_version_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/android-ndk-r$(LOCAL_NDK_VERSION)/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_ARCH)
   ifeq ($(wildcard $(my_ndk_version_root)),)
     $(error $(LOCAL_PATH): ndk version root does not exist: $(my_ndk_version_root))
   endif
diff --git a/core/envsetup.mk b/core/envsetup.mk
index 5b0d88c..f556efe 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -119,10 +119,12 @@
   HOST_PREBUILT_TAG := $(HOST_OS)-$(HOST_ARCH)
 endif
 
-# Build dalvikvm on hosts that support it
+# Build dalvikvm on hosts that support it, but not if we're building the sim
 ifeq ($(HOST_OS),linux)
+ifneq ($(TARGET_SIMULATOR),true)
 	WITH_HOST_DALVIK := true
 endif
+endif
 
 
 # ---------------------------------------------------------------
diff --git a/tools/signapk/SignApk.java b/tools/signapk/SignApk.java
index 3244a49..c4d73c8 100644
--- a/tools/signapk/SignApk.java
+++ b/tools/signapk/SignApk.java
@@ -220,10 +220,12 @@
     /** Write to another stream and also feed it to the Signature object. */
     private static class SignatureOutputStream extends FilterOutputStream {
         private Signature mSignature;
+        private int mCount;
 
         public SignatureOutputStream(OutputStream out, Signature sig) {
             super(out);
             mSignature = sig;
+            mCount = 0;
         }
 
         @Override
@@ -234,6 +236,7 @@
                 throw new IOException("SignatureException: " + e);
             }
             super.write(b);
+            mCount++;
         }
 
         @Override
@@ -244,11 +247,16 @@
                 throw new IOException("SignatureException: " + e);
             }
             super.write(b, off, len);
+            mCount += len;
+        }
+
+        public int size() {
+            return mCount;
         }
     }
 
     /** Write a .SF file with a digest of the specified manifest. */
-    private static void writeSignatureFile(Manifest manifest, OutputStream out)
+    private static void writeSignatureFile(Manifest manifest, SignatureOutputStream out)
             throws IOException, GeneralSecurityException {
         Manifest sf = new Manifest();
         Attributes main = sf.getMainAttributes();
@@ -282,6 +290,15 @@
         }
 
         sf.write(out);
+
+        // A bug in the java.util.jar implementation of Android platforms
+        // up to version 1.6 will cause a spurious IOException to be thrown
+        // if the length of the signature file is a multiple of 1024 bytes.
+        // As a workaround, add an extra CRLF in this case.
+        if ((out.size() % 1024) == 0) {
+            out.write('\r');
+            out.write('\n');
+        }
     }
 
     /** Write a .RSA file with a digital signature. */