我有一个应用程序在调试模式下运行良好,但在发布模式下无法正常工作。我使用了没有firebase的谷歌登录,它给予我错误**“platfromException(sign_in_failed,h1.b:10:,null,null)"**
这个发布的应用程序是由签名的apk生成的。
当我从android studio构建应用程序,然后发布。apk是不工作(它没有安装),但调试apk工作良好。以下是生成签名apk的过程和代码,任何步骤都错过了?
- Internet权限可在mainfeast文件中获得。
1.在生成签名APK时创建了新的.jks文件,并添加了以下代码:
在android文件夹**”www.example.com“**中创建了一个文件kep.properties,该文件中包含以下代码:
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
应用程序级别构建.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'
}
主要代码
<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控制台SHA-1
1条答案
按热度按时间xdnvmnnf1#
必须将
sha-1
密钥添加到firebase中之后生成APK并尝试登录**
sha-1
的生成方法有很多,请参考以下链接Generate SHA-1 for Flutter/React-Native/Android-Native app
然后将
sha-1
添加到firebase项目设置中请从firebase启用谷歌登录
生成APK后尝试登录
或者
基本上,错误是ApiException:10.要解决这个问题,你需要在google cloud console上用SHA1注册你的应用程序。进入console.cloud.google.com点击凭据〉创建凭据〉OAuth客户端ID选择你希望你的应用程序工作的平台。填写你的应用程序的包名。为了填写SHA1值,打开你的命令行和cd到android文件夹内你的主项目文件夹和键入命令./gradlew signingReport然后按回车.