Building Android Runtime (ART) for (native) Linux

283 views
Skip to first unread message

Kunal Sareen

unread,
Nov 3, 2022, 4:36:07 PM11/3/22
to Android Building
Hi all,

I'm trying to build and run the Android Runtime (ART) standalone (i.e. natively) on a Linux (Ubuntu 22.04) system. I'm trying to do this to have a faster turn-around time for development (I'm planning on working on ART for a research project).

My understanding is that I need to use the `silvermont-eng` target, which I set using `lunch`. However, if I try to build ART as an APEX package (as is mentioned in the ART build README), then the built executables expect the runtime linker to be at `/system/bin/linker` so fail to run natively on the Linux machine.

Here's how I've built the above (I'm using the `master-art` manifest in order to only build ART):
```
source build/envsetup.sh
export SOONG_ALLOW_MISSING_DEPENDENCIES=true
lunch silvermont-eng
TARGET_BUILD_APPS="com.android.art" TARGET_BUILD_UNBUNDLED=true m
```

I presume the issues are related to building an APEX package for ART. Is there a way to not build an APEX package then?

Any help you can offer will be much appreciated.

Sincerely,
Kunal
Message has been deleted
Message has been deleted

Kunal Sareen

unread,
Nov 16, 2022, 2:09:49 PM11/16/22
to Android Building
Hi Orion,

Thank you for the tips! I'm now attempting to add a simple prebuilt library to the ART runtime, but I can't seem to get it to link properly. What I've done is this so far:

Create new file "simple_example.h" in "art/runtime":

    #ifndef ART_RUNTIME_SIMPLE_H
    #define ART_RUNTIME_SIMPLE_H
    namespace simple {
    extern void simple_print(int num);
    }
    #endif

Where the `simple_print(int)` function is implemented as a Rust library.

I then use the `simple_print()` function in some ART code by importing the header and using the function like: `simple::simple_print(10);`

I then copy the `libsimple.so` prebuilt library into the respective "prebuilts/runtime/mainline/runtime/sdk/{os}/{arch}/lib/" directories.  I've then edited two SOONG blueprint files:

"art/runtime/Android.bp":

@@ -485,6 +485,7 @@ libart_cc_defaults {
         "libbase", // For common macros.
         "liblog",
         "liblz4",
+        "libsimple",
         "liblzma", // libelffile(d) dependency; must be repeated here since it's a static lib.
         "libnativebridge",
         "libnativeloader",

(i.e. I've added the library to the "shared_libs" for "libart_cc_defaults")

"prebuilts/runtime/mainline/runtime/sdk/Android.bp":

@@ -1612,6 +1612,54 @@ cc_prebuilt_library_static {
     },
 }

+cc_prebuilt_library_shared {
+    name: "libsimple",
+    prefer: true,
+    visibility: ["//visibility:public"],
+    apex_available: [
+        "com.android.art",
+        "com.android.art.debug",
+    ],
+    target: {
+        host: {
+            enabled: true,
+        },
+        android: {
+            compile_multilib: "both",
+        },
+        android_arm64: {
+            srcs: ["android/arm64/lib/libsimple.so"],
+        },
+        android_x86_64: {
+            srcs: ["android/x86_64/lib/libsimple.so"],
+        },
+        android_arm: {
+            srcs: ["android/arm/lib/libsimple.so"],
+        },
+        android_x86: {
+            srcs: ["android/x86/lib/libsimple.so"],
+        },
+        linux_bionic: {
+            compile_multilib: "64",
+        },
+        linux_bionic_x86_64: {
+            enabled: true,
+            srcs: ["linux_bionic/x86_64/lib/libsimple.so"],
+        },
+        linux_glibc_x86_64: {
+            enabled: true,
+            srcs: ["linux_glibc/x86_64/lib/libsimple.so"],
+        },
+        linux_glibc_x86: {
+            enabled: true,
+            srcs: ["linux_glibc/x86/lib/libsimple.so"],
+        },
+    },
+    strip: {
+        none: true,
+    }
+}
+
 sdk_snapshot {
     name: "runtime-module-sdk@current",
     visibility: ["//visibility:public"],

However, building it gives me an error like: "module libart missing dependencies: libsimple{os:linux_glibc,arch:x86_64,link:shared}". Note I created the "linux_glibc" directory to "prebuilts/runtime/mainline/runtime/sdk/" myself which I though would have been a fix for the error, but unfortunately it did not work.

Any help you can offer will be much appreciated. Thank you for your time.

Sincerely,
Kunal

On Tuesday, November 15, 2022 at 9:28:25 PM UTC+11 Orion Hodson wrote:
Hi Kunal

You can build ART for host with the master-art manifest using:

$ cd $ANDROID_BUILD_TOP
$ . build/envsetup.sh
$ lunch silvermont-eng
$ art/tools/buildbot-build.sh --host

You can check your changes don't break existing tests unexpectedly running:

$ art/test.py --host -r -g

Good luck
Orion

--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-...@googlegroups.com
To unsubscribe from this group, send email to
android-buildi...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to the Google Groups "Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-buildi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-building/04804340-d186-4ec7-87fb-8dde31f9381en%40googlegroups.com.

Orion Hodson

unread,
Nov 24, 2022, 4:45:46 AM11/24/22
to android-...@googlegroups.com
The lunch target is arbitrary if doing a host build. The one cited is plucked from `art/test/README.chroot.md`.

The `buildbot-build.sh --host` invocation does a fairly minimal host build and builds all the dependencies needed for ART and libcore tests.

On Wed, 16 Nov 2022 at 19:08, 'Fabien Sanglard' via Android Building <android-...@googlegroups.com> wrote:
Why not use `aosp_x86_64-eng` target?

```
source build/envsetup.sh
lunch aosp_x86_64-eng
m -j62 dalvikvm
out/host/linux-x86/bin/dalvikvm -showversion
```

Outputs:
```
ART version 2.1.0 x86_64
```
--
--
You received this message because you are subscribed to the "Android Building" mailing list.
To post to this group, send email to android-...@googlegroups.com
To unsubscribe from this group, send email to
android-buildi...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

---
You received this message because you are subscribed to the Google Groups "Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-buildi...@googlegroups.com.

Orion Hodson

unread,
Nov 28, 2022, 2:17:46 PM11/28/22
to android-...@googlegroups.com
Hi Kunal

If you are building for host, use the buildbot-build.sh script.

Your command-line is building for a silvermont device so attempting to build a lot more than you need.

The prebuilts are just that: prebuilts, they are not intended for modification. If you want to add a library to ART look at the libraries already under art/, e.g. libartbase.

Whilst rust is interesting, it's not something we have a specific use for in ART at the moment: no data / pointers on how to do that for the time being.

Thanks
Orion


Reply all
Reply to author
Forward
0 new messages