2

我按照这篇文章https://forums.developer.huawei.com/forumPortal/en/topic/0204412554756330223做HMS账号套件插件。这是预期的结果。

在此处输入图像描述

点击华为登录后应该会弹出华为ID页面。

但它只保留在登录页面上。并弹出很多我看不懂的日志。

这是日志。

记录消息

import 'package:flutter/material.dart';
import 'package:huawei_account/huawei_account.dart';
import 'package:sign_in_hms/home.dart';

void main() {
   runApp(MyApp());
 }
  
 class MyApp extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     return MaterialApp(
       title: 'AccountKit',
       theme: ThemeData(
         primarySwatch: Colors.blue,
         visualDensity: VisualDensity.adaptivePlatformDensity,
       ),
       home: MyHomePage(title: 'Account Kit'),
     );
   }
 }
  
 class MyHomePage extends StatefulWidget {
   MyHomePage({Key key, this.title}) : super(key: key);
   final String title;
  
   @override
   _MyHomePageState createState() => _MyHomePageState();
 }
  
 class _MyHomePageState extends State<MyHomePage> {
   List<String> logs = [];
  
   @override
   Widget build(BuildContext context) {
     return Scaffold(
       appBar: AppBar(
         title: Text(widget.title),
       ),
       body: new Stack(
         fit: StackFit.expand,
         children: <Widget>[
           new Image(
             image: new AssetImage("assets/images/mobile.png"),
             fit: BoxFit.cover,
           ),
           new Form(
               child: new Container(
             padding: const EdgeInsets.all(60.0),
             child: new Column(
               mainAxisAlignment: MainAxisAlignment.center,
               children: [
                 new TextField(
                   decoration: new InputDecoration(
                       labelText: "Enter Email", focusColor: Colors.white),
                   keyboardType: TextInputType.emailAddress,
                 ),
                 new TextField(
                   decoration: new InputDecoration(labelText: "Enter Password"),
                   keyboardType: TextInputType.text,
                 ),
                 new Padding(
                   padding: const EdgeInsets.only(top: 20.0, bottom: 20.0),
                 ),
                 new MaterialButton(
                   minWidth: 100.0,
                   height: 40.0,
                   onPressed: () => {print('object')},
                   color: Colors.red,
                   textColor: Colors.white,
                   child: Text("LOGIN", style: TextStyle(fontSize: 20)),
                 ),
                 new Padding(
                   padding: const EdgeInsets.only(top: 10.0, bottom: 10.0),
                 ),
                 Text(
                   '( OR )',
                   textAlign: TextAlign.center,
                   overflow: TextOverflow.ellipsis,
                   style: TextStyle(
                       fontWeight: FontWeight.bold,
                       color: Colors.white,
                       fontSize: 15),
                 ),
                 new Padding(
                   padding: const EdgeInsets.only(top: 10.0, bottom: 10.0),
                 ),
                 new MaterialButton(
                   child: Text(
                     " HUAWEI SIGN IN",
                     style: TextStyle(fontSize: 20),
                   ),
                   minWidth: 100.0,
                   height: 40.0,
                   onPressed: _onSinIn,
                   color: Colors.red,
                   textColor: Colors.white,
                   padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                 )
               ],
             ),
           ))
         ],
       ),
     );
   }
  
   void _onSinIn() async {
     AccountAuthParamsHelper authParamHelper = new AccountAuthParamsHelper();
     authParamHelper
       ..setIdToken()
       ..setAuthorizationCode()
       ..setAccessToken()
       ..setProfile()
       ..setEmail()
       ..setScopeList([Scope.openId]);
     try {
       final AuthAccount accountInfo = await AccountAuthService.signIn(authParamHelper);
       setState(() {
         Navigator.push(
           context,
           MaterialPageRoute(
               builder: (context) => Home(accountInfo)),
         );
         _showToast(context);
         logs.add(accountInfo.displayName);
       });
     } on Exception catch (exception) {
       print(exception.toString());
       logs.add(exception.toString());
     }
   }
  
   void _showToast(BuildContext context) {
     final scaffold = Scaffold.of(context);
     scaffold.showSnackBar(
       SnackBar(
         content: const Text('Successfully Loged In'),
         action: SnackBarAction(
             label: 'UNDO', onPressed: scaffold.hideCurrentSnackBar),
       ),
     );
   }
 }
4

1 回答 1

1

确保证书指纹的设备配置和云端配置一致。客户端应用打包的证书与AppGallery Connect网站上为应用配置的SHA256证书指纹相同。

  1. 申请相关服务时,请确认证书指纹配置正确。打开应用的APK文件,解压META-INF目录,获取目录下的CERT.RSA文件,运行keytool -printcert -file META-INF/CERT.RSA命令记录签名证书信息.

  2. 登录AppGallery Connect,点击我的项目,选择需要的项目。在显示的页面,选择应用程序,进入项目设置 > 一般信息,检查SHA-256证书指纹中的值是否与步骤1中的值相同。

此外,HMS Core (APK) 会缓存签名文件。您需要在您设备的Apps页面找到HMS Core (APK)并清除缓存,重启您的应用程序,然后再次执行之前的操作。

于 2021-08-03T02:30:52.910 回答