$npx -y skills add hanamizuki/solopreneur --skill gplay-gradle-buildBuild, sign, and package Android apps with Gradle before uploading to Google Play. Use when asked to create an APK or AAB, configure signing, or set up build pipelines.
| 1 | # Gradle Build for Google Play |
| 2 | |
| 3 | Use this skill when you need to build an Android app before uploading to Play Store. |
| 4 | |
| 5 | ## Build Types |
| 6 | |
| 7 | ### App Bundle (AAB) - Recommended |
| 8 | App Bundles are required for new apps on Google Play: |
| 9 | |
| 10 | ```bash |
| 11 | ./gradlew bundleRelease |
| 12 | ``` |
| 13 | |
| 14 | Output: `app/build/outputs/bundle/release/app-release.aab` |
| 15 | |
| 16 | ### APK - Legacy |
| 17 | For apps not using bundles: |
| 18 | |
| 19 | ```bash |
| 20 | ./gradlew assembleRelease |
| 21 | ``` |
| 22 | |
| 23 | Output: `app/build/outputs/apk/release/app-release.apk` |
| 24 | |
| 25 | ## Signing Configuration |
| 26 | |
| 27 | ### build.gradle (app level) |
| 28 | ```groovy |
| 29 | android { |
| 30 | signingConfigs { |
| 31 | release { |
| 32 | storeFile file(System.getenv("KEYSTORE_FILE") ?: "release.keystore") |
| 33 | storePassword System.getenv("KEYSTORE_PASSWORD") |
| 34 | keyAlias System.getenv("KEY_ALIAS") |
| 35 | keyPassword System.getenv("KEY_PASSWORD") |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | buildTypes { |
| 40 | release { |
| 41 | signingConfig signingConfigs.release |
| 42 | minifyEnabled true |
| 43 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | ``` |
| 48 | |
| 49 | ### Environment Variables |
| 50 | ```bash |
| 51 | export KEYSTORE_FILE=/path/to/release.keystore |
| 52 | export KEYSTORE_PASSWORD=your_keystore_password |
| 53 | export KEY_ALIAS=your_key_alias |
| 54 | export KEY_PASSWORD=your_key_password |
| 55 | |
| 56 | ./gradlew bundleRelease |
| 57 | ``` |
| 58 | |
| 59 | ## Version Management |
| 60 | |
| 61 | ### gradle.properties |
| 62 | ```properties |
| 63 | VERSION_NAME=1.2.3 |
| 64 | VERSION_CODE=123 |
| 65 | ``` |
| 66 | |
| 67 | ### build.gradle |
| 68 | ```groovy |
| 69 | android { |
| 70 | defaultConfig { |
| 71 | versionCode project.property('VERSION_CODE').toInteger() |
| 72 | versionName project.property('VERSION_NAME') |
| 73 | } |
| 74 | } |
| 75 | ``` |
| 76 | |
| 77 | ### Increment version |
| 78 | ```bash |
| 79 | # Read current version |
| 80 | CURRENT_VERSION=$(grep VERSION_CODE gradle.properties | cut -d'=' -f2) |
| 81 | NEW_VERSION=$((CURRENT_VERSION + 1)) |
| 82 | |
| 83 | # Update gradle.properties |
| 84 | sed -i "" "s/VERSION_CODE=$CURRENT_VERSION/VERSION_CODE=$NEW_VERSION/" gradle.properties |
| 85 | |
| 86 | # Build |
| 87 | ./gradlew bundleRelease |
| 88 | ``` |
| 89 | |
| 90 | ## ProGuard/R8 Configuration |
| 91 | |
| 92 | ### Enable R8 (default in AGP 3.4+) |
| 93 | ```groovy |
| 94 | buildTypes { |
| 95 | release { |
| 96 | minifyEnabled true |
| 97 | shrinkResources true |
| 98 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
| 99 | } |
| 100 | } |
| 101 | ``` |
| 102 | |
| 103 | ### Generate mapping file |
| 104 | Mapping file location: `app/build/outputs/mapping/release/mapping.txt` |
| 105 | |
| 106 | Upload to Play Console for crash symbolication: |
| 107 | ```bash |
| 108 | gplay deobfuscation upload \ |
| 109 | --package com.example.app \ |
| 110 | --edit $EDIT_ID \ |
| 111 | --apk-version 123 \ |
| 112 | --type proguard \ |
| 113 | --file app/build/outputs/mapping/release/mapping.txt |
| 114 | ``` |
| 115 | |
| 116 | ## Build Variants |
| 117 | |
| 118 | ### Product Flavors |
| 119 | ```groovy |
| 120 | android { |
| 121 | flavorDimensions "version" |
| 122 | productFlavors { |
| 123 | free { |
| 124 | dimension "version" |
| 125 | applicationIdSuffix ".free" |
| 126 | } |
| 127 | paid { |
| 128 | dimension "version" |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | ``` |
| 133 | |
| 134 | ### Build specific flavor |
| 135 | ```bash |
| 136 | ./gradlew bundleFreeRelease |
| 137 | ./gradlew bundlePaidRelease |
| 138 | ``` |
| 139 | |
| 140 | ## CI/CD Build |
| 141 | |
| 142 | ### GitHub Actions Example |
| 143 | ```yaml |
| 144 | - name: Build Release AAB |
| 145 | run: | |
| 146 | echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > release.keystore |
| 147 | export KEYSTORE_FILE=release.keystore |
| 148 | export KEYSTORE_PASSWORD="${{ secrets.KEYSTORE_PASSWORD }}" |
| 149 | export KEY_ALIAS="${{ secrets.KEY_ALIAS }}" |
| 150 | export KEY_PASSWORD="${{ secrets.KEY_PASSWORD }}" |
| 151 | ./gradlew bundleRelease |
| 152 | |
| 153 | - name: Upload to Play Store |
| 154 | env: |
| 155 | GPLAY_SERVICE_ACCOUNT: ${{ secrets.PLAY_SERVICE_ACCOUNT }} |
| 156 | run: | |
| 157 | gplay release \ |
| 158 | --package com.example.app \ |
| 159 | --track internal \ |
| 160 | --bundle app/build/outputs/bundle/release/app-release.aab |
| 161 | ``` |
| 162 | |
| 163 | ## Common Build Tasks |
| 164 | |
| 165 | ### Clean build |
| 166 | ```bash |
| 167 | ./gradlew clean bundleRelease |
| 168 | ``` |
| 169 | |
| 170 | ### Build with specific SDK versions |
| 171 | ```bash |
| 172 | ./gradlew bundleRelease -PminSdkVersion=21 -PtargetSdkVersion=34 |
| 173 | ``` |
| 174 | |
| 175 | ### Build without tests |
| 176 | ```bash |
| 177 | ./gradlew bundleRelease -x test -x lint |
| 178 | ``` |
| 179 | |
| 180 | ### Build multiple variants |
| 181 | ```bash |
| 182 | ./gradlew bundle # Builds all variants |
| 183 | ``` |
| 184 | |
| 185 | ## Troubleshooting |
| 186 | |
| 187 | ### Build fails with signing errors |
| 188 | ```bash |
| 189 | # Verify keystore |
| 190 | keytool -list -v -keystore release.keystore |
| 191 | ``` |
| 192 | |
| 193 | ### Check AAB contents |
| 194 | ```bash |
| 195 | bundletool build-apks \ |
| 196 | --bundle=app-release.aab \ |
| 197 | --output=output.apks \ |
| 198 | --mode=universal |
| 199 | |
| 200 | unzip output.apks |
| 201 | ``` |
| 202 | |
| 203 | ### Verify version codes |
| 204 | ```bash |
| 205 | ./gradlew tasks --all | grep Version |
| 206 | ``` |
| 207 | |
| 208 | ## Best Practices |
| 209 | |
| 210 | 1. **Never commit keystores** - Store in secure location |
| 211 | 2. **Use environment variables** for credentials |
| 212 | 3. **Enable ProGuard/R8** for release builds |
| 213 | 4. **Upload mapping files** after each release |
| 214 | 5. **Increment version code** for every build |
| 215 | 6. **Test release builds** before uploading |
| 216 | 7. **Use App Bundles (AAB)** instead of APKs when possible |