Skip to content

how to build release version of coreclr for android? #33237

Description

@gemSender

I append “cmakeargs -DBUILD_TYPE=Release" at the end of build command and still got debug version with huge size of "libcoreclr.so"

Activity

  1. janvorli commented on Mar 5, 2020

    @janvorli
    Member

    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 Release to the command line. If you build it using the build.sh in the root, the option is -runtimeConfiguration Release, but I think that it has been recently changed to be the default.
    There is also a -stripsymbols option to strip the symbols from the binaries.

  2. jkotas commented on Mar 5, 2020

    @jkotas
    Member
  3. am11 commented on Mar 5, 2020

    @am11
    Member

    @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. :)

  4. am11 commented on Mar 5, 2020

    @am11
    Member

    For release build, you can add --configuration Release to the build.sh command.
    (I have just rebased my branch with dotnet/master, also trying out a fresh build)

  5. gemSender commented on Mar 6, 2020

    @gemSender
    Author

    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 Release to the command line. If you build it using the build.sh in the root, the option is -runtimeConfiguration Release, but I think that it has been recently changed to be the default.
    There is also a -stripsymbols option to strip the symbols from the binaries.

    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.

  6. gemSender commented on Mar 6, 2020

    @gemSender
    Author

    For release build, you can add --configuration Release to the build.sh command.
    (I have just rebased my branch with dotnet/master, also trying out a fresh build)

    i tried this but got cmake configure error blew:

    CMake Error at /home/razor/coreclr_runtime_src/eng/native/configuretools.cmake:66 (message):
    objcopy not found
    Call Stack (most recent call first):
    CMakeLists.txt:6 (include)

    -- Configuring incomplete, errors occurred!
    See also "/home/razor/coreclr_runtime_src/artifacts/obj/android.28-arm64.Release/CMakeFiles/CMakeOutput.log".

    /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"

    .tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/x86_64-linux-android/bin/objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/bin/objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/i686-linux-android/bin/objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/share/man/man1/aarch64-linux-android-objcopy.1
    .tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/share/man/man1/x86_64-linux-android-objcopy.1
    .tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/share/man/man1/i686-linux-android-objcopy.1
    .tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/share/man/man1/arm-linux-androideabi-objcopy.1
    .tools/android-rootfs/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/arm-linux-androideabi/bin/objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/x86_64-4.9/prebuilt/linux-x86_64/x86_64-linux-android/bin/objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/x86_64-4.9/prebuilt/linux-x86_64/bin/x86_64-linux-android-objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/x86_64-4.9/prebuilt/linux-x86_64/share/man/man1/x86_64-linux-android-objcopy.1
    .tools/android-rootfs/android-ndk-r21/toolchains/x86-4.9/prebuilt/linux-x86_64/i686-linux-android/bin/objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/x86-4.9/prebuilt/linux-x86_64/share/man/man1/i686-linux-android-objcopy.1
    .tools/android-rootfs/android-ndk-r21/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/share/man/man1/arm-linux-androideabi-objcopy.1
    .tools/android-rootfs/android-ndk-r21/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-objcopy
    .tools/android-rootfs/android-ndk-r21/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/share/man/man1/aarch64-linux-android-objcopy.1

    enter command "whereis objcopy"

    objcopy: /usr/bin/objcopy /usr/share/man/man1/objcopy.1.gz

  7. am11 commented on Mar 6, 2020

    @am11
    Member

    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 git clean -xdf, followed by eng/common/cross/build-android-rootfs.sh then execute above command. Also please show this part of the logs (where native build commences):

      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++
  8. gemSender commented on Mar 7, 2020

    @gemSender
    Author

    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 git clean -xdf, followed by eng/common/cross/build-android-rootfs.sh then execute above command. Also please show this part of the logs (where native build commences):

      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 !

  9. gemSender commented on Mar 9, 2020

    @gemSender
    Author

    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 git clean -xdf, followed by eng/common/cross/build-android-rootfs.sh then execute above command. Also please show this part of the logs (where native build commences):

      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 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 ?

  10. 29 remaining items

  11. janvorli commented on Nov 10, 2020

    @janvorli
    Member

    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.

  12. janvorli commented on Nov 11, 2020

    @janvorli
    Member

    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
    The problem is a failure to find an ICU include:

      In file included from /home/janvorli/git/runtime4/src/libraries/Native/Unix/System.Globalization.Native/pal_casing.c:9:
      /home/janvorli/git/runtime4/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h:23:10: fatal error: 'unicode/ucurr.h' file not found
      #include <unicode/ucurr.h>
    

    I haven't looked at what in that change has broken it. @am11 do you happen to have any quick ideas?

  13. am11 commented on Nov 11, 2020

    @am11
    Member

    I've ran a git bisect to find the change that has broken the Android build

    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:

    /home/nathan/github/dotnet/runtime/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h:22:10: fatal error: 'unicode/uclean.h' file not found

    and that header was added in:

    5c99007#diff-7ede8c5e272d0eff6c61b098c43459717e75840c2b333caee9d5fd0fe5cce81f
    (this was not me..)

    My previous comment was intended as: unless someone looks after Android (or any other platform for that matter) properly, such build breakages are inevitable.

  14. janvorli commented on Nov 11, 2020

    @janvorli
    Member

    @am11 I completely agree that since we don't test / officially support Android with coreclr, it can break any time.

  15. dotnet-policy-service commented on May 13, 2025

    @dotnet-policy-service
    Contributor

    Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

    This process is part of our issue cleanup automation.

  16. dotnet-policy-service commented on May 27, 2025

    @dotnet-policy-service
    Contributor

    This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

  17. removed this from the Future milestone on May 27, 2025
  18. locked and limited conversation to collaborators on Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions