mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-01 03:39:18 -05:00
Updated Working for Android (markdown)
@ -1,46 +1,106 @@
|
|||||||
**NOTE: This guide is intended for Android development on Windows platform, for alternative platforms, check:**
|
> [!NOTE]
|
||||||
- [Working for Android on macOS](https://github.com/raysan5/raylib/wiki/Working-for-Android-(on-macOS))
|
> This guide is intended for Android development on Windows platform, for alternative platforms, check:
|
||||||
- [Working for Android on Linux](https://github.com/raysan5/raylib/wiki/Working-for-Android-(on-Linux))
|
> - [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
|
## 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
|
### 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
|
### 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.
|
- 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.
|
||||||
- From command line, navigate to `android-sdk/tools/bin` and execute the following commands:
|
|
||||||
```
|
- Open a command prompt, navigate to `android-sdk/tools/bin`, and run the following commands:
|
||||||
sdkmanager --sdk_root=<your_path_sdk> --update
|
```
|
||||||
sdkmanager --sdk_root=<your_path_sdk> --list
|
sdkmanager --sdk_root=<path_to_sdk> --update
|
||||||
sdkmanager --sdk_root=<your_path_sdk> --install build-tools;29.0.3
|
sdkmanager --sdk_root=<path_to_sdk> --install build-tools;<version>
|
||||||
sdkmanager --sdk_root=<your_path_sdk> --install platform-tools
|
sdkmanager --sdk_root=<path_to_sdk> --install platform-tools
|
||||||
sdkmanager --sdk_root=<your_path_sdk> --install platforms;android-28
|
sdkmanager --sdk_root=<path_to_sdk> --install platforms;android-<api_level>
|
||||||
sdkmanager --sdk_root=<your_path_sdk> --install extras;google;usb_driver
|
sdkmanager --sdk_root=<path_to_sdk> --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).
|
|
||||||
|
> [!NOTE]
|
||||||
|
> To find available versions and API levels:
|
||||||
|
> ```
|
||||||
|
> sdkmanager --sdk_root=<path_to_sdk> --list
|
||||||
|
> ```
|
||||||
|
|
||||||
### 3. Android NDK
|
### 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=<your_path_sdk> --install ndk;<version>
|
||||||
|
```
|
||||||
|
|
||||||
## 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 <build_system> \
|
||||||
|
-DCMAKE_BUILD_TYPE=Release \
|
||||||
|
-DCMAKE_TOOLCHAIN_FILE=<path_to_ndk>/build/cmake/android.toolchain.cmake \
|
||||||
|
-DPLATFORM=Android \
|
||||||
|
-DANDROID_ABI=<abi> \
|
||||||
|
-DANDROID_PLATFORM=<minimum-api-level> \
|
||||||
|
-DBUILD_EXAMPLES=OFF # or ON if you want examples
|
||||||
|
cmake --build Build
|
||||||
|
```
|
||||||
|
**Explanation of placeholders:**
|
||||||
|
* `<build_system>` → Your build system generator. `Ninja` is recommended.
|
||||||
|
* `<path_to_ndk>` → Full path to your installed Android NDK directory.
|
||||||
|
* `<abi>` → Target CPU architecture: `armeabi-v7a`, `arm64-v8a`, `x86`, or `x86_64`.
|
||||||
|
* `<minimum-api-level>` → 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=<path_to_ndk> \
|
||||||
|
ANDROID_API_VERSION=<minimum-api-level> \
|
||||||
|
ANDROID_ARCH=<abi>
|
||||||
|
```
|
||||||
|
- 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
|
## Implementation for Android Studio
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user