const { withAppBuildGradle } = require("@expo/config-plugins"); // Injects a proper release signingConfig into the generated build.gradle. // Reads credentials from gradle.properties (populated by build-apk.sh at build time). // This plugin runs during `expo prebuild` so android/ doesn't need to be committed. module.exports = function withAndroidReleaseSigning(config) { return withAppBuildGradle(config, (mod) => { let contents = mod.modResults.contents; if (contents.includes("MYAPP_UPLOAD_STORE_FILE")) { return mod; // already patched } const releaseBlock = ` release { if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) { storeFile file(MYAPP_UPLOAD_STORE_FILE) storePassword MYAPP_UPLOAD_STORE_PASSWORD keyAlias MYAPP_UPLOAD_KEY_ALIAS keyPassword MYAPP_UPLOAD_KEY_PASSWORD } }`; // Insert release signingConfig after the closing brace of the debug block contents = contents.replace( /(signingConfigs\s*\{[\s\S]*?debug\s*\{[\s\S]*?\})/, `$1\n${releaseBlock}` ); // Switch the release buildType from debug signing to release signing contents = contents.replace( /(buildTypes[\s\S]*?release\s*\{[\s\S]*?)signingConfig\s+signingConfigs\.debug/, "$1signingConfig signingConfigs.release" ); mod.modResults.contents = contents; return mod; }); };