[英]Flutter provider not working in release apk, but working fine in debug mode
[英]flutter: I have using firebase auth with provider. Its working fine in debug but app crashes in release
我正在尝试创建发布 apk,但是当发布 apk 并运行我的发布设备时,它崩溃了,但在调试时它可以正常工作,找到您可以。 我已经检查并发布了我的 firebase 身份验证代码。 谁能帮帮我
main.dart 代码
class MyApp extends StatelessWidget {
bool isFirstTime;
ThemeData appTheme;
MyApp(bool isFirstTime,ThemeData appTheme) {
this.isFirstTime = isFirstTime;
this.appTheme=appTheme;
}
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
StreamProvider<UserModel>.value(
value: Auth().onAuthStateChanged,
),
Provider<Database>(create: (_)=>RealtimeDatabase(),),
Provider<AuthBase>(create: (_)=>Auth(),),
ChangeNotifierProvider.value(value: UserAddressesViewModel()),
ChangeNotifierProvider.value(value: GoogleMapsFindAddressModel()),
ChangeNotifierProvider.value(value: SelectAddressViewModel()),
ChangeNotifierProvider.value(value: AppThemeViewModel(appTheme))
],
child: CMaterialAppWidget(isFirstTime: isFirstTime,),
);
}
}
身份验证类
UserModel _userFromFirebase(User user,UserType userType) {
if (user == null) {
return null;
}
return UserModel(
uid: user.uid,
name: user.displayName,
userImage: user.photoURL,
userType: userType,
phoneNumber: user.phoneNumber
);
}
@override
Stream<UserModel> get onAuthStateChanged {
return _firebaseAuth.authStateChanges().map((event){
if(event.isAnonymous!=null){
return _userFromFirebase(event, event.isAnonymous?UserType.guest:UserType.standard);
}else{
return _userFromFirebase(event, UserType.guest);
}
});
构建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 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 30
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.hellowcity"
minSdkVersion 18
targetSdkVersion 30
versionCode 4
versionName '1.3'
multiDexEnabled true
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.firebase:firebase-analytics:17.3.0'
// implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta03'
}
// ADD THIS AT THE BOTTOM
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'
您是否已将 sha 密钥添加到 Firebase 控制台?
注意:debug 和 release 的 sha key 是不同的
您可以使用 ./android/gradlew signatureReport 找到您的密钥
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.