发布到 Play 商店后 Flutter Firebase 电话验证不起作用

时间:2021-04-03 15:28:19

标签: firebase flutter firebase-authentication

我正在尝试通过 Firebase 使用电话验证。我的代码在调试和发布模式下都能完美运行,但是当我将我的应用上传到 Play 商店时,它却无法运行。

这是它给出的错误:

<块引用>

'此请求缺少有效的应用程序标识符,这意味着 SafetyNet 检查和 reCAPTCHA 检查均未成功。请重试,或查看 logcat 以了解更多详细信息。'

我已将所有密钥添加到 firebase,启用 Android Device Verification API,但仍然出现相同的错误。

这是我用于电话验证的代码:

Future<void> onVerifyCode(BuildContext context, UserModel userModel) async {
    print('i am verifycode');
    void verificationDone(PhoneAuthCredential credential) async {
      await _firebaseAuth.signInWithCredential(credential).then((value) {
        if (value.user != null) {
          Navigator.push(
            context,
            MaterialPageRoute(
              builder: (_) => AccountDetails(
                userModel: userModel,
              ),
            ),
          );
        } else {
          Fluttertoast.showToast(msg: "Error validating OTP, try again");
        }
      }).catchError((error) {
        print('verify done error' + error);
        Fluttertoast.showToast(msg: '$error');
      });
    }

    void verificationFail(FirebaseAuthException e) {
      print('i am fail' + e.message);
      Fluttertoast.showToast(msg: '${e.message}');
    }

    void codeSent(String verificationId, int resendToken) async {
      print('i am codeSent');
      _verificationId = verificationId;
      // dialogBox(verificationId, resendToken);
      // Create a PhoneAuthCredential with the code
    }

    final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
        (String verificationId) {
      _verificationId = verificationId;
    };

    await _firebaseAuth
        .verifyPhoneNumber(
            phoneNumber: "+91${userModel.phone}",
            timeout: const Duration(seconds: 60),
            verificationCompleted: verificationDone,
            verificationFailed: verificationFail,
            codeSent: codeSent,
            codeAutoRetrievalTimeout: codeAutoRetrievalTimeout)
        .catchError((error) {
      print('verifyPhoneNo' + error);
      Fluttertoast.showToast(msg: '$error');
    });
  }

这是我的 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 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: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    compileSdkVersion 30

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.shdigital.vasts"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            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.release
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "androidx.browser:browser:1.3.0"
    implementation 'com.android.support:multidex:1.0.3'
}

这是我的 build.gradle(项目级别):

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        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
}

这是我的 pub.yaml 文件:

name: demoappname

description: A new Flutter application.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.3+4

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter


  
  cupertino_icons: ^1.0.0

  provider: ^4.3.2+4

  video_player: ^2.0.2

  chewie: ^1.0.0

  flutter_windowmanager: ^0.0.2

  dio: ^3.0.10

  path_provider: ^1.6.27

  path: ^1.7.0

  #firebase
  firebase_core: "^0.7.0"

  firebase_auth: "^0.20.1"

  connectivity: ^2.0.2

  pin_code_text_field: ^1.7.1

  share: ^0.6.5+4

  http: ^0.12.2

  fluttertoast: ^7.1.6

  shared_preferences: ^0.5.12+4

  razorpay_flutter: 1.1.0

  image_picker: ^0.6.7+21



dev_dependencies:
  flutter_test:
    sdk: flutter


flutter:

 
  uses-material-design: true

  assets:
    - assets/images/

0 个答案:

没有答案