Merge "Use libnativehelper's existing code for creating a String[]." into dalvik-dev
diff --git a/build/Android.aexec.mk b/build/Android.aexec.mk
index 758fe02..6d6177c 100644
--- a/build/Android.aexec.mk
+++ b/build/Android.aexec.mk
@@ -33,10 +33,11 @@
   ifeq ($(2),debug)
     LOCAL_CFLAGS += -UNDEBUG
   endif
+  LOCAL_SHARED_LIBRARIES := libnativehelper
   ifeq ($(2),ndebug)
-    LOCAL_SHARED_LIBRARIES := libart
+    LOCAL_SHARED_LIBRARIES += libart
   else
-    LOCAL_SHARED_LIBRARIES := libartd
+    LOCAL_SHARED_LIBRARIES += libartd
   endif
   ifeq ($(1),target)
     LOCAL_SHARED_LIBRARIES += libstlport
diff --git a/src/main.cc b/src/main.cc
index 091cda0..381f8f7 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -8,6 +8,7 @@
 #include "jni.h"
 #include "logging.h"
 #include "scoped_ptr.h"
+#include "toStringArray.h"
 #include "ScopedLocalRef.h"
 
 // TODO: move this into the runtime.
@@ -26,40 +27,6 @@
   }
 }
 
-// TODO: this code should be shared with other parts of the system
-// that create string arrays.
-//Create a String[] and populate it with the contents of argv.
-static jobjectArray CreateStringArray(JNIEnv* env, char** argv, int argc) {
-  // Find the String class.
-  ScopedLocalRef<jclass> klass(env, env->FindClass("java/lang/String"));
-  if (env->ExceptionCheck()) {
-    fprintf(stderr, "Got exception while finding class String\n");
-    return NULL;
-  }
-  DCHECK(klass.get() != NULL);
-
-  // Create an array of String elements.
-  jobjectArray args = env->NewObjectArray(argc, klass.get(), NULL);
-  if (env->ExceptionCheck()) {
-    fprintf(stderr, "Got exception while creating String array\n");
-    return NULL;
-  }
-  DCHECK(args != NULL);
-
-  // Allocate a string object for each argv element.
-  for (int i = 0; i < argc; ++i) {
-    ScopedLocalRef<jstring> elt(env, env->NewStringUTF(argv[i]));
-    if (env->ExceptionCheck()) {
-      fprintf(stderr, "Got exception while allocating Strings\n");
-      return NULL;
-    }
-    DCHECK(elt.get() != NULL);
-    env->SetObjectArrayElement(args, i, elt.get());
-  }
-
-  return args;
-}
-
 // Determine whether or not the specified method is public.
 //
 // Returns JNI_TRUE on success, JNI_FALSE on failure.
@@ -97,8 +64,7 @@
   // We want to call main() with a String array with our arguments in
   // it.  Create an array and populate it.  Note argv[0] is not
   // included.
-  ScopedLocalRef<jobjectArray> args(env,
-      CreateStringArray(env, argv + 1, argc - 1));
+  ScopedLocalRef<jobjectArray> args(env, toStringArray(env, argv + 1));
   if (args.get() == NULL) {
     return false;
   }