diff --git a/Working-for-Android.md b/Working-for-Android.md index 6361841..cfa3c17 100644 --- a/Working-for-Android.md +++ b/Working-for-Android.md @@ -1,46 +1,106 @@ -**NOTE: This guide is intended for Android development on Windows platform, for alternative platforms, check:** - - [Working for Android on macOS](https://github.com/raysan5/raylib/wiki/Working-for-Android-(on-macOS)) - - [Working for Android on Linux](https://github.com/raysan5/raylib/wiki/Working-for-Android-(on-Linux)) +> [!NOTE] +> This guide is intended for Android development on Windows platform, for alternative platforms, check: +> - [Working for Android on macOS](https://github.com/raysan5/raylib/wiki/Working-for-Android-(on-macOS)) +> - [Working for Android on Linux](https://github.com/raysan5/raylib/wiki/Working-for-Android-(on-Linux)) ## Installing required tools -Android requires a set of tools to do all the build process to generate a .APK game. +Android requires a set of tools to do all the build process to generate an APK: ### 1. Open JDK -You can just download the JDK from [here](https://jdk.java.net/13/) and decompress it in a directory, raylib `Makefile.Android` scripts looks for it on `C:\open-jdk`. +You can download the JDK from [here](https://jdk.java.net/13/) and extract it to a directory. The raylib `Makefile.Android` scripts expect it to be located at `C:\open-jdk`. ### 2. Android SDK -Actually, Android SDK is composed by a series of tools, you can install everything in a go just downloading [Android Studio](https://developer.android.com/studio/#downloads) and installing the full package. +Actually, the Android SDK consists of several tools, but you can install everything at once by downloading [Android Studio](https://developer.android.com/studio/#downloads) and installing the full package. -Alternatively, you can just install the required files manually. To do that, start downloading `Command line tools` package, found at the end of this [page](https://developer.android.com/studio/#command-tools). +Alternatively, you can install only the required tools manually. To do this, download the Command line tools package, located at the bottom of this [page](https://developer.android.com/studio/#command-tools). - - Decompress downloaded `sdk-tools-...` file into a folder named `android-sdk`. One of the included tools is the [sdkmanager]((https://developer.android.com/studio/command-line/sdkmanager)), a command line utility to install required packages. - - From command line, navigate to `android-sdk/tools/bin` and execute the following commands: -``` -sdkmanager --sdk_root= --update -sdkmanager --sdk_root= --list -sdkmanager --sdk_root= --install build-tools;29.0.3 -sdkmanager --sdk_root= --install platform-tools -sdkmanager --sdk_root= --install platforms;android-28 -sdkmanager --sdk_root= --install extras;google;usb_driver -``` -With those commands you're installing all required tools. It includes: `tools`, `build-tools`, `platform-tools`, `platforms\android-28` api level and also `extras\google\usb_driver` (that you need to install to connect to your device). +- Decompress the downloaded `sdk-tools-...` file into a folder named `android-sdk`. One of the included tools is [sdkmanager](https://developer.android.com/studio/command-line/sdkmanager), a command-line utility for installing the required packages. + +- Open a command prompt, navigate to `android-sdk/tools/bin`, and run the following commands: + ``` + sdkmanager --sdk_root= --update + sdkmanager --sdk_root= --install build-tools; + sdkmanager --sdk_root= --install platform-tools + sdkmanager --sdk_root= --install platforms;android- + sdkmanager --sdk_root= --install extras;google;usb_driver + ``` + +> [!NOTE] +> To find available versions and API levels: +> ``` +> sdkmanager --sdk_root= --list +> ``` ### 3. Android NDK -To develop with raylib in C, we need to install the Android Native Development Kit. You can download it from [here](https://developer.android.com/ndk/downloads/). Android NDK includes support files for multiple Android APIs and multiple architectures. raylib scripts expect to use NDK r21 and found it available on `C:\android-ndk`. +To develop with Raylib in C, you need to install the Android Native Development Kit (NDK). +- You can download it directly from [here](https://developer.android.com/ndk/downloads/). +- Alternatively, you can install it using `sdkmanager`: + ``` + sdkmanager --sdk_root= --install ndk; + ``` -## Compiling raylib source code +The Android NDK supports multiple Android APIs and architectures (ABIs). The supported ABIs are: `armeabi-v7a`, `arm64-v8a`, `x86`, and `x86_64`. Support for `riscv64` is experimental in the latest NDK versions (see [this](https://github.com/google/android-riscv64) for details). -To compile raylib sources, just navigate from command line to directory `raylib/src/` and execute `Makefile` with: +By default, Raylib’s scripts use NDK r21 and expect it to be located at `C:\android-ndk`. - mingw32-make PLATFORM=PLATFORM_ANDROID +### 4. Compiling raylib for Android -NOTE: libraylib.a will be generated in `raylib/src` directory by default. +You can build raylib using either **CMake** or **Make**. Follow the steps below depending on your preferred method. -WARNING: Maybe your Android device uses a 64bit CPU but be careful, installed Android OS could still be 32bit, not allowing 64bit apps. +1. **Using CMake** + - Clone the repository: + ``` + git clone https://github.com/raysan5/raylib.git + cd raylib + ``` + - Build raylib as a static library: + ``` + rm -rf Build + cmake -B Build \ + -G \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_TOOLCHAIN_FILE=/build/cmake/android.toolchain.cmake \ + -DPLATFORM=Android \ + -DANDROID_ABI= \ + -DANDROID_PLATFORM= \ + -DBUILD_EXAMPLES=OFF # or ON if you want examples + cmake --build Build + ``` + **Explanation of placeholders:** + * `` → Your build system generator. `Ninja` is recommended. + * `` → Full path to your installed Android NDK directory. + * `` → Target CPU architecture: `armeabi-v7a`, `arm64-v8a`, `x86`, or `x86_64`. + * `` → Minimum Android API level to support (See [this](https://developer.android.com/ndk/guides/cmake#android_platform) for details). + + - After building, the static library `libraylib.a` will be located in `Build/raylib/` + +2. **Using Make** + + - Navigate to the source folder: + ``` + cd raylib/src + ``` + - Build the library: + ``` + make clean + make PLATFORM=PLATFORM_ANDROID \ + ANDROID_NDK= \ + ANDROID_API_VERSION= \ + ANDROID_ARCH= + ``` + - By default, the static library `libraylib.a` will be generated in `raylib/src/` + +> [!WARNING] +> Your Android device may have a 64-bit CPU, but the installed OS could still be 32-bit. Make sure the selected ABI matches your device architecture. + +> [!NOTE] +> You can build raylib as a shared library (`-DBUILD_SHARED_LIBS=ON` for CMake, `RAYLIB_LIBTYPE=SHARED` for Make), but this is discouraged due to [known issues](https://github.com/raysan5/raylib/issues/5114). + +--- ## Implementation for Android Studio