https://github.com/jakobbbb/unitynativeandroidcmake
CMake-based setup for developing native Unity plugins for Android
https://github.com/jakobbbb/unitynativeandroidcmake
android cmake native-plugin unity
Last synced: 2 months ago
JSON representation
CMake-based setup for developing native Unity plugins for Android
- Host: GitHub
- URL: https://github.com/jakobbbb/unitynativeandroidcmake
- Owner: jakobbbb
- Created: 2024-10-21T13:55:20.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-11-22T16:24:32.000Z (6 months ago)
- Last Synced: 2025-01-27T06:11:58.619Z (4 months ago)
- Topics: android, cmake, native-plugin, unity
- Language: Mathematica
- Homepage:
- Size: 96.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# UnityNativeAndroidCMake
This repo contains a simple CMake-based setup for developing native
Unity plugins for Android as well as Linux and Windows.The `./NativePlugin` directory contains code to build a sample plugin,
while `./UnityProject` contains a sample Unity project for this plugin.
Before opening the project, you must first compile the native plugin.## Setup
This repo is configured to work out of the box with the included plugin
and Unity project, as well as given that your Unity Editor is installed
via Unity Hub at the default location and with NDK (i.e. Android Build
Support) included. If this is not the case on your system, or you wish
to adapt the CMake setup for your own needs, please consider the
following:A Unity project into which the plugin is to be installed must be
specified. This is set to `./UnityProject` by default and can be
overridden by setting the `UNITY_PROJECT_DIR` CMake flag.Given the Unity project, the CMake setup will extract the project's
Unity version and attempt to locate both the Unity Editor (for inclusion
of the Unity header files) as well as the NDK (for native compilation on
Android).If your Unity editor is not installed at the default location
(`~/Unity/Hub/Editor//Editor` on Linux,
`C:/Program Files/Unity/Hub/Editor//Editor"` on Windows),
set the `UNITY_EDITOR` flag accordingly. Note that the directory this
points to should contain the Unity executable.If you're not using the NDK supplied with Unity, you must set the
`ANDROID_NDK` flag to the NDK directory. Note that this is the
directory containing the `ndk-build` and `ndk-gdb` scripts, among
others.## Building on Linux
The following will build the plugin and copy it to the Unity project's
plugin directory:```bash
cd NativePlugin
make clean && make
```You can specify CMake flags for the Unity project directory, as well as
the Unity Editor and NDK locations as follows:
```bash
make CMAKE_FLAGS="-DUNITY_PROJECT_DIR=/path/to/project -DUNITY_EDITOR=/path/to/Editor -DANDROID_NDK=/path/to/NDK"
```### Building for Android on Linux
Instead of just running `make`, run `make anrdoid`. You may have to run
`make clean` beforehand.## Note: Installation to the Unity Project
The plugin will be installed into the Unity project, e.g. at
`Assets/Plugins/Linux/libNativePlugin.so` or
`/Assets/Plugins/Windows/NativePlugin.dll`.
Note that each plugin must have an associated `.meta` file specifying
which platforms to run the plugin on.
These are located in `NativePlugin/meta` and copied to the project's
`Assets` directory along with the native library itself.This is done because Unity will automatically delete any `.meta` files
referencing files that do not exist. That is, opening the project on
Linux would auto-delete `NativePlugin.dll.meta`.