This page describes how to run an end-to-end test using a demo app and the
Google Play Console.

## Steps

To download the SDK, run the demo app, verify the app is working correctly, and
view frame timing information from the app in the Google Play Console, do the
following:

1. Clone the main branch of the [Android Open Source Project](https://android.googlesource.com/platform/frameworks/opt/gamesdk/) Games SDK Repository.
2. Build and run the demo app.
3. Run the monitor app.
4. Create a release build.
5. Run the release build.
6. View the graphs in the Google Play Console.

## Build and run the demo app

Run the APT Insights Demo app in Android Studio to make sure everything
builds correctly. This project uses CMake for native code building and shows how
to use the `gamesdk.cmake` file, which is the easiest way to get started.

To run the demo app, do the following:

1. Open Android Studio.
2. Click **File \> Open** and select `gamesdk/samples/tuningfork/insightsdemo/build.gradle`.
3. Wait for Android Studio to sync the project.
4. Connect a device (or [create a virtual device](https://developer.android.com/studio/run/managing-avds)) to run the sample. Enable [developer options and USB debugging](https://developer.android.com/studio/debug/dev-options#enable) on the device.
5. Select the target device and click **Run**
   ![Android Studio Run button](https://developer.android.com/static/studio/images/buttons/toolbar-run.png).
   For more information, see [Build and run your app](https://developer.android.com/studio/run).

   ![](https://developer.android.com/static/images/games/performance-tuner/test-app.png) **Figure 1.** Test app running successfully
6. The sample APK should build and install on the target device. If you
   encounter errors, check the following:

   - You have a [supported version](https://developer.android.com/games/sdk#requirements) of the Android SDK; see the `compileSdkVersion` field in the app module `build.gradle` file for more information. You can [update the SDK version](https://developer.android.com/studio/intro/update#sdk-manager) from the **SDK Platforms** tab in the SDK Manager.
   - You have a [supported version](https://developer.android.com/games/sdk#requirements) of the Android NDK; see the `ndkVersion` field in the app module `build.gradle` file for more information. You can [install a specific version of the NDK](https://developer.android.com/studio/projects/install-ndk#specific-version) from the **SDK Tools** tab in the SDK Manager.
   - The `local.properties` file in the project does *not* have an entry for `ndk.dir`. This location is specified by Android Studio and uses the NDK version from above. If you have this entry, clear the entire line.
   - After any build setting change, clean the project (**Build \> Clean
     Project** ) and refresh the linked C++ projects (**Build \> Refresh Linked
     C++ Projects**).

## Run the monitor app

With a debug build of the demo app or any other Tuning Fork-enabled app,
you can configure the app to send and receive data from a local endpoint rather
than the Google Play server. To do this, set the `endpoint_uri_override` in
the Tuning Fork settings:  

    #ifndef NDEBUG
       settings.endpoint_uri_override = "http://localhost:9000";
    #endif

You must also include the following permissions in the `AndroidManifest.xml`
file:  

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

The demo app already has these changes (see [`insightsdemo.cpp`](https://android.googlesource.com/platform/frameworks/opt/gamesdk/+/refs/heads/master/samples/tuningfork/insightsdemo/app/src/main/cpp/insightsdemo.cpp)).

You can use this feature to verify that an app is sending and receiving the
proper data. To verify this, run the demo app and the Tuning Fork Monitor app at
the same time. This monitoring app acts as a local server and displays the data
that a Tuning Fork-enabled app produces.

To run the monitoring app and demo app at the same time to verify that the demo
app is working properly, do the following:

1. Install the Tuning Fork Monitor app APK on the target device using [adb](https://developer.android.com/studio/command-line/adb):  

   ```
   adb install gamesdk/gamesdk/apks/tools/TuningForkMonitor.apk
   ```
2. Open the monitoring app.
3. Press the Android Home button to send the Tuning Fork Monitor app to the background on the device.
4. [Run the demo app](https://developer.android.com/games/sdk/performance-tuner/custom-engine/run-demo-app#run-demo-app) again in the foreground for about 30 seconds.
5. Switch back to the Tuning Fork Monitor app.
6. The demo app appears under **Live Applications** as `com.tuningfork.insightsdemo 16`. Tap this entry to see app details and live telemetry.

![](https://developer.android.com/static/images/games/performance-tuner/monitor-app1.png) **Figure 2.** The monitor app detects the demo app  
![](https://developer.android.com/static/images/games/performance-tuner/monitor-app2.png) **Figure 3.** The monitor app displays data from the demo app

## Create a release build

Create a release build of the demo app in Android Studio. You upload this build
to the Google Play Console to enable frame timing graphs in Android Vitals.

1. [Enable the Android Performance Parameters API](https://developer.android.com/games/sdk/performance-tuner/custom-engine/enable-api)
   in Google Cloud Console. This API enables the app to communicate with
   Google Play. You don't need to restrict the API key for the demo app.

2. Make sure to copy your API key from the previous step into the `api_key`
   field in
   `gamesdk/samples/tuningfork/insightsdemo/app/src/main/assets/tuningfork/tuningfork_settings.txt`.

3. The demo app's application ID is reserved, so can't upload an APK that uses
   it. Change this ID in the app's `build.gradle` file:

   ```
   applicationId "com.tuningfork.your-unique-identifier"
   ```
4. Clean the project (**Build \> Clean Project** ) and refresh the linked C++
   projects (**Build \> Refresh Linked C++ Projects**).

5. Create a signing configuration for release builds.

   1. Select **File \> Project Structure \> Modules**.
   2. Select the **Signing Configs** tab.
   3. Add a new configuration named `release`.
   4. [Create a keystore](https://developer.android.com/studio/publish/app-signing#generate-key) for the configuration.
6. Associate the release signing configuration with the release build variant.

   1. Select **File \> Project Structure \> Build Variants**.
   2. Select the **Build Types** tab.
   3. Select the build type named `release`.
   4. In the **Signing Config** box, select the release configuration variable.
7. In the Android Studio project window, select the **app** directory. (This
   selection enables the menu selection in the next step.)

8. Change the active build variant to `release` (**Build \> Select Build
   Variant**).

9. Select **Build \> Build Bundles(s)/APK(s) \> Build APK(s)** . When the build
   completes, click the **locate** link to find the release APK.

10. Create a new application for the demo app in the Google Play Console. For
    more information, see
    [Upload an app](https://support.google.com/googleplay/android-developer/answer/113469).

11. Upload the release APK to the **Internal test track** . For more information,
    see
    [Prepare \& roll out releases](https://support.google.com/googleplay/android-developer/answer/7159011).

    | **Note:** You must upload the APK to an internal test track on Google Play. If you do not, privacy filters block the associated graph from appearing.

## Run the release build

Select the target device and click **Run**
![Android Studio Run button](https://developer.android.com/static/studio/images/buttons/toolbar-run.png).
You must use the same release APK that you uploaded to the
Google Play Console.

Let the demo app run for awhile. It can take up to 30 minutes for the Google
Play Console to start displaying data. Verify that data is uploading to the
server by selecting the **Info** log level in the **Logcat** window. If you see
errors in the log, see
[Troubleshoot common errors](https://developer.android.com/games/sdk/performance-tuner/custom-engine/troubleshooting).  

    ... I/TuningFork:Web: Connecting to:
        https://performanceparameters.googleapis.com/v1/applications/com.tuningfork.yourapp/apks/24:uploadTelemetry
    ... I/TuningFork: Scene loading 30 (true) took 166 ms
    ... I/TuningFork:Web: Response code: 200
    ... I/TuningFork:Web: Response message: OK
    ... I/TuningFork.GE: UPLOAD request returned 200 {}

| **Note:** Make sure to run the release build variant or else data won't upload to the Google Play Console.

## View the graphs in the Google Play Console

Open the Google Play Console and select the test application. Select **Android
Vitals \> Performance \> Insights** to see the frame time graph.

![](https://developer.android.com/static/images/games/performance-tuner/android-vitals-rendering.png)
**Figure 4.** Android vitals graph

You have successfully run an end-to-end test with the Tuning Fork
library. You can delete the test app project in the Google Play Console, as it
is no longer needed.