6

my google sign in my flutter app works perfectly in both iOS and android simulators, and in iOS in release mode when downloading from app store. The problem is the release appbundle from the play store doesn't work. when I click the google sign in button, it shows my accounts, I select the account, it goes through and just flickers and goes back to the main screen.

I have run ./gradlew signingReport and have gotten both debug and release SHA1 Keys and placed them in my firebase console.

my app level build.grade looks like this

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 = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '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 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.rnainc.edganizer_school_app"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        
        multiDexEnabled true
        //ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
    }

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

    buildTypes {
        release {
            signingConfig signingConfigs.release
            aaptOptions { cruncherEnabled = false }
            
            // need either some or all of the following 4 lines to make sure the app actually launches when downloaded from the play store, otherwise it crashes upon installation
            minifyEnabled false
            useProguard false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.android.support:multidex:1.0.3'
}

apply plugin: 'com.google.gms.google-services'

 configurations.all {
    resolutionStrategy {
        force 'com.google.android.gms:play-services-location:15.0.0'
     }
 }

this is my android level build.grade, as you can see, I tried multiple versions, 3.6.4, 4.0.1, 4.1.0, all the same problem. I have tried other things like updating to the latest versions of all firebase plugins, flutter clean. But still same issue. I also checked the GCP OAuth 2.0 Client IDs in my GCP console and it shows that two certificates where made for me (auto generated when I added the SHA1 keys to firebase).

I'm really not sure what else I can tinker with to get this working, not sure where the problem is to be honest.

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        //classpath 'com.android.tools.build:gradle:4.0.1'
        //classpath 'com.android.tools.build:gradle:4.1.0'
        classpath 'com.android.tools.build:gradle:3.6.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.4'
        
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
RNA
  • 63
  • 1
  • 5

3 Answers3

14

You need to copy the new SHA-1 generated in play console and add it in firebase / GCP

play console - app signing

Bharath
  • 1,036
  • 10
  • 13
  • OMG, that easy eh! you are amazing! that worked. Just so that I learn, can you please share with me where this is written anywhere in the documentation? I thought I read everything I could get my hands on, but didn't know I had to do that. thank – RNA Nov 20 '20 at 18:49
  • cool! I don't know where it written in documentation. I faced this issue once and after lots of searches i got solutions through stackoverflow only! https://stackoverflow.com/questions/39318370/google-sign-in-not-working-after-publishing-in-play-store – Bharath Nov 21 '20 at 16:12
0

To implement without firebase, try visa - https://github.com/e-oj/visa

Here's an example with Facebook auth (It also supports google):

import 'package:visa/auth-data.dart';
import 'package:visa/fb.dart';

class AuthPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      /// Simply Provide all the necessary credentials
      body: FaceBookAuth().visa.authenticate(
          clientID: '139732240983759',
          redirectUri: 'https://www.e-oj.com/oauth',
          scope: 'public_profile,email',
          state: 'fbAuth',
          onDone: done
      )
    );
  }
}

and the "done" callback:

done(AuthData authData){
  print(authData);

  /// You can pass the [AuthData] object to a 
  /// post-authentication screen. It contaions 
  /// all the user and OAuth data collected during
  /// the authentication process. In this example,
  /// our post-authentication screen is "complete-profile".
  Navigator.pushReplacementNamed(
      context, '/complete-profile', arguments: authData
  );
}
e-oj
  • 209
  • 2
  • 5
0

Link is called App Integrity now

enter image description here

kiwicmc
  • 26
  • 3