-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to build release version of coreclr for android? #33237
Comments
Which .sh script are you using for the build? You don't need to use -DBUILD_TYPE=Release, there is an option of the build script that sets that. If you build it using the build.sh in the src/coreclr, then you just add |
cc @am11 |
@gemSender, we are in process of updating the Android builds. The PRs are under review at the moment. If you could try to build runtime repo (excluding mono for now) with the PR branch following these instructions: #32800 (comment), and give us some feedback that would be help us validating the changes. :) |
For release build, you can add |
I'v tried this but got new error messages when building v2.2.8 released . Then I tried v3.0.3 and got blocked by "liblttng-ust-devel building test" in "src/pal/src/configure.cmake" even if i installed liblttng-ust-devel for ndk 。 I'm trying to build the branch as @am11 mentioned. |
i tried this but got cmake configure error blew:
-- Configuring incomplete, errors occurred! /home/razor/coreclr_runtime_src/src/installer/corehost/build.proj(43,5): error MSB3073: The command "/home/razor/coreclr_runtime_src/src/installer/corehost/build.sh Release arm64 -apphostver "5.0.0-dev" -hostver "5.0.0-dev" -fxrver "5.0.0-dev" -policyver "5.0.0-dev" -commithash "0065943756c868a7603d9c0d4d0dc46fc1ad72ee" -cross" exited with code 1. then I enter command "find .tools/android-rootfs/android-ndk-r21 | grep objcopy"
enter command "whereis objcopy"
|
I was able to build coreclr with my PR branch (on Ubuntu bionic host) with the following command yesterday: ROOTFS_DIR=$(realpath .tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subsetCategory coreclr --configuration Release git hash is tip of my PR branch: $ git rev-parse HEAD
0065943756c868a7603d9c0d4d0dc46fc1ad72ee
$ git status
On branch feature/android-build
Your branch is up to date with 'origin/feature/android-build'. if it all looks the same, could you try cleaning the repo with Commencing CoreCLR Repo build
__DistroRid: android.28-arm64
__RuntimeId: android.28-arm64
Setting up directories for build
Checking prerequisites...
/usr/bin/cmake
Restoring the OptimizationData package
Restore completed in 1.42 sec for /datadrive/projects/runtime4/src/coreclr/src/.nuget/optdata/optdata.csproj.
Commencing build of "CoreCLR component" for Linux.arm64.Release in /datadrive/projects/runtime4/artifacts/obj/coreclr/Linux.arm64.Release
Restore completed in 782.43 ms for /datadrive/projects/runtime4/eng/empty.csproj.
Invoking "/datadrive/projects/runtime4/eng/native/gen-buildsys.sh" "/datadrive/projects/runtime4/src/coreclr" "/datadrive/projects/runtime4/src/coreclr" "/datadrive/projects/runtime4/artifacts/obj/coreclr/Linux.arm64.Release" arm64 clang "" "" Release "" -DCLR_ENG_NATIVE_DIR="/datadrive/projects/runtime4/eng/native" -DCLR_CMAKE_PGO_INSTRUMENT=0 -DCLR_CMAKE_OPTDATA_PATH= -DCLR_CMAKE_PGO_OPTIMIZE=1 -DCLR_REPO_ROOT_DIR="/datadrive/projects/runtime4" -DSTRIP_SYMBOLS=true
loading initial cache file /datadrive/projects/runtime4/src/coreclr/tryrun.cmake
-- Check for working C compiler: /datadrive/projects/android-arm64-rootfs/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
-- Check for working C compiler: /datadrive/projects/android-arm64-rootfs/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /datadrive/projects/android-arm64-rootfs/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ |
I built coreclr native library successfully with the branch you shared , Thank you for your reply ! |
I tried to host coreclr on my Android app, but when I loaded libcoreclr.so with the dlopen function, an error occurred. I called the dlerror function, and the error it returned was "libgcc_s.so.1 not found"。 Is the error relate with linking glibc library while compiling coreclr ? |
I think we would need to copy the whole set of dependencies (or use termux to install them via adb shell), could you also check what BTW, I read your previous comments and thanks a lot for the feedback. I have already opened two PRs to fix the issues you mentioned. It encouraged me to test the build in a docker container (isolated environment) to see what assumptions went wrong from my previous tests. dotnet/arcade#5003, #33342. Still missing a patch (which i have locally ready and tested in docker, need some polishing) for the original Android PR. will take some cycles to smooth things out on the build side. |
It seems that the compile parameter "-fPIC" should be added for android, otherwise when the target api level is greater than 21, the function System.loadLibrary will fail to be called . |
It compiles all native components of product using runtime/eng/native/configureplatform.cmake Line 303 in 13e7f19
grep -lR \-fPIC artifacts/obj # from runtime repo root (after the compilation) |
Is it possible to host coreclr on an non-rooted Android device ? The process got crashes when I call the function "coreclr_initialize".
|
Seems like
LD_PRELOAD to find out if there is any other blocker?
|
Something like: echo "int membarrier(int cmd, int flags) { return 0; }" | gcc -xc -shared -o libcoreclr-33237-workaround.so
LD_PRELOAD=$(pwd)/libcoreclr-33237-workaround.so ./myApp |
When I replaced membarrier with an empty function, the coreclr_initialize function no longer crashed, but it returned an error code of 0x80004005. I tried to debug the startup code by printing logs and found the EEStartupHelper function (located at "runtime/src/coreclr /src/ vm/ ceemain.cpp ") called the InitializeDebugger , this function throws an exception, causing g_EEStartupStatus to be set to E_FAIL. I tried to disable the macro DEBUGGING_SUPPORTED by modifying the file "src/coreclr/ clrdefinitions.cmake", but got some compilation errors. |
Some optional features are not tested in the CI environments, where they are always enabled. |
The first batch of changes are merged @gemSender, here is the docker file which I have used during the development: src: https://gist.github.com/am11/a68aaab2cb803f90a78c3956910ea218 $ docker build --tag dotnet-runtime-android-arm64 - <<'EOF'
FROM ubuntu:bionic
RUN apt update && \
apt install -y git wget unzip libicu-dev clang-9 liblttng-ust-dev locales
RUN echo en_US.UTF-8 UTF-8 >> /etc/locale.gen && \
locale-gen && \
update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV CMAKE_INSTALL_SCRIPT_URL https://github.com/Kitware/CMake/releases/download/v3.16.5/cmake-3.16.5-Linux-x86_64.sh
RUN wget --show-progress --progress=bar:force:noscroll $CMAKE_INSTALL_SCRIPT_URL; sh cmake-3.16.5-Linux-x86_64.sh --skip-license
ARG gfork=dotnet
ARG gbranch=master
RUN git clone https://github.com/$gfork/runtime --branch $gbranch --single-branch --depth 1
WORKDIR runtime
RUN ./eng/common/cross/build-android-rootfs.sh arm64
RUN ROOTFS_DIR=$(realpath /runtime/.tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subsetCategory coreclr --configuration Release
RUN ROOTFS_DIR=$(realpath /runtime/.tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subsetCategory libraries --configuration Release
RUN ROOTFS_DIR=$(realpath /runtime/.tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subsetCategory installer --configuration Release
EOF (for other fork or branch use, e.g. some managed components in installer are failing during the crossgen due to wrong RID resolution, tracked by #33069. I have not yet tried the device testing, or tried to make your issue somehow reproduce in emulator. Do you have any script for reproducible environment (preferably with emulator and NDK installed)? |
Might want to change
|
Yup, at the time Dockerfile was written, there were subset and subsetCategory options, later the latter one was squashed into the former. :) |
That's weird
Note: apparently leaving out |
91f1418 was the last hash which I tested with the aforementioned Dockerfile. At the time mono bits in this repo did not enabled Android cross-compilation, which is why I split the build steps. Now mono subset also build, so we don't need to specify the subsets. It would be nice if we can add the missing bits (related to CoreCLR) in official build docker (currently used for mono+libs+installer in CI without coreclr), so we can enable this: DOTNET_DOCKER_TAG=ubuntu-18.04-android-20200612003336-e2c3f83
docker run --rm -v /datadrive/projects/runtime:/runtime -w /runtime \
mcr.microsoft.com/dotnet-buildtools/prereqs:$DOTNET_DOCKER_TAG \
./build.sh (versions are available at https://github.com/dotnet/versions/blob/master/build-info/docker/image-info.dotnet-dotnet-buildtools-prereqs-docker-master.json) |
@CircuitRCAY it looks like you're hitting #40727 |
I'm building coreclr without Docker or Debian (or derivs), and I'm no longer hitting #40727. Building this under Arch Linux is somewhat trivial:
Full log: https://hastebin.com/umucohabaj.sql |
Still finding issues building coreclr and the installer: https://asciinema.org/a/oMMVVJH1GO1iXY8dPll1zgACX |
I am trying to build the runtime for android (following the directions in https://github.com/dotnet/runtime/tree/a89dcada9eb18e7a370b82027c256c7e16d9e7be/docs/workflow/building/coreclr/android.md). However, the scripts seems to be outdated; there are references to scripts that no longer exist or scripts that have changed names. The instructions mention the script The runtime/eng/common/cross/build-android-rootfs.sh Lines 125 to 131 in 894b730
which I edited to be executed and updated to ROOTFS_DIR=\$\($__ToolchainDir/.tools/android-rootfs/android-ndk-r21/sysroot\) ./build.sh --cross --arch $__BuildArch --subset clr
ROOTFS_DIR=\$\($__ToolchainDir/.tools/android-rootfs/android-ndk-r21/sysroot\) ./build.sh --cross --arch $__BuildArch --subset libs
ROOTFS_DIR=\$\($__ToolchainDir/.tools/android-rootfs/android-ndk-r21/sysroot\) ./build.sh --cross --arch $__BuildArch --subset installer which, after calling https://github.com/dotnet/runtime/blob/558d49245b050de4235d7420f06c5f0ddc41b8ed/eng/common/build.sh and https://github.com/dotnet/runtime/blob/b9d26c89e9b789dc36ef630fc1533cf912926cf1/eng/native/init-distro-rid.sh, throws an error in https://github.com/dotnet/runtime/tree/c80b6f42af88205539a88eb1d712779e30162317/eng/common/cross/toolchain.cmake at line 87 runtime/eng/common/cross/toolchain.cmake Line 87 in 894b730
when it cannot find the file Unfortunately, I am stuck at this point. Does anyone have some guidance on how to continue or some up-to-date instructions I could follow? My end goal is to be able to use the dotnet cli to build and run packages in the termux android application. |
@nathanpovo I've tried to run the ./eng/common/cross/build-android-rootfs.sh arm64 For arm: ./eng/common/cross/build-android-rootfs.sh arm I've tried to build coreclr using the command the script has printed at the end and it worked too. |
The command ./eng/common/cross/build-android-rootfs.sh arm64 executes successfully. The issue I am having is with the printed commands. Running ROOTFS_DIR=$(realpath /home/nathan/github/dotnet/runtime/.tools/android-rootfs/android-ndk-r21/sysroot) ./build.sh --cross --arch arm64 --subset clr I get the following output:
For some reason, the percentage does not always reach the same amount; if I rerun the command I get higher and higher percentages. I tried running the command multiple times and the highest it got was 25%. |
Android with CoreCLR is not an officially supported platform right now; it is a community supported platform. It is 'point in time' kind of support. If we fix it today, there is no guarantee the build will sustain tomorrow as we have evidentially seen in this thread alone; with all the infrastructural as well as the code changes being checked in. Android with Mono is a an officially supported platform. It has libcoreclr.so build out of src/mono/netcore. It has a CI leg, which runs for every Pull Request. If you are interested in using .NET with Android, IMO, you can try out Mono option. If you really want CoreCLR support, then (IMO again), we should create a 'distilled' docker builder image out of these scripts, as done for FreeBSD (dotnet/dotnet-buildtools-prereqs-docker#277) and illumos (dotnet/dotnet-buildtools-prereqs-docker#324), and finally create a downstream CI for those, as done for FreeBSD: https://github.com/wfurt/freebsd-bootstrap-cli/blob/4289056/.cirrus.yml and illumos: https://github.com/am11/runtime/blob/b0c224e/.github/workflows/main.yml. This is to keep up with the daily changes. |
I was mostly experimenting to see if it was possible to build the clr for Android to be able to use it in the Termux app. However, with all the changes it might be worth waiting for .NET 6.0 to come out which should have official support for building for Android. Thank you for the quick response, @am11. |
For me, the clr build command passed 100% for both arm and arm64, so it sounds like some missing build dependency or some kind of a problem with the distro you are building it on. Can you please share the full log from the failed build using a gist? The fact that the percentages are different each time is expected. The build runs on multiple processors at the same time, so it always manages to build some sub-project before it fails on a problematic one. Since the build is incremental, next time it starts little farther. |
@janvorli where can I find the log? |
@nathanpovo just cut and paste the console output starting at the build command. |
https://gist.github.com/nathanpovo/927aaabdc5924180d25f32b5351ec75b I started the build from scratch to show the full log. |
I've just found what's wrong. I've tried the build again, this time in a different checkout of the runtime repo and it failed the same way as for you. I've then checked the checkout I've tried it in before and it still worked. Looking at the state of that checkout reveals the reason. In the checkout I was trying it before, I had a state from March for some reason (commit bc28cbe at the head). At that time, it worked. Now it does not. |
I've ran a git bisect to find the change that has broken the Android build. It was this one: #35173 - Port CoreCLR to SunOS
I haven't looked at what in that change has broken it. @am11 do you happen to have any quick ideas? |
Actually I fixed the Android build in February #32800. There are dozens of breaking changes since. I am surprised that git bisect has only found my other PR, while the error @nathanpovo is encountering is:
and that header was added in: 5c99007#diff-7ede8c5e272d0eff6c61b098c43459717e75840c2b333caee9d5fd0fe5cce81f My previous comment was intended as: unless someone looks after Android (or any other platform for that matter) properly, such build breakages are inevitable. |
@am11 I completely agree that since we don't test / officially support Android with coreclr, it can break any time. |
I append “cmakeargs -DBUILD_TYPE=Release" at the end of build command and still got debug version with huge size of "libcoreclr.so"
The text was updated successfully, but these errors were encountered: