Merge "Fix wrap.sh for 32-bit apps on 64-bit devices."
diff --git a/docs/changelogs/Changelog-r25.md b/docs/changelogs/Changelog-r25.md
index 4f7e05a..5d668dd 100644
--- a/docs/changelogs/Changelog-r25.md
+++ b/docs/changelogs/Changelog-r25.md
@@ -19,8 +19,11 @@
   will now receive `-O3`. If you're building with AGP and haven't overridden
   AGP's default CMake modes, this change does not affect you, as AGP uses
   `RelWithDebInfo` by default.
+* [Issue 1744]: Fixes ASan wrap.sh file to support 32-bit apps on 64-bit
+  devices.
 
 [Issue 1740]: https://github.com/android/ndk/issues/1740
+[Issue 1744]: https://github.com/android/ndk/issues/1744
 
 ## Changes
 
diff --git a/wrap.sh/asan.sh b/wrap.sh/asan.sh
index 1e0fa20..3929540 100644
--- a/wrap.sh/asan.sh
+++ b/wrap.sh/asan.sh
@@ -4,15 +4,10 @@
 cmd=$1
 shift
 
-export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1
-ASAN_LIB=$(ls "$HERE"/libclang_rt.asan-*-android.so)
-if [ -f "$HERE/libc++_shared.so" ]; then
-    # Workaround for https://github.com/android-ndk/ndk/issues/988.
-    export LD_PRELOAD="$ASAN_LIB $HERE/libc++_shared.so"
-else
-    export LD_PRELOAD="$ASAN_LIB"
-fi
-
+# This must be called *before* `LD_PRELOAD` is set. Otherwise, if this is a 32-
+# bit app running on a 64-bit device, the 64-bit getprop will fail to load
+# because it will preload a 32-bit ASan runtime.
+# https://github.com/android/ndk/issues/1744
 os_version=$(getprop ro.build.version.sdk)
 
 if [ "$os_version" -eq "27" ]; then
@@ -23,4 +18,13 @@
   cmd="$cmd -XjdwpProvider:adbconnection -XjdwpOptions:suspend=n,server=y $@"
 fi
 
+export ASAN_OPTIONS=log_to_syslog=false,allow_user_segv_handler=1
+ASAN_LIB=$(ls "$HERE"/libclang_rt.asan-*-android.so)
+if [ -f "$HERE/libc++_shared.so" ]; then
+    # Workaround for https://github.com/android-ndk/ndk/issues/988.
+    export LD_PRELOAD="$ASAN_LIB $HERE/libc++_shared.so"
+else
+    export LD_PRELOAD="$ASAN_LIB"
+fi
+
 exec $cmd