make android_app_write_cmd() publicly available

This CL exposes android_app_write_cmd() function which has been
previously only used internally. It can be useful for implementing
custom events at the game_activity_glue level.

Bug: 371512572
Test: ./build.sh tests
Change-Id: Iaa2a343b14f2749ea6d47b495d49b8c39b092c55
2 files changed
tree: f7c88f93fad3218ba8fc1160c53cff038d2f4422
  1. buildSrc/
  2. game-activity/
  3. game-text-input/
  4. games-controller/
  5. games-frame-pacing/
  6. games-memory-advice/
  7. games-performance-tuner/
  8. gradle/
  9. hooks/
  10. include/
  11. samples/
  12. src/
  13. test/
  14. third_party/
  15. .clang-format
  16. .gitignore
  17. ab_info.py
  18. ARCHIVED
  19. build.bat
  20. build.gradle
  21. build.sh
  22. download.sh
  23. gradle.properties
  24. gradlew
  25. gradlew.bat
  26. LICENSE
  27. OWNERS
  28. PREUPLOAD.cfg
  29. README.md
  30. RELEASE_NOTES
  31. settings.gradle
  32. THIRD_PARTY_NOTICES
  33. VERSIONS
README.md

Android Game Development Kit (AGDK)

Integrating the AGDK libraries in your game

Unless you need to compile AGDK from sources, it's recommended that you use the package with the pre-compiled library. You can download it on https://developer.android.com/games/agdk.

Build AGDK

In order to build AGDK, this project must be initialized using the repo tool. On Windows, we recommend running all commands involving repo with Git Bash, and setting git config --global core.symlinks true to avoid issues with symlinks.

mkdir android-games-sdk
cd android-games-sdk
repo init -u https://android.googlesource.com/platform/manifest -b android-games-sdk

Build with locally installed SDK/NDK

If the Android SDK is already installed locally, then download only the AGDK source and build tools (~500Mb).

repo sync -c -j8 gamesdk
repo sync -c -j8 external/modp_b64 external/googletest external/nanopb-c external/protobuf external/StatsD tools/repohooks
repo sync -c -j8 prebuilts/cmake/linux-x86 prebuilts/cmake/windows-x86 prebuilts/cmake/darwin-x86

