|
| 1 | +# Example App using Live Objects |
| 2 | + |
| 3 | +This demo app showcases Ably Live Objects functionality with two interactive features: |
| 4 | + |
| 5 | +- **Color Voting**: Real-time voting system where users can vote for their favorite color (Red, Green, Blue) and see live vote counts synchronized across all devices |
| 6 | +- **Task Management**: Collaborative task management where users can add, edit, and delete tasks that sync in real-time across all connected devices |
| 7 | + |
| 8 | +Follow the steps below to get started with the Live Objects demo app |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +Ensure you have the following installed: |
| 13 | +- [Android Studio](https://developer.android.com/studio) (latest stable version) |
| 14 | +- Java 17 or higher |
| 15 | +- Android SDK with API Level 34 or higher |
| 16 | + |
| 17 | +Add your Ably key to the `local.properties` file: |
| 18 | + |
| 19 | +```properties |
| 20 | +sdk.dir=/path/to/android/sdk |
| 21 | + |
| 22 | +EXAMPLES_ABLY_KEY=xxxx:yyyyyy |
| 23 | +``` |
| 24 | + |
| 25 | +## Steps to Run the App |
| 26 | + |
| 27 | +1. Open in Android Studio |
| 28 | + |
| 29 | + - Open Android Studio. |
| 30 | + - Select File > Open and navigate to the cloned repository. |
| 31 | + - Open the project. |
| 32 | + |
| 33 | +2. Sync Gradle |
| 34 | + |
| 35 | + - Wait for Gradle to sync automatically. |
| 36 | + - If it doesn’t, click on Sync Project with Gradle Files in the toolbar. |
| 37 | + |
| 38 | +3. Configure an Emulator or Device |
| 39 | + |
| 40 | + - Set up an emulator or connect a physical Android device. |
| 41 | + - Ensure the device is configured with at least Android 5.0 (API 21). |
| 42 | + |
| 43 | +4. Run the App |
| 44 | + |
| 45 | + - Select your emulator or connected device in the device selector dropdown. |
| 46 | + - Click on the Run button ▶️ in the toolbar or press Shift + F10. |
| 47 | + |
| 48 | +5. View the App |
| 49 | + |
| 50 | + Once the build is complete, the app will be installed and launched on the selected device or emulator. |
| 51 | + |
| 52 | +## What You'll See |
| 53 | + |
| 54 | +The app opens with two tabs: |
| 55 | + |
| 56 | +1. **Color Voting Tab**: |
| 57 | + - Vote for Red, Green, or Blue colors |
| 58 | + - See real-time vote counts that update instantly across all devices |
| 59 | + - Reset all votes with the "Reset all" button |
| 60 | + |
| 61 | +2. **Task Management Tab**: |
| 62 | + - Add new tasks using the text input and "Add Task" button |
| 63 | + - Edit existing tasks by clicking the edit icon |
| 64 | + - Delete individual tasks or remove all tasks at once |
| 65 | + - See the total task count and real-time updates as tasks are modified |
| 66 | + |
| 67 | +To see the real-time synchronization in action, run the app on multiple devices or emulators with the same Ably key. |
| 68 | + |
| 69 | +## Building release APK |
| 70 | + |
| 71 | +This is useful to check ProGuard rules, app size, etc. |
| 72 | + |
| 73 | +1. Create signing keys for the Android app |
| 74 | + |
| 75 | +```shell |
| 76 | +keytool -genkey -v -keystore release.keystore \ |
| 77 | +-storepass <store-password> \ |
| 78 | +-alias <key-alias> \ |
| 79 | +-keypass <key-password> \ |
| 80 | +-keyalg RSA -keysize 2048 -validity 25000 -dname "CN=Ably Example App,OU=Examples,O=Ably,L=London,ST=England,C=GB" |
| 81 | +``` |
| 82 | + |
| 83 | +2. Update `local.properties` file: |
| 84 | + |
| 85 | +```properties |
| 86 | +EXAMPLES_STORE_FILE=/absolute/path/to/release.keystore |
| 87 | +EXAMPLES_STORE_PASSWORD=<store-password> |
| 88 | +EXAMPLES_KEY_ALIAS=<key-alias> |
| 89 | +EXAMPLES_KEY_PASSWORD=<key-password> |
| 90 | +``` |
| 91 | + |
| 92 | +3. Build release APK |
| 93 | + |
| 94 | +```shell |
| 95 | +./gradlew :examples:assembleRelease |
| 96 | +``` |
| 97 | + |
| 98 | +4. Install to the device |
| 99 | + |
| 100 | +```shell |
| 101 | +adb install -r examples/build/outputs/apk/release/examples-release.apk |
| 102 | +``` |
| 103 | + |
| 104 | +## Troubleshooting |
| 105 | + |
| 106 | +- SDK Not Found: Install missing SDK versions from File > Settings > Appearance & Behavior > System Settings > Android SDK. |
| 107 | +- Build Failures: Check the error logs and resolve dependencies or configuration issues. |
0 commit comments