|
|
(One intermediate revision by one other user not shown) |
Line 1: |
Line 1: |
− | The following instructions apply to '''v1.2 and later'''. For earlier versions the best documentation is https://github.com/vcmi/vcmi-android/blob/master/building.txt (and reading scripts in that repo), however very limited to no support will be provided from our side if you wish to go down that rabbit hole.
| + | {{Template:MovedToWebpage|https://vcmi.eu/developers/Building_Android/}} |
− | | |
− | ''Note'': building has been tested only on Linux and macOS. It may or may not work on Windows out of the box.
| |
− | | |
− | == Requirements ==
| |
− | # CMake 3.20+: download from your package manager or from https://cmake.org/download/
| |
− | # Android command line tools or Android Studio for your OS: https://developer.android.com/studio/
| |
− | # JDK 11, not necessarily from Oracle
| |
− | # Android NDK version '''r25c (25.2.9519653)''', there're multiple ways to obtain it:
| |
− | #* install with Android Studio
| |
− | #* install with <code>sdkmanager</code> command line tool
| |
− | #* download from https://developer.android.com/ndk/downloads
| |
− | #* download with Conan, see [[#NDK and Conan]]
| |
− | # (optional) Ninja: download from your package manager or from https://github.com/ninja-build/ninja/releases
| |
− | | |
− | == Obtaining source code ==
| |
− | Clone https://github.com/vcmi/vcmi with submodules. Example for command line:
| |
− | <nowiki>git clone --recurse-submodules https://github.com/vcmi/vcmi.git</nowiki>
| |
− | | |
− | == Obtaining dependencies ==
| |
− | We use Conan package manager to build/consume dependencies, find detailed usage instructions [https://github.com/vcmi/vcmi/tree/develop/docs/conan.md here]. Note that the link points to the cutting-edge state in <code>develop</code> branch, for the latest release check the same document in the [https://github.com/vcmi/vcmi/tree/master/docs/conan.md master branch].
| |
− | | |
− | On the step where you need to replace '''PROFILE''', choose:
| |
− | * <code>android-32</code> to build for 32-bit architecture (armeabi-v7a)
| |
− | * <code>android-64</code> to build for 64-bit architecture (aarch64-v8a)
| |
− | | |
− | === NDK and Conan ===
| |
− | Conan must be aware of the NDK location when you execute <code>conan install</code>. There're multiple ways to achieve that as written in the [https://docs.conan.io/1/integrations/cross_platform/android.html Conan docs]:
| |
− | * the easiest is to download NDK from Conan (option 1 in the docs), then all the magic happens automatically. You need to create your own Conan profile that imports our Android profile and adds 2 new lines (you can of course just copy everything from our profile into yours without including) and then pass this new profile to <code>conan install</code>:
| |
− | <nowiki>include(/path/to/vcmi/CI/conan/android-64)
| |
− | [tool_requires]
| |
− | android-ndk/r25c</nowiki>
| |
− | * to use an already installed NDK, you can simply pass it on the command line to <code>conan install</code>:
| |
− | <nowiki>conan install -c tools.android:ndk_path=/path/to/ndk ...</nowiki>
| |
− | | |
− | == Build process ==
| |
− | Building for Android is a 2-step process. First, native C++ code is compiled to a shared library (unlike executable on other platforms), then Java code is compiled to an actual executable which will be loading the native shared library at runtime.
| |
− | | |
− | === C++ code ===
| |
− | This is a traditional CMake project, you can build it from command line or some IDE. You're not required to pass any custom options (except Conan toolchain file), defaults are already good. If you wish to use your own CMake presets, inherit them from our <code>build-with-conan</code> preset. Example:
| |
− | | |
− | <nowiki>cmake -S . -B ../build -G Ninja -D CMAKE_BUILD_TYPE=Debug --toolchain ...
| |
− | cmake --build ../build</nowiki>
| |
− | | |
− | You can also see a more detailed walkthrough on CMake configuration at [[How to build VCMI (macOS)#Configuring project for building]].
| |
− | | |
− | === Java code ===
| |
− | After the C++ part is built, native shared libraries are copied to the appropriate location of the Java project (they will be packaged in the APK). You can either open the Java project located in <code>android</code> directory of the repo in Android studio and work with it as with any Android project or build from command line.
| |
− | | |
− | Example how to build from command line in Bash shell, assumes that current working directory is VCMI repository:
| |
− | <nowiki># the following environment variables must be set
| |
− | export JAVA_HOME=/path/to/jdk11
| |
− | export ANDROID_HOME=/path/to/android/sdk
| |
− | | |
− | cd android
| |
− | ./gradlew assembleDebug</nowiki>
| |
− | | |
− | APK will appear in <code>android/vcmi-app/build/outputs/apk/debug</code> directory which you can then install to your device with <code>adb install -r /path/to/apk</code> (adb command is from Android command line tools).
| |
− | | |
− | If you wish to build and install to your device in single action, use <code>installDebug</code> instead of <code>assembleDebug</code>.
| |