Upgrading Gradle in Visual Studio Code

Upgrading Gradle in Visual Studio Code

I was having issues checking the signingReport for my application, I was trying to review all the SHA keys for my Android app so that I could implement Google Sign-In OAuth 2.0.

The following code was creating errors:
./gradlew singingReport

I decided it was probably best to upgrade my gradle version in my VS Code installation, as I didn't appear to be compatible with my Java installation.

Everything had worked fine up until this point, but it appears Google sign-in was the straw that broke the camels back.

If you have a reason to upgrade your gradle version there are a couple of things to do before proceeding:

  1. Check your Java versions in VS Code terminal: java --version
  2. Check compatible versions of Java and Gradle from gradles official site: https://docs.gradle.org/current/userguide/compatibility.html

Once you are happy that with what you have, and what you need - the next steps are required to update your app:

  1. Retrieve the URL for appropriate gradle version: https://services.gradle.org/distributions/
  2. Reference the appropriate gradle version in your gradle-wrapper.properties file of your project: e.g., distributionUrl=https://services.gradle.org/distributions/gradle-8.8-all.zip
  3. Rebuild wrapper in VS Code terminal: ./gradlew wrapper
  4. Confirm upgrade in VS Code terminal: ./gradlew --version

Once everything is up-to-date, you can re-run ./gradlew singingReport to determine all the SHA keys associated with your app - be aware, you don't just need release track keys, you are going to need debug ones too.

The output of this command will provide details similar to the following:

Task :app:signingReport Variant: debug Config: debug Store: C:\Android\.android\debug.keystore Alias: AndroidDebugKey MD5: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX SHA1: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX... SHA-256: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX... Valid until: Tuesday, July 15, 2053

Variant: release
Config: release
Store: C:\Users\iainm\OneDrive\Documents\upload-keystore.jks
Alias: upload
MD5: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
SHA1: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX...
SHA-256: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX...
Valid until: Thursday, August 10, 2051

Variant: profile
Config: debug
Store: C:\Android.android\debug.keystore
Alias: AndroidDebugKey
MD5: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
SHA1: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX...
SHA-256: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX...
Valid until: Tuesday, July 15, 2053

NOTE: While there will be several tasks and varients, there will probably only be a few in SHA1 and SHA-256 keys in the end, copy these - along with any app signing keys from the Google Play Console (relative to your):

svnG9Ni7Eb

Once this has been achieved, follow your regular trusted sources for how to implement the sign-in function within your flutter app. I myself followed a few different guides, and leveraged ChatGPT for assistance in my specific application.

Here is a snippet of my sign-in function:

Future signInWithGoogle() async {
try {
final GoogleSignIn googleSignIn = GoogleSignIn(
scopes: [
'email',
'profile',
],
);

// Trigger the authentication flow
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();

// If the user cancels the sign-in flow, googleUser will be null
if (googleUser == null) {
// User canceled the sign-in
return;
}

// Obtain the auth details from the request
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;

// Create a new credential
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);

// Sign in to Firebase with the Google [UserCredential]
UserCredential userCredential =
await FirebaseAuth.instance.signInWithCredential(credential);

// Check if user details exist in Firestore
DocumentSnapshot userDoc = await FirebaseFirestore.instance
.collection("users")
.doc(userCredential.user!.email)
.get();

if (!userDoc.exists) {
String username = googleUser.displayName!;
String email = userCredential.user!.email!;
String userId = userCredential.user!.uid;

await FirebaseFirestore.instance.collection("users").doc(email).set({
'username': username,
'email': email,
'userId': userId,
});
} else {
// Fetch user data and set global variables
var userData = userDoc.data() as Map;
firebaseUsername = userData['username'];
firebaseEmail = userData['email'];
firebaseUserId = userData['userId'];
}
} catch (e) {
displayMessage("Error signing in with Google: $e");
print('Error signing in with Google: $e');
}
}