안드로이드에서 Google 로그인
설치 단계와 이 플러그인에 대한 전체 마크다운 가이드가 포함된 설정 프롬프트를 복사하세요.
소개
소개란In this guide, you will learn how to setup Google Login with Capgo Social Login for Android. I assume that you have already read the 일반 설정 가이드를 이미 읽었다고 가정합니다..
Android에서 Google 로그인을 사용하는 방법
Android에서 Google 로그인을 설정하는 방법을 배울 것입니다.이 부분에서 Android에서 Google 로그인을 설정하는 방법을 배울 것입니다.
-
Android 클라이언트 ID 만들기
-
검색 바 클릭
-
검색
credentials그리고APIs and Services스크린샷의 2번에 해당하는
-
자격 증명 옵션에 클릭
create credentials
-
APIs and Services에서 자격 증명 선택
OAuth client ID
-
Select the
Android응용 프로그램 유형
-
Open Android Studio
-
Android Studio 프로젝트 탐색기에서 가장 아래쪽에
Gradle Scripts
-
Find
build.gradle모듈app
-
build.gradle (Module: app) file in Gradle Scripts section
android.defaultConfig.applicationIdCopy thepackage nameIn Google 콘솔
-
Now, 터미널을 열어보세요. 당신이 앱 폴더에 있는지 확인하세요.
android터미널에서 gradlew signInReport 명령어를 실행하세요../gradlew signInReport
- SHA1 인증서 지문이 출력된 터미널
SHA1.
- Android 클라이언트 생성 폼에 패키지 이름과 SHA1을 입력한 상태
applicationIdAndroid용 웹 클라이언트를 생성하세요. (Android용은 필수입니다.)Package NameAndroid용 웹 클라이언트를 생성하세요. (Android용은 필수입니다.)create
-
-
Android용 웹 클라이언트를 생성하세요. (Android용은 필수입니다.)
-
Go to the
Create credentialsGoogle Console 페이지로 이동하세요. -
Set application type to
Web
-
Click
Create
-
Copy the client ID, you’ll use this as the
webClientIdcode에 사용할 클라이언트 ID를 복사하세요.
-
-
Modify your
MainActivity-
Android Studio에서 앱을 열어 주세요. 앱을 실행할 수 있습니다.
cap open android -
Find
MainActivity.java-
Open the
app폴더
-
Find
java
-
Find your
MainActivity.java그리고 클릭하여
-
-
Modify
MainActivity.java. code를 다음에 추가해주세요import ee.forgr.capacitor.social.login.GoogleProvider;import ee.forgr.capacitor.social.login.SocialLoginPlugin;import ee.forgr.capacitor.social.login.ModifiedMainActivityForSocialLoginPlugin;import com.getcapacitor.PluginHandle;import com.getcapacitor.Plugin;import android.content.Intent;import android.util.Log;import com.getcapacitor.BridgeActivity;// ModifiedMainActivityForSocialLoginPlugin is VERY VERY important !!!!!!public class MainActivity extends BridgeActivity implements ModifiedMainActivityForSocialLoginPlugin {@Overridepublic void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);if (requestCode >= GoogleProvider.REQUEST_AUTHORIZE_GOOGLE_MIN && requestCode < GoogleProvider.REQUEST_AUTHORIZE_GOOGLE_MAX) {PluginHandle pluginHandle = getBridge().getPlugin("SocialLogin");if (pluginHandle == null) {Log.i("Google Activity Result", "SocialLogin login handle is null");return;}Plugin plugin = pluginHandle.getInstance();if (!(plugin instanceof SocialLoginPlugin)) {Log.i("Google Activity Result", "SocialLogin plugin instance is not SocialLoginPlugin");return;}((SocialLoginPlugin) plugin).handleGoogleLoginIntent(requestCode, data);}}// This function will never be called, leave it empty@Overridepublic void IHaveModifiedTheMainActivityForTheUseWithSocialLoginPlugin() {}} -
클립보드에 복사해주세요
-
-
Use Google Login in your application
-
First, import
SocialLoginimport { SocialLogin } from '@capgo/capacitor-social-login'; -
Call initialize. This should be called only once.
// onMounted is Vue specific// webClientId is the client ID you got in the web client creation step not the android client ID.onMounted(() => {SocialLogin.initialize({google: {webClientId: '673324426943-avl4v9ubdas7a0u7igf7in03pdj1dkmg.apps.googleusercontent.com',}})}) -
Call
SocialLogin.login. Create a button and run the following code on click.const res = await SocialLogin.login({provider: 'google',options: {}})// handle the responseconsole.log(JSON.stringify(res))
-
-
테스트를 위해 에뮬레이터를 구성하세요.
-
그리고 플러스 버튼을 클릭하세요.
Device manager플러스 버튼이 강조된 Android Studio의 디바이스 매니저로 들어가세요.
-
가상 디바이스 구성에서 가상 디바이스 생성 버튼을 클릭하세요.
-
디바이스 아이콘
Play Store플레이 스토어 지원을 하는 디바이스 목록
As you can see, the
pixel 8supports thePlay Storeservices -
Click
next
-
Make sure that the OS image is of type
Google Play. IT MUST be of typeGoogle Play
-
Click next
-
Confirm your device. You can name your emulator as you prefer
-
__CAPGO_KEEP_0__에
Device Manager시뮬레이터를 부팅하세요.
-
시뮬레이터가 부팅되면 설정으로 이동하세요.
-
__CAPGO_KEEP_0__ 설정 화면에 Google Play 옵션이 있습니다.
Google Play
- Google Play 업데이트 화면에 업데이트 버튼이 있습니다.
Update__CAPGO_KEEP_2__을 테스트하세요.
-
-
__CAPGO_KEEP_0__
If you did everything correctly, you should see the Google login flow working properly:
문제 해결
문제 해결이러한 문제가 발생하면, Google Cloud Console의 앱 설정과 일치하는지 확인하세요. Android Google Sign-In 오류는 일반적으로 패키지 이름, SHA-1, 또는 클라이언트 ID의 불일치로 인해 발생합니다.
인증 관리자, SHA-1, 및 Firebase
인증 관리자, SHA-1, 및 FirebaseAndroid에서 이 플러그인은 Google Credential Manager (androidx.credentials 와 Sign in with Google), legacy 버전이 아닌 GoogleSignInClient API. Logcat 오류, 예를 들어 GetCredentialCustomException: [28444] Developer console is not set up correctly 는 해당 스택에서 발생합니다.
Logcat을 필터링하세요. GoogleProvider 또는 CapgoSocialLogin 로그인 실패 후에도. webClientId 플러그인은 패키지 이름, 서명 SHA-1, 그리고 가려진
이를 Google Cloud Console에서 비교할 수 있도록.
Google Cloud 설정이 필요합니다.제목 ‘Google Cloud 설정이 필요합니다.’
| Google Cloud 프로젝트에 두 가지 종류의 OAuth 2.0 클라이언트 ID가 필요합니다. | 클라이언트 유형 | 사용 목적 |
|---|---|---|
| 위치 | 웹 애플리케이션 | webClientId 서버 / ID 토큰 대상 SocialLogin.initialize() |
| Android, 하나의 서명 키당 | Google Cloud Console에서만 사용하세요. 이 ID를 | A common mistake는 Android client ID를 사용하는 것입니다. webClientId |
Credential Manager는 Web client ID를 필요로 합니다. Android client ID는 단지 올바른 패키지 이름과 SHA-1만 등록하면 됩니다. webClientIdCreate one Android OAuth client for each certificate that signs builds you test:
Debug:
- for the debug variant.
./gradlew signingReportRelease: - Play App Signing: Play Console > App integrity > App signing key certificate에서 찾습니다. Play Store 빌드에 대해 필요합니다.
- The
in applicationId __CAPGO_KEEP_0__ android/app/build.gradle Android OAuth 클라이언트 패키지 이름이 정확히 일치해야 합니다. 포함된任何 접미사. .debug OAuth 동의 화면이 테스트 모드일 경우, 사용자 > 테스트 사용자에서 테스트하는 모든 Google 계정을 추가하세요. 앱을 프로덕션으로 출시하는 것은 필요하지 않습니다.
scopes. email 디지털 자산 링크 ( profile )는 Credential Manager를 통해 Google과 함께 로그인하는 경우 필요하지 않습니다.assetlinks.jsonGoogle Cloud의 변경 사항은 몇 시간 동안 전파될 수 있습니다.
오류 28444: 개발자 콘솔이 올바르게 설정되지 않았습니다.
제목이 '오류 28444: 개발자 콘솔이 올바르게 설정되지 않았습니다.'인 섹션
이것은 거의 항상 Google이 설치된 APK 서명 인증서, 패키지 이름, 및을 combination으로 거부했을 때 발생합니다. 다음 체크리스트를 통해 작업하세요: webClientId확인
- Confirm
webClientId__CAPGO_KEEP_0__은 웹 애플리케이션 클라이언트 ID로 끝나며.apps.googleusercontent.com. - 앱을 실행하고 실패를 재현한 후 Logcat을 읽어보세요.
GoogleProvider,signingSha1=Android 및package=. - In Google Cloud Console > Credentials에서, Android OAuth 클라이언트를 열고 정확한 패키지 이름 및 SHA-1을 확인하세요.
- 릴리즈 빌드 테스트 중인 경우, 디버그 키 스토어의 SHA-1만 등록하지 마세요.
- 앱이 Play Store를 통해 배포되는 경우, 또한 Play App Signing SHA-1을 등록하세요.
- 웹 및 Android 클라이언트가 동일한 Google Cloud 프로젝트에 존재해야 합니다.
- consent 화면이 테스트 중인 경우, Google 계정이 테스트 사용자인지 확인하세요.
- 콘솔 변경 후 기다리며 다시 시도하세요.
USER_CANCELLED 디버그 빌드의 계정 선택 후에도 SHA-1 또는 클라이언트 ID 불일치가 발생할 수 있습니다. 콘솔 설정을 위에서부터 수정하세요.
__CAPGO_KEEP_0__ SHA-1을 설치한 빌드에서 추출하세요
__CAPGO_KEEP_0__ SHA-1 추출debug 또는 local 빌드:
cd android && ./gradlew signingReport서명된 릴리스 APK:
keytool -printcert -jarfile android/app/release/app-release.apk해당 패키지 이름이 일치하는 Android OAuth 클라이언트에 SHA-1을 추가하고 동일한 서명된 APK를 다시 설치한 후 다시 테스트하세요:
adb install android/app/release/app-release.apk로그인 결과를 읽는 중입니다
로그인 결과를 읽는 방법토큰이 중첩되어 있습니다. result:
const login = await SocialLogin.login({ provider: 'google' });const idToken = login.result?.idToken;Firebase Auth의 경우, 해당 키를 사용하여 idToken Web 클라이언트 ID를 사용하여 webClientId 에서 initialize.
개발 SHA-1 인증서를 얻을 수 없다면, 커스텀 키스토어를 사용해 보세요. 이ssue 댓글 프로젝트에 키스토어를 추가하는 방법을 설명합니다.
Google Login on Android에서 계속
Google Login on Android에서 계속하는 방법이미 사용 중입니다. Google Android 로그인 인증 및 계정 흐름을 계획하고 연결하려면 @capgo/capacitor-social-login을 사용하여 @capgo/capacitor-social-login의 원시 기능을 사용하여 @capgo/capacitor-social-login @capgo/capacitor-social-login의 구현 세부 정보를 사용하여 @capgo/capacitor-passkey @capgo/capacitor-passkey의 구현 세부 정보를 사용하여 @capgo/capacitor-native-biometric @capgo/capacitor-native-biometric의 구현 세부 정보를 사용하여 두 단계 인증 두 단계 인증의 구현 세부 정보를 사용하여