Skip to content

Commit 2d5c982

Browse files
Improve docs for building & running CoreCLR Android on Windows + WSL (#118672)
* Add command for installing additional tools * Update CoreCLR Android doc * Update table of contents * Rename SDK_VER to ANDROID_CLI_TOOLS_VER * Bump versions * Update WSL specific steps * Fix link * Bump version
1 parent 953f308 commit 2d5c982

File tree

3 files changed

+74
-48
lines changed

3 files changed

+74
-48
lines changed

docs/workflow/building/coreclr/android.md

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
# Experimental support of CoreCLR on Android
22

3-
This is the internal documentation which outlines experimental support of CoreCLR on Android and includes instructions on how to:
4-
- [Build CoreCLR for Android](./android.md#building-coreclr-for-android)
5-
- [Build and run a sample application with CoreCLR](./android.md#building-and-running-a-sample-app)
6-
- [Debug the sample app and the runtime](./android.md#debugging-the-runtime-and-the-sample-app)
7-
8-
## Prerequisite
9-
10-
- Download and install [OpenJDK 23](https://openjdk.org/projects/jdk/23/)
11-
- Download and install [Android Studio](https://developer.android.com/studio/install) and the following:
12-
- Android SDK (minimum supported API level is 21)
13-
- Android NDK r27
14-
15-
> [!NOTE]
16-
> Prerequisites can also be downloaded and installed manually:
17-
> - by running the automated script as described in [Testing Libraries on Android](../../testing/libraries/testing-android.md#using-a-terminal)
18-
> - by downloading the archives:
19-
> - Android SDK - Download [command-line tools](https://developer.android.com/studio#command-line-tools-only) and use `sdkmanager` to download the SDK.
20-
> - Android NDK - Download [NDK](https://developer.android.com/ndk/downloads)
3+
This is the internal documentation which outlines experimental support of CoreCLR on Android.
4+
5+
## Table of Contents
6+
7+
- [Prerequisite](#prerequisite)
8+
- [Building CoreCLR for Android](#building-coreclr-for-android)
9+
- [MacOS and Linux](#macos-and-linux)
10+
- [Requirements](#requirements)
11+
- [Building the runtime, libraries and tools](#building-the-runtime-libraries-and-tools)
12+
- [Windows + WSL2](#windows--wsl2)
13+
- [Windows requirements](#windows-requirements)
14+
- [WSL requirements](#wsl-requirements)
15+
- [Building the runtime, libraries and tools](#building-the-runtime-libraries-and-tools-1)
16+
- [Building and running a sample app](#building-and-running-a-sample-app)
17+
- [Building HelloAndroid sample](#building-helloandroid-sample)
18+
- [Running HelloAndroid sample on an emulator](#running-helloandroid-sample-on-an-emulator)
19+
- [WSL2](#wsl2)
20+
- [Building and running tests on an emulator](#building-and-running-tests-on-an-emulator)
21+
- [Debugging the runtime and the sample app](#debugging-the-runtime-and-the-sample-app)
22+
- [Steps](#steps)
23+
- [See also](#see-also)
24+
- [Troubleshooting](#troubleshooting)
25+
- [Android samples or functional tests fail to build](#android-samples-or-functional-tests-fail-to-build)
26+
- [java.lang.NullPointerException: Cannot invoke String.length()](#javalangnullpointerexception-cannot-invoke-stringlength)
2127

2228
## Building CoreCLR for Android
2329

@@ -34,11 +40,23 @@ Supported target architectures:
3440

3541
### MacOS and Linux
3642

37-
#### Requirements
43+
#### Prerequisites
44+
45+
- Download and install [OpenJDK 23](https://openjdk.org/projects/jdk/23/)
46+
- Download and install [Android Studio](https://developer.android.com/studio/install) and the following:
47+
- Android SDK (minimum supported API level is 21)
48+
- Android NDK r27c
49+
50+
> [!NOTE]
51+
> Prerequisites can also be downloaded and installed manually:
52+
> - An automated script as described in [Testing Libraries on Android](../../testing/libraries/testing-android.md#using-a-terminal)
53+
> - Downloading the archives:
54+
> - Android SDK - Download [command-line tools](https://developer.android.com/studio#command-line-tools-only) and use `sdkmanager` to download the SDK.
55+
> - Android NDK - Download [NDK](https://developer.android.com/ndk/downloads)
3856
3957
Set the following environment variables:
40-
- ANDROID_SDK_ROOT=`<full-path-to-android-sdk>`
41-
- ANDROID_NDK_ROOT=`<full-path-to-android-ndk>`
58+
- `export ANDROID_SDK_ROOT=<full-path-to-android-sdk>`
59+
- `export ANDROID_NDK_ROOT=<full-path-to-android-ndk>`
4260

4361
#### Building the runtime, libraries and tools
4462

@@ -57,22 +75,32 @@ To build CoreCLR runtime NuGet packages, run the following command from `<repo-r
5775
> [!NOTE]
5876
> The runtime packages will be located at: `<repo-root>/artifacts/packages/<configuration>/Shipping/`
5977
60-
### Windows
78+
### Windows + WSL2
6179

6280
Building on Windows is not directly supported yet. However it is possible to use WSL2 for this purpose.
6381

64-
#### WSL2
82+
#### Windows prerequisites
83+
84+
- Download and install [Android Studio](https://developer.android.com/studio/install)
85+
- Enable [long paths](../../requirements/windows-requirements.md#enable-long-paths)
6586

66-
##### Requirements
87+
#### WSL prerequisites
6788

68-
1. Install the Android SDK and NDK in WSL per the [prerequisites](#prerequisite). This can be done by downloading the archives or using Android Studio.
89+
1. Follow [linux-requirements.md](../../requirements/linux-requirements.md).
90+
2. Install OpenJDK, Android SDK and Android NDK in as described in [Linux prerequisites](#prerequisites). There is a convenient automated script, but it can also be done manually by downloading the archives or using Android Studio.
6991
- In case of Android Studio:
7092
- Make sure WSL is updated: from Windows host, `wsl --update`
7193
- [Enabled systemd](https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/#set-the-systemd-flag-set-in-your-wsl-distro-settings)
7294
- `sudo snap install android-studio --classic`
73-
2. Set the following environment variables:
74-
- ANDROID_SDK_ROOT=`<full-path-to-android-sdk>`
75-
- ANDROID_NDK_ROOT=`<full-path-to-android-ndk>`
95+
- For Ubuntu, OpenJDK 21 is sufficient:
96+
97+
```
98+
apt install openjdk-21-jdk
99+
```
100+
101+
3. Set the following environment variables:
102+
- `export ANDROID_SDK_ROOT=<full-path-to-android-sdk>`
103+
- `export ANDROID_NDK_ROOT=<full-path-to-android-ndk>`
76104

77105
#### Building the runtime, libraries and tools
78106

@@ -84,9 +112,7 @@ To build CoreCLR runtime, libraries and tools, run the following command from `<
84112

85113
## Building and running a sample app
86114

87-
To demonstrate building and running an Android sample application with CoreCLR, we will use:
88-
- the [HelloAndroid sample app](../../../../src/mono/sample/Android/AndroidSampleApp.csproj).
89-
- a functional tests [Android.Device_Emulator.JIT.Test](../../../../src/tests/FunctionalTests/Android/Device_Emulator/JIT/Android.Device_Emulator.JIT.Test.csproj)
115+
To demonstrate building and running an Android application with CoreCLR, we will use the [HelloAndroid sample app](../../../../src/mono/sample/Android/AndroidSampleApp.csproj).
90116

91117
A prerequisite for building and running samples locally is to have CoreCLR successfully built for desired Android platform.
92118

@@ -128,30 +154,24 @@ The app can be run on an emulator running on the Windows host.
128154
2. In Windows, create and start an emulator
129155
3. In WSL, swap the `adb` from the Android SDK in WSL2 with that from Windows
130156
- `mv $ANDROID_SDK_ROOT/platform-tools/adb $ANDROID_SDK_ROOT/platform-tools/adb-orig`
131-
- `ln -s /mnt/<path-to-adb-on-host> $ANDROID_SDK_ROOT/platform-tools/adb`
157+
- `ln -s /mnt/<path-to-sdk-on-host>/platform-tools/adb.exe $ANDROID_SDK_ROOT/platform-tools/adb`
158+
- On Windows host, you can find the SDK location in Android Studio's SDK Manager.
132159
4. In WSL, Make xharness use the `adb` corresponding to the Windows host:
133160
- `export ADB_EXE_PATH=$ANDROID_SDK_ROOT/platform-tools/adb`
134161
5. In WSL, run the `make` command as [above](#running-helloandroid-sample-on-an-emulator)
135162
136-
### Building and running functional tests on an emulator
163+
## Building and running tests on an emulator
137164
138-
Similarly to the `HelloAndroid` sample, it is possible to build and run a functional test on Android with CoreCLR on an emulator.
165+
To demonstrate building and running tests on CoreCLR Android, we will use the [Android.Device_Emulator.JIT.Test](../../../../src/tests/FunctionalTests/Android/Device_Emulator/JIT/Android.Device_Emulator.JIT.Test.csproj) test project.
139166
140-
To build and run a functional test on Android with CoreCLR, run the following command from `<repo_root>`:
167+
To build and run the test on Android with CoreCLR, run the following command from `<repo_root>`:
141168
142169
```
143-
./dotnet.sh build -c Release src/tests/FunctionalTests/Android/Device_Emulator/JIT/Android.Device_Emulator.JIT.Test.csproj /p:TargetOS=android /p:TargetArchitecture=arm64 /t:Test /p:RuntimeFlavor=coreclr
170+
./dotnet.sh build -c <Debug|Release> src/tests/FunctionalTests/Android/Device_Emulator/JIT/Android.Device_Emulator.JIT.Test.csproj /p:TargetOS=android /p:TargetArchitecture=<x64|arm64> /t:Test /p:RuntimeFlavor=coreclr
144171
```
145172
146173
> [!NOTE]
147-
> Similarly to the `HelloAndroid` sample the emulator needs to be up and running.
148-
149-
### Useful make commands
150-
151-
For convenience it is possible to run a single make command which builds all required dependencies, the app and runs it:
152-
```
153-
make BUILD_CONFIG=<Debug|Release> TARGET_ARCH=<x64|arm64> RUNTIME_FLAVOR=CoreCLR DEPLOY_AND_RUN=true all -C src/mono/sample/Android
154-
```
174+
> Similarly to the `HelloAndroid` sample, the emulator needs to be up and running.
155175
156176
## Debugging the runtime and the sample app
157177
@@ -191,6 +211,8 @@ Similar instructions for debugging Android apps with Mono runtime can be found [
191211
192212
### Android samples or functional tests fail to build
193213
214+
#### java.lang.NullPointerException: Cannot invoke String.length()
215+
194216
If multiple JDKs are installed on your system, you may encounter the following error:
195217
196218
```

docs/workflow/requirements/linux-requirements.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ If you're planning to use your environment to do Linux cross-building to other a
9595
- `qemu`
9696
- `qemu-user-static`
9797

98+
```bash
99+
apt install binfmt-support debootstrap qemu qemu-user-static
100+
```
101+
98102
### Fedora
99103

100104
These instructions are written assuming *Fedora 40*.

docs/workflow/testing/libraries/testing-android.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ Android SDK and NDK can be automatically installed via the following script:
2323
set -e
2424

2525
NDK_VER=r27c
26-
SDK_VER=9123335_latest
27-
SDK_API_LEVEL=33
28-
SDK_BUILD_TOOLS=33.0.1
26+
ANDROID_CLI_TOOLS_VER=13114758_latest
27+
SDK_API_LEVEL=36
28+
SDK_BUILD_TOOLS=36.0.0
2929

3030
if [[ "$OSTYPE" == "darwin"* ]]; then
3131
HOST_OS=darwin
@@ -45,7 +45,7 @@ unzip ~/andk.zip -d $(dirname ${ANDROID_NDK_ROOT}) && rm -rf ~/andk.zip
4545
# download Android SDK, accept licenses and download additional packages such as
4646
# platform-tools, platforms and build-tools
4747
export ANDROID_SDK_ROOT=~/android-sdk
48-
curl https://dl.google.com/android/repository/commandlinetools-${HOST_OS_SHORT}-${SDK_VER}.zip -L --output ~/asdk.zip
48+
curl https://dl.google.com/android/repository/commandlinetools-${HOST_OS_SHORT}-${ANDROID_CLI_TOOLS_VER}.zip -L --output ~/asdk.zip
4949
mkdir ${ANDROID_SDK_ROOT} && unzip ~/asdk.zip -d ${ANDROID_SDK_ROOT}/cmdline-tools && rm -rf ~/asdk.zip
5050
yes | ${ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} --licenses
5151
${ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools/bin/sdkmanager --sdk_root=${ANDROID_SDK_ROOT} "platform-tools" "platforms;android-${SDK_API_LEVEL}" "build-tools;${SDK_BUILD_TOOLS}"

0 commit comments

Comments
 (0)