// Signs release builds with the musicshare upload key when it's configured in // ~/.gradle/gradle.properties (MUSICSHARE_UPLOAD_STORE_FILE, _STORE_PASSWORD, // _KEY_ALIAS, _KEY_PASSWORD). Without it the release APK is left unsigned, which // is what F-Droid expects (it signs with its own key). The key never lives in the repo. const { withAppBuildGradle } = require('expo/config-plugins'); const MARKER = '// musicshare release signing'; const SIGNING_CONFIG = ` ${MARKER} release { if (project.hasProperty('MUSICSHARE_UPLOAD_STORE_FILE')) { storeFile file(MUSICSHARE_UPLOAD_STORE_FILE) storePassword MUSICSHARE_UPLOAD_STORE_PASSWORD keyAlias MUSICSHARE_UPLOAD_KEY_ALIAS keyPassword MUSICSHARE_UPLOAD_KEY_PASSWORD } }`; module.exports = function withReleaseSigning(config) { return withAppBuildGradle(config, (cfg) => { let gradle = cfg.modResults.contents; if (gradle.includes(MARKER)) return cfg; // Add a release signing config next to the debug one. gradle = gradle.replace(/signingConfigs\s*\{/, (m) => `${m}${SIGNING_CONFIG}`); // In the release build type, use it when the key is configured. const release = gradle.indexOf('release {', gradle.indexOf('buildTypes {')); if (release === -1) throw new Error('withReleaseSigning: no release build type in app/build.gradle'); const line = gradle.indexOf('signingConfig signingConfigs.debug', release); if (line === -1) throw new Error('withReleaseSigning: release build type has no signingConfig line'); gradle = gradle.slice(0, line) + "signingConfig project.hasProperty('MUSICSHARE_UPLOAD_STORE_FILE') ? signingConfigs.release : null" + gradle.slice(line + 'signingConfig signingConfigs.debug'.length); cfg.modResults.contents = gradle; return cfg; }); };