![](/img/trans.png)
[英]Flutter Android firebase notification doesn't work in release mode
[英]Firebase SignIn error only in android release mode
I have phone sign in with Firebase in my flutter app and it all works perfectly in debug mode both iOS and Android but when in release mode it throws an error only on Android device (physical). iOS 在發布模式下仍然可以完美運行。
[+9626 ms] E/flutter (21573): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'String'
[ ] E/flutter (21573): #0 MethodChannelFirebaseAuth.verifyPhoneNumber.<anonymous closure> (package:firebase_auth_platform_interface/src/method_channel/method_channel_firebase_auth.dart:655)
[ ] E/flutter (21573): #1 _RootZone.runUnaryGuarded (dart:async/zone.dart:1593)
[ ] E/flutter (21573): #2 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339)
[ ] E/flutter (21573): #3 _DelayedData.perform (dart:async/stream_impl.dart:515)
[ ] E/flutter (21573): #4 _PendingEvents.handleNext (dart:async/stream_impl.dart:620)
[ ] E/flutter (21573): #5 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591)
[ ] E/flutter (21573): #6 _microtaskLoop (dart:async/schedule_microtask.dart:40)
[ ] E/flutter (21573): #7 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49)
[ ] E/flutter (21573):
這是我的 function
Future verifyPhoneNumber() async {
try {
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: _telNumberController.text,
verificationCompleted: (PhoneAuthCredential credential) async {
print('COMPLETED');
},
verificationFailed: (FirebaseAuthException e) {
print('FAILED');
},
codeSent: (
String verificationId,
int? resendToken,
) {
print('CODE SENT');
},
codeAutoRetrievalTimeout: (String verificationId) {},
);
} catch (e) {
print(e);
}
}
它正確傳遞了電話號碼,但甚至沒有達到任何print
- 既不是verificationCompleted
完成,也不是verificationFailed
失敗
任何想法為什么我會得到這種行為?
UPD:我發現我的版本 SHA1 和 SHA256 與調試版本不同,所以我將它們添加到 Firebase,下載新的 google-services.json 文件,運行 Z5ACEBC4CB70DDBB074B0AC76AAB17AE,但問題仍然存在。 我相信這與應用程序無法在發布模式下執行的重新驗證碼有關。
UPD2我還添加了來自 Google Play 商店的 SHA 密鑰。 所以現在我已經調試、發布和 Google Play SHA1 和 SHA256。 但是仍然有相同的錯誤,並且在調試中仍然可以完美運行,但在發布中卻不行
UPD3發現當我從 build.gradle 更改
signingConfig signingConfigs.debug
至
signingConfig signingConfigs.release
所以我做的發布signinConfig有問題
使用此命令創建上傳密鑰庫 ~keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload~
在 android 文件夾中創建 key.properties
storePassword=***
keyPassword=***
keyAlias=upload
storeFile=/Users/amarchuk/upload-keystore.jks~
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
有什么問題?
最后! 經過一周的痛苦,我發現它的來源在您的 Google 中可以控制台https://console.cloud.google.com/ - 憑據 - API 密鑰 - 你有你的 ZE84E30B9390CDB64DB6DB2C9AB878 密鑰。 我將它限制為 Android 應用程序,因為它應該是,但你必須添加你的 SHA1 密鑰,我只有我的調試 SHA1 密鑰,但沒有發布密鑰。 添加發布密鑰解決了問題。 希望對其他用戶有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.