I've been trying to build my flutter (android) project on Codemagic, but I keep getting MalformedJsonException. I am assuming the (firebase) google-services.json file encoded to base64 string is where the issue is arising from.
* What went wrong:
Execution failed for task ':app:processReleaseGoogleServices'.
com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 2261
Please, I need a way to get around this.
I was facing this issue because the script provided in the Codemagic documentation was only meant to read pure json file but in my case; the the json file was encrypted to Base64
string, so it was necessary to decrypt the binary into a valid json file before parsing it.
Here's the original script from the doc
#!/usr/bin/env sh
set -e # exit on first failed command
echo $ANDROID_FIREBASE_SECRET > $FCI_BUILD_DIR/android/app/google-services.json
echo $IOS_FIREBASE_SECRET > $FCI_BUILD_DIR/ios/Runner/GoogleService-Info.plist
Here's the working script
#!/usr/bin/env sh
set -e # exit on first failed command
echo $ANDROID_FIREBASE_SECRET | base64 --decode > $FCI_BUILD_DIR/android/app/google-services.json
echo $IOS_FIREBASE_SECRET | base64 --decode > $FCI_BUILD_DIR/ios/Runner/GoogleService-Info.plist
Reference: https://blog.codemagic.io/how-to-load-firebase-config-in-codemagic-with-environment-variables/