Created
September 25, 2021 16:42
-
-
Save wendreof/3dfa1c35cd0dcb96c7637bff8435fe02 to your computer and use it in GitHub Desktop.
7-How-to-Safely-Build-Assigned-Flutter-App-with-GitHub-Actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def localProperties = new Properties() | |
def localPropertiesFile = rootProject.file('local.properties') | |
if (localPropertiesFile.exists()) { | |
localPropertiesFile.withReader('UTF-8') { reader -> | |
localProperties.load(reader) | |
} | |
} | |
def flutterRoot = localProperties.getProperty('flutter.sdk') | |
if (flutterRoot == null) { | |
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") | |
} | |
def flutterVersionCode = localProperties.getProperty('flutter.versionCode') | |
if (flutterVersionCode == null) { | |
flutterVersionCode = '4' | |
} | |
def flutterVersionName = localProperties.getProperty('flutter.versionName') | |
if (flutterVersionName == null) { | |
flutterVersionName = '4.1.0' | |
} | |
apply plugin: 'com.android.application' | |
apply plugin: 'kotlin-android' | |
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" | |
def keystoreProperties = new Properties() | |
def keystorePropertiesFile = rootProject.file('key.properties') | |
if (keystorePropertiesFile.exists()) { | |
keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) | |
} | |
android { | |
compileSdkVersion 30 | |
sourceSets { | |
main.java.srcDirs += 'src/main/kotlin' | |
} | |
lintOptions { | |
disable 'InvalidPackage' | |
} | |
defaultConfig { | |
applicationId "your-applicationid.com" | |
minSdkVersion 16 | |
targetSdkVersion 30 | |
versionCode flutterVersionCode.toInteger() | |
versionName flutterVersionName | |
} | |
signingConfigs { | |
release { | |
//From decoded key | |
storeFile = file('key.jks') | |
//From key.properties | |
keyAlias keystoreProperties['keyAlias'] | |
keyPassword keystoreProperties['keyPassword'] | |
storePassword keystoreProperties['storePassword'] | |
} | |
} | |
buildTypes { | |
release { | |
minifyEnabled true | |
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | |
signingConfig signingConfigs.release | |
} | |
} | |
} | |
flutter { | |
source '../..' | |
} | |
dependencies { | |
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD | |
on: | |
push: | |
branches: | |
- develop | |
- master | |
pull_request: | |
branches: | |
- develop | |
- master | |
env: | |
JAVA_VERSION: "11.x" | |
FLUTTER_VERSION: "2.2.3" | |
FLUTTER_CHANNEL: "stable" | |
PROPERTIES_PATH: "./android/key.properties" | |
jobs: | |
flutter_test: | |
name: Run Flutter assigned build appbundle | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-java@v1 | |
with: | |
java-version: ${{env.JAVA_VERSION}} | |
- uses: subosito/flutter-action@v1 | |
with: | |
channel: ${{env.FLUTTER_CHANNEL}} | |
flutter-version: ${{env.FLUTTER_VERSION}} | |
# Creating the key.properties file | |
- run: | | |
echo keyPassword=\${{ secrets.KEY_STORE }} > ${{env.PROPERTIES_PATH}} | |
echo storePassword=\${{ secrets.KEY_PASSWORD }} >> ${{env.PROPERTIES_PATH}} | |
echo keyAlias=\${{ secrets.KEY_ALIAS }} >> ${{env.PROPERTIES_PATH}} | |
# Decoding base64 key into a file | |
- run: echo "${{ secrets.KEYSTORE2 }}" | base64 --decode > android/app/key.jks | |
# Get dependencies and make assigned appbundle | |
- run: | | |
flutter pub get | |
flutter build appbundle | |
# Make appbundle downloadable | |
- name: Upload artefato | |
uses: actions/upload-artifact@v2 | |
with: | |
name: appbundle | |
path: build/app/outputs/bundle/release |
echo keyPassword=\${{ secrets.KEY_STORE }} > ${{env.PROPERTIES_PATH}}
why do you need to put \
after =
?
my build fails here saying:
line 2: syntax error near unexpected token
)'`
maybe because I have these characters KEY_STORE
The backslash b4 the = is for escaping the subsequent character.
Are u changing something? I've never had your problem.
yes, I ended up restoring the whole key.properties
from base64
, similar to how you did key.jks
so instead of 4 concatenating lines I have one,
Thank you for this snippet though, after some adjustment I get it building in CI
Good for u!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Take a look at How to Safely Build Assigned Flutter App with GitHub Actions post