Skip to content

Commit

Permalink
feat: sign app
Browse files Browse the repository at this point in the history
  • Loading branch information
hpp2334 committed Jun 17, 2024
1 parent e242221 commit 0dfeaf5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ jobs:
pnpm run build:apk
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
ANDROID_SIGN_JKS: ${{ secrets.ANDROID_SIGN_JKS }}
ANDROID_SIGN_PASSWORD: ${{ secrets.ANDROID_SIGN_PASSWORD }}
- name: Upload binaries to artifacts
uses: actions/upload-artifact@v4
if: ${{ startsWith(github.ref, 'refs/tags/pre-v') }}
Expand Down
17 changes: 16 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
namespace "com.kutedev.ease_music_player"
compileSdkVersion flutter.compileSdkVersion
Expand Down Expand Up @@ -52,11 +58,20 @@ android {
versionName flutterVersionName
}

signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? rootProject.file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
signingConfig signingConfigs.release
}
}
}
Expand Down
20 changes: 17 additions & 3 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
const { execSync } = require('child_process')
const { mkdirSync, rmSync, cpSync } = require('fs')
const { mkdirSync, rmSync, cpSync, writeFileSync } = require('fs')
const { ROOT, CLIENT_ROOT } = require('./base')
const path = require('path')

execSync('flutter build apk --release --split-per-abi', { stdio: 'inherit', cwd: ROOT })

const androidDir = path.resolve(ROOT, './android')
const jksPath = path.resolve(androidDir, 'ease_music_player.jks')
const keyPropertiesPath = path.resolve(androidDir, 'key.properties')
const srcDir = path.resolve(ROOT, './build/app/outputs/flutter-apk')
const dstDir = path.resolve(ROOT, './artifacts/apk')

// Signing
writeFileSync(keyPropertiesPath, `storePassword=${process.env.ANDROID_SIGN_PASSWORD}
keyPassword=${process.env.ANDROID_SIGN_PASSWORD}
keyAlias=key0
storeFile=ease_music_player.jks`)
console.log(`${keyPropertiesPath} written`)

const jks = Buffer.from(process.env.ANDROID_SIGN_JKS, 'base64')
writeFileSync(jksPath, jks);
console.log(`${jksPath} written`)

execSync('flutter build apk --release --split-per-abi', { stdio: 'inherit', cwd: ROOT })

rmSync(dstDir, { recursive: true, force: true })
mkdirSync(srcDir, { recursive: true })
cpSync(srcDir, dstDir, { recursive: true })

0 comments on commit 0dfeaf5

Please sign in to comment.