Make fuzzer run on device and print less logs

* Update the build system so that the fuzzer runs on device
* Set up an init method to initialize things only once
* Set log level to error. This avoids a lot of warning LOGs

Bug: 249085422
Test: Run the fuzzer locally, both host and device
Change-Id: I1664b654bb7351dcf75bef08b9c26cee4b648429
diff --git a/tools/fuzzer/Android.bp b/tools/fuzzer/Android.bp
index 556460e..473992b 100644
--- a/tools/fuzzer/Android.bp
+++ b/tools/fuzzer/Android.bp
@@ -30,9 +30,17 @@
     // Run in debug mode for the DCHECKs.
     defaults: ["libartd_static_defaults"],
 
-    // Build and run on x86 only for now.
+    // Build and run on x86 too.
     host_supported: true,
-    device_supported: false,
+
+    // Device needs perfetto as a shared lib.
+    target: {
+        android: {
+            shared_libs: [
+                "heapprofd_client_api",
+            ],
+        },
+    },
 
     corpus: ["corpus/*"],
     dictionary: "dex.dict",
diff --git a/tools/fuzzer/libart_verify_dex_fuzzer.cc b/tools/fuzzer/libart_verify_dex_fuzzer.cc
index 9f2b935..4bdcc22 100644
--- a/tools/fuzzer/libart_verify_dex_fuzzer.cc
+++ b/tools/fuzzer/libart_verify_dex_fuzzer.cc
@@ -17,10 +17,15 @@
 #include "base/mem_map.h"
 #include "dex/dex_file_loader.h"
 
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+extern "C" int LLVMFuzzerInitialize(int* argc ATTRIBUTE_UNUSED, char*** argv ATTRIBUTE_UNUSED) {
   // Initialize environment.
   art::MemMap::Init();
+  // Set logging to error and above to avoid warnings about unexpected checksums.
+  android::base::SetMinimumLogSeverity(android::base::ERROR);
+  return 0;
+}
 
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
   // Skip compact DEX.
   // TODO(dsrbecky): Remove after removing compact DEX.
   const char* dex_string = "cdex";