Flutter/라이브러리

Flutter[Android] Google Play Game 연동하기

smileDeveloper 2023. 2. 10. 23:18
반응형
SMALL

Flutter로 Google Play game을 연동하기 위해서 고군분투했던 경험이 있습니다...

 

처음 Play Game과 연동하기 위해서 엄청 노력했지만 안 돼서 정말 시간만 날리고 정신이 가출했었죠...

 

시간이 지나고 문서를 자세히 읽어보니 방법을 찾을 수 있었습니다.

 

우선 Play Game과 연동하게 되면 몇가지 혜택이 있습니다!

 

  1. 업적 및 리더보드 기능 제공
  2. 데이터베이스 제공
  3. https://developers.google.com/games/services?hl=ko
 

Play 게임 서비스  |  Google Developers

모바일 게임과 웹 게임을 사용할 플레이어를 찾고 유지하며 서로를 연결합니다.

developers.google.com

게임과 관련하여 구글이 이렇게 지원을 해줍니다!!!

 

하여튼 Flutter로 연동하는 방법은 다음과 같습니다.

 


Game Service에 등록하기 위해서는 먼저 앱이 등록되어있어야 합니다.

 

등록이 되어있다면

[Google-Sign-In](https://pub.dev/packages/google_sign_in) 과

 

google_sign_in | Flutter Package

Flutter plugin for Google Sign-In, a secure authentication system for signing in with a Google account on Android and iOS.

pub.dev

[Game-Service](https://pub.dev/packages/games_services)를 추가해 줍니다.

 

games_services | Flutter Package

A new Flutter plugin to support game center and google play games services.

pub.dev

 

 

 

그다음 앱 ID를 찾아주어야 합니다. Google Play Console에서 찾을 수 있습니다.

 

이 ID를 가지고 적어주면 됩니다. 아래를 보면 @string/app_id로 되어있죠? 이는 다음과 같이 처리하면 됩니다.

    <meta-data 
    android:name="com.google.android.gms.games.APP_ID" 
    android:value="@string/app_id" /> 

    <meta-data 
    android:name="com.google.android.gms.version" 
    android:value="@integer/google_play_services_version" />
반응형
android/app/src/main/res/values/game-ids.xml

<?xml version="1.0" encoding="utf-8"?>
<!--Google Play game services IDs. Save this file as res/values/games-ids.xml in your project.-->
<resources>
  <!--app_id-->
  <string name="app_id" translatable="false">ID</string>
  <!--package_name-->
  <string name="package_name" translatable="false"> ex) com.smile.develop </string>
</resources>

이렇게 까지 하면 이제 코드만 짜면 됩니다!! 구글 로그인 후 구글 플레이에 로그인해 주면 됩니다!!

void loginGooglePlay() async {
    await authService.loginWithGoogle(); // Google Login logic
    GamesServices.signIn(shouldEnableSavedGame: true);
  }

 

이제 Play Games의 여러 기능들을 사용할 수 있게 되었습니다!! 모르는 부분을 댓글로 질문을 남겨주세요!!

 

첫 글이라 두서없이 적게 된 것 같은데 오늘 소개한 내용들을 차근차근 포스트 해보도록 하겠습니다! 봐주셔서 감사합니다

 

웃으며 개발할 날이 올 수 있게 항상 도와드리겠습니다!!

반응형
LIST