2

I have one app which are running fine in debug mode but its not working properly in released mode. I have used google login without firebase and its give me error "platfromException(sign_in_failed,h1.b:10:,null,null)"

This released app is genrated by signed apk.

When i build app from android studio then released.apk is not working(its not installed) but debug apk is working well. Following are the process and code for genrating signed apk, any steps are missed?

  1. Internet permission is available in mainfeast file.
  2. Created new .jks file at the time of genrate signed apk and added following code:

Crated one file in android folder "kep.properties" following code in this file:

storePassword=password from previous step
keyPassword=password from previous step
keyAlias=key0
storeFile=location of the key store file, such as /Users/user name/key.jks

App leve build.gradle

    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 FileNotFoundException("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.1'
}

apply plugin: 'com.android.application'
apply plugin:  'com.google.gms.google-services'
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 33
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.mahuva_azadari"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        minSdkVersion 21
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    signingConfigs {
        debug {
            keyAlias 'androiddebugkey'
            keyPassword 'android'
            storeFile file('mykey.jks')
            storePassword 'android'
        }
    }

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

    buildTypes {
        debug {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation platform('com.google.firebase:firebase-bom:31.1.1')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics'
}

Mainfeast code

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mahuva_azadari">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />

    <queries>
        <intent>
            <action android:name="android.intent.action.SENDTO" />
            <data android:scheme="mailto" />
        </intent>
    </queries>

   <application
        android:label="Azadari Schedule"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize"
            android:usesCleartextTraffic="true">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

Google console SHA-1

enter image description here

Taki Rajani
  • 177
  • 12

1 Answers1

1

You have to add sha-1 key into firebase

After that generate apk and try login**

There are many way to generate sha-1, please refer to the below link

Generate SHA-1 for Flutter/React-Native/Android-Native app

After that add sha-1 into firebase project setting

enter image description here

Please enable google sign in from firebase

enter image description here

After generate apk and try to log in

Or

Basically, the error is ApiException: 10. To solve this, you will need register your app with a SHA1 on google cloud console. Go to console.cloud.google.com click credentials > create credentials >OAuth client ID choose the platform in which you want you application to work on. fill in the package name of your application. In order to fill in the SHA1 value, open your command line and cd to the android folder inside you main project folder and type the command ./gradlew signingReport then hit enter.

Rahul Variya
  • 1,257
  • 1
  • 6
  • 15
  • 1
    **Comments have been [moved to chat](https://chat.stackoverflow.com/rooms/251920/discussion-on-answer-by-rahul-variya-flutter-release-app-is-not-working-properly); please do not continue the discussion here.** Before posting a comment below this one, please review the [purposes of comments](/help/privileges/comment). Comments that do not request clarification or suggest improvements usually belong as an [answer](/help/how-to-answer), on [meta], or in [chat]. Comments continuing discussion may be removed. – sideshowbarker Feb 16 '23 at 08:59