微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

@react-native-community/google-signin 独立应用程序不起作用

如何解决@react-native-community/google-signin 独立应用程序不起作用

我使用 @react-native-community/google-signin 在调试模式下运行良好,但不适用于 android 发布模式(独立应用)。

我已经尝试过文档中所说的,但什么也没做。 https://reactnative.dev/docs/signed-apk-android https://github.com/react-native-google-signin/google-signin

谁能帮帮我...

我从我的密钥库版本中获取了凭据 OAuth 2.0 客户端 ID 宽度 SHA-1。

这是我的代码

const signIn = async () => {
    try {
      GoogleSignin.configure({
        scopes: ['email','profile'],webClientId: webClient
        offlineAccess: true,forceCodeForRefreshToken: true,accountName: ''
     });

      await GoogleSignin.hasPlayServices();
      const isSignedIn = await GoogleSignin.isSignedIn();
      if(isSignedIn){
        await GoogleSignin.revokeAccess();
        await GoogleSignin.signOut();
      }
     
     
      const respLogGoogle = await GoogleSignin.signIn();
     
      const responseLogBack = 
        await dispatch(authActions.loginSocials(
          respLogGoogle.user.email,respLogGoogle.user.name,respLogGoogle.user.photo
        ))
      ;

     
    } catch (error) {
      if (error.code === statusCodes.SIGN_IN_CANCELLED) {
        // user cancelled the login flow
        console.log('Cancel');
      } else if (error.code === statusCodes.IN_PROGRESS) {
        console.log('Signin in progress');
        // operation (f.e. sign in) is in progress already
      } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
        console.log('PLAY_SERVICES_NOT_AVAILABLE');
        // play services not available or outdated
      } else {
        // some other error happened
         console.log("GOOGLE:",error);
      }
    }
  };

Gradle 属性

MYAPP_UPLOAD_STORE_FILE='KeyStore.keystore'
MYAPP_UPLOAD_KEY_ALIAS='keyAlias'
MYAPP_UPLOAD_STORE_PASSWORD='*********'
MYAPP_UPLOAD_KEY_PASSWORD='='*********''

构建gradle

signingConfigs {
        release {
            if (project.hasProperty('KeyStore.keystore')) {
                storeFile file('KeyStore.keystore')
                storePassword '*******'
                keyAlias 'keyAlias'
                keyPassword '*********'
            }
        }
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    /* signingConfigs {
       
    } */
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production,you need to generate your own    keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"),"proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }

谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。