A sample project demonstrating use of the Android Game Development Kit libraries. AGDKTunnel is derived from the NDK sample Endless Tunnel.
AGDKTunnel uses the following AGDK libraries:
Open the `samples/agdktunnel' directory in Android Studio 4.2 or higher.
The GLM library must be downloaded before building:
git clone https://github.com/g-truc/glm.git
You can build this application to run in Google Play Games for PC with features like the Input SDK to display keyboard controls and cloud saving using PGS. For an optimized experience consider enabling the following features:
We use Play Games Services (PGS) to sign-in and cloud save to play in Play Games Services and mobile. To enable this feature following the next steps.
app/src/main/res/values/strings.xmlwith the id of your project in the Google Play Console.
We use the Play Asset Delivery (PAD) API with Texture Compression Format Targeting (TCFT) to delivery optimal compressed textures (ETC2 by default and DXT1 for Google Play Games for PC). To enable PAD:
gradle.propertiesfile and change:
java -jar bundletool-all-1.9.1.jar build-apks --bundle=app/build/outputs/bundle/playGamesPCDebug/app-playGamesPC-debug.aab --output=agdktunnel.apks --local-testing java -jar bundletool-all-1.9.1.jar install-apks --apks=agdktunnel.apks
For more information see the codelab: Using Play Asset Delivery in native games
AGDKTunnel integrates the Memory Advice library to receive hints when memory usage is becoming critical and risks being terminated by the OS due to low available memory.
Memory consumption is artificially inflated using the MemoryConsumer class, which also displays status information onscreen. This is off by default. The Consume Memory button in the title screen can be used to enable memory consumption.
When active, the Memory Consumer allocates at random intervals blocks of variable sizes and places them into two memory pools, dubbed ‘General’ and ‘Cache’. If the Memory Advice library signals a critical memory situation, the Memory Consumer frees all allocations from the Cache pool. After the first critical memory warning, the Memory Consumer ceases to allocate into the General pool and only allocates into the Cache pool.
When active, the Memory Consumer displays statistics on screen in the UI and Play scenes. The information is formatted as follows:
(status) (crit warning count) (percent available) (General pool size) (Cache pool size)
OK|WARN|CRIT Memory State reported by the Memory Advice library (crit warning count) The number of times Memory Advice has reported a critical memory shortage (percent available) The estimated percentage of available memory reported by Memory Advice, this is updated every five seconds (General pool size) Total allocation size of the General pool in megabytes (Cache pool size) Total allocation size of the Cache pool in megabytes
Android Performance Tuner is disabled by default. To enable it, perform the following steps:
These steps are described in more detail in the following subsections.
Python is expected to be available in your
protobuf package is expected to have been installed via
pip. In some cases, Android Studio may be using an internal install of Python rather than a system install. If this is the case, you may need to run
pip install protobuf from the Terminal tab in Android Studio.
The APT functionality requires a valid API key to operate. This is not necessary to run the sample. For information on configure an API key for APT, see the Get an API key for the Android Performance Tuner section of the Codelab Integrating Android Performance Tuner into your native Android game.
To enable building the runtime APT assets and use the library at runtime, edit the
gradle.properties file and change:
APTEnabled=true. When switching configurations, it is recommended to sync the gradle file, and run Build -> Refresh Linked C++ Projects and Build -> Clean Project before rebuilding.