Point the environment variable ANDROID_HOME to your local Android SDK (and ANDROID_NDK, if the ndk isn't in ANDROID_HOME/ndk-bundle). Use the following gradle tasks to build the Game SDK with or without Tuning Fork:

cd gamesdk
# Build Swappy:
./gradlew packageLocalZip -Plibraries=swappy -PpackageName=local
# Build Swappy and Tuning Fork:
./gradlew packageLocalZip -Plibraries=swappy,tuningfork -PpackageName=localtf

Note that it may be necessary to use Android SDK Manager to download particular versions of Android SDK, NDK and cmake as expected by the build. The error message should provide guidance in that case.

Build with specific prebuilt SDKs

Download the project along with specific versions of prebuilt Android SDK and NDK (~4GB). First, download the core project and tools:

repo sync -c -j8 gamesdk
repo sync -c -j8 external/modp_b64 external/googletest external/nanopb-c external/protobuf
repo sync -c -j8 prebuilts/cmake/linux-x86 prebuilts/cmake/windows-x86 prebuilts/cmake/darwin-x86

Cmake and Ninja binaries must be in your PATH like below. Please replace PLATFORM_NAME with either linux-x86 for Linux or darwin-86 for MacOS or windows-x86 for Windows, and run the following command:

export PATH="$PATH:`pwd`/prebuilts/cmake/PLATFORM_NAME/bin"
export PATH="$PATH:`pwd`/prebuilts/ninja/PLATFORM_NAME"

Next, use the download script to get prebuilt SDKs and/or NDKs.

cd gamesdk
./download.sh

Finally, build AGDK using downloaded prebuilts.

cd gamesdk
# Build and package Swappy in a ZIP file:
ANDROID_HOME=`pwd`/../prebuilts/sdk ANDROID_NDK=`pwd`/../prebuilts/ndk/r20 ./gradlew packageLocalZip -Plibraries=swappy -PpackageName=local
# Build and package Swappy and Tuning Fork in a ZIP file:
ANDROID_HOME=`pwd`/../prebuilts/sdk ANDROID_NDK=`pwd`/../prebuilts/ndk/r20 ./gradlew packageLocalZip -Plibraries=swappy,tuningfork -PpackageName=localtf

Build with all prebuilt SDKs

Download the whole repository with all available prebuilt Android SDKs and NDKs (~23GB).

repo sync -c -j8

Build static and dynamic libraries for several SDK/NDK pairs.

cd gamesdk
ANDROID_HOME=`pwd`/../prebuilts/sdk ./gradlew packageZip -Plibraries=swappy,tuningfork

Build properties reference

The command lines presented earlier are a combination of a build or packaging task, and a set of properties.

Build tasks are:

  • build: build the libraries with prebuilt SDK/NDK.
  • buildLocal: build the libraries with your locally installed Android SDK and NDK.
  • buildUnity: build the libraries with the (prebuilt) SDK/NDK for use in Unity.
  • buildAar: build the libraries with prebuilt SDK/NDK for distribution in a AAR with prefab.

Packaging tasks are:

  • packageZip: create a zip of the native libraries for distribution.
  • packageLocalZip: create a zip with the libraries compiled with your locally installed Android SDK and NDK.
  • packageUnityZip: create a zip for integration in Unity.
  • packageMavenZip: create a zip with the native libraries in a AAR file in Prefab format and a pom file. You can also use packageAar to only get the AAR file.

Properties are:

  • -Plibraries=swappy,tuningfork: comma-separated list of libraries to build (for packaging/build tasks).
  • -PpackageName=gamesdk: the name of the package, for packaging tasks. Defaults to “gamesdk”.
  • -PbuildType=Release: the build type, “Release” (default) or “Debug”.
  • Sample related properties:
    • -PincludeSampleSources: if specified, build tasks will include in their output the sources of the samples of the libraries that are built.
    • -PincludeSampleArtifacts: if specified, build tasks will also compile the samples and projects related to the libraries, and include their resulting artifact in the packaged archive.
    • -PskipSamplesBuild: if specified and -PincludeSampleArtifacts is specified, this will skip the actual gradle build of the samples and projects related to the libraries. Use this when you want to check that the packaging works correctly and don't want to rebuild everything.

Here are some commonly used examples:

# All prebuilt SDKs, with sample sources:
ANDROID_HOME=`pwd`/../prebuilts/sdk ./gradlew packageZip -Plibraries=swappy,tuningfork -PpackageName=fullsdk -PincludeSampleSources

# All prebuilt SDKs, with sample sources and precompiled samples:
ANDROID_HOME=`pwd`/../prebuilts/sdk ./gradlew packageZip -Plibraries=swappy,tuningfork -PpackageName=fullsdk -PincludeSampleSources -PincludeSampleArtifacts

# Swappy or Swappy+TuningFork for Unity:
./gradlew buildUnity --Plibraries=swappy --PpackageName=swappyUnity
./gradlew buildUnity --Plibraries=swappy,tuningfork --PpackageName=unity

# Zips to upload AARs to Maven:
./gradlew packageMavenZip -Plibraries=swappy -PpackageName=fullsdk
./gradlew packageMavenZip -Plibraries=tuningfork -PpackageName=fullsdk

Tests

./gradlew localUnitTests # Requires a connected ARM64 device to run
./gradlew localDeviceInfoUnitTests # No device required, tests are running on host

Samples

Samples are classic Android projects, using CMake to build the native code. They are also all triggering the build of AGDK.

Using Grade command line:

cd samples/bouncyball && ./gradlew assemble
cd third_party/cube && ./gradlew assemble
cd samples/tuningfork/insightsdemo && ./gradlew assemble
cd samples/tuningfork/experimentsdemo && ./gradlew assemble

The Android SDK/NDK exposed using environment variables (ANDROID_HOME) will be used for building both the sample project and AGDK.

Using Android Studio

Open projects using Android Studio:

  • samples/bouncyball
  • third_party/cube
  • samples/tuningfork/insightsdemo
  • samples/tuningfork/experimentsdemo

and run them directly (Shift + F10 on Linux, Control + R on macOS). The local Android SDK/NDK (configured in Android Studio) will be used for building both the sample project and AGDK.

Development and debugging

After opening a sample project using Android Studio, uncomment the line containing add_gamesdk_sources(). This will add the Swappy/Tuning Fork sources as part of the project. You can then inspect the source code (with working auto completions) and run the app in debug mode (with working breakpoints and inspectors).

Note for macOS Users

You may find that the APT demos will not build on your machine because protoc is being blocked by security settings. A warning dialog message is displayed: "protoc" cannot be opened because the developer cannot be verified"

In this case, please follow the instructions in the following article to allow protoc to be run: https://support.apple.com/en-gb/guide/mac-help/mh40616/mac