Mulai Mengintegrasikan Login dengan Google ke dalam Aplikasi Android Anda
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Sebelum mulai mengintegrasikan Login dengan Google di aplikasi Anda sendiri, Anda harus
mengonfigurasi project Konsol API Google dan menyiapkan project Android Studio.
Langkah-langkah pada halaman ini menerangkan hal itu. Langkah berikutnya
kemudian menjelaskan cara mengintegrasikan Login dengan Google ke dalam aplikasi Anda.
Prasyarat
Google Sign-In untuk Android memiliki persyaratan sebagai berikut:
Perangkat yang kompatibel dan didukung Android yang menjalankan Android 6.0 atau yang lebih baru dan
menyertakan Google Play Store atau emulator dengan AVD yang menjalankan platform Google
API berdasarkan Android 4.2.2 atau yang lebih baru dan memiliki layanan Google Play
versi 15.0.0 atau yang lebih baru.
Android SDK versi terbaru, termasuk komponen SDK Tools. SDK
tersedia dari Android SDK Manager di Android Studio.
Project yang dikonfigurasi untuk dikompilasi dengan Android 6.0 (Marshmallow) atau yang lebih baru.
Panduan ini ditulis untuk pengguna Android Studio, yang merupakan lingkungan pengembangan
yang direkomendasikan.
Menambahkan Google Play Services
Dalam file build.gradle level atas project Anda, pastikan repositori Maven Google
disertakan:
allprojects {
repositories {
google()
// If you're using a version of Gradle lower than 4.1, you must instead use:
// maven {
// url 'https://maven.google.com'
// }
}
}
Kemudian, di file build.gradle tingkat aplikasi, deklarasikan
layanan Google Play sebagai dependensi:
Buka project Anda di API console, atau buat project jika Anda belum memilikinya.
Di halaman layar izin OAuth, pastikan semua informasi
lengkap dan akurat.
Di halaman Kredensial, buat client ID jenis Android untuk aplikasi Anda
jika Anda belum memilikinya. Anda harus menentukan nama paket
aplikasi dan sidik jari sertifikat SHA-1. Lihat Mengautentikasi Klien
Anda untuk mengetahui informasi
selengkapnya.
Mendapatkan client ID OAuth 2.0 server backend Anda
Di halaman Kredensial, buat client ID jenis Aplikasi web. Catat
string client ID, yang harus Anda teruskan ke
metode requestIdToken atau requestServerAuthCode saat membuat
objek GoogleSignInOptions.
Langkah berikutnya
Setelah mengonfigurasi project Konsol API Google dan menyiapkan
project Android Studio, Anda dapat mengintegrasikan Login dengan Google ke dalam
aplikasi.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-26 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-26 UTC."],[],[],null,["# Start Integrating Google Sign-In into Your Android App\n\n| **Warning:**\n|\n| **The Google Sign-In for Android API is outdated and no longer supported.**\n| To ensure the continued security and usability of your app, [migrate your Sign in with\n| Google implementation to Credential Manager](/identity/sign-in/credential-manager-siwg) today. Credential Manager\n| supports passkey, password, and federated identity authentication (such as\n| Sign-in with Google), stronger security, and a more consistent user\n| experience.\n|\n| **For Wear developers:** Credential Manager will be supported in Wear OS\n| 5.1 and later on selected watches. Developers actively supporting Wear OS 3, 4\n| and 5.0 devices with Sign in with Google should continue using Google Sign-in\n| for Android for your Wear applications. Sign in with Google support will be\n| available on Credential Manager APIs for these versions of WearOS at a later\n| date.\n\nBefore you can start integrating Google Sign-In in your own app, you must\nconfigure a Google API Console project and set up your Android Studio project.\nThe steps on this page do just that. The [next steps](#next_steps)\nthen describe how to integrate Google Sign-In into your app.\n\nPrerequisites\n-------------\n\nGoogle Sign-In for Android has the following requirements:\n\n- A compatible Android-powered device that runs Android 6.0 or newer and includes the Google Play Store or an emulator with an AVD that runs the Google APIs platform based on Android 4.2.2 or newer and has Google Play services version 15.0.0 or newer.\n- The latest version of the Android SDK, including the SDK Tools component. The SDK is available from the Android SDK Manager in Android Studio.\n- A project configured to compile against Android 6.0 (Marshmallow) or newer.\n\nThis guide is written for users of Android Studio, which is the recommended\ndevelopment environment.\n\nAdd Google Play services\n------------------------\n\nIn your project's top-level `build.gradle` file, ensure that Google's Maven\nrepository is included: \n\n allprojects {\n repositories {\n google()\n\n // If you're using a version of Gradle lower than 4.1, you must instead use:\n // maven {\n // url 'https://maven.google.com'\n // }\n }\n }\n\nThen, in your app-level `build.gradle` file, declare\n[Google Play services](https://developers.google.com/android) as a dependency: \n\n apply plugin: 'com.android.application'\n ...\n\n dependencies {\n implementation 'com.google.android.gms:play-services-auth:21.3.0'\n }\n\nConfigure a Google API Console project\n--------------------------------------\n\n1. Open your project in the [API console](https://console.cloud.google.com/), or create a project if you don't already have one.\n2. On the OAuth consent screen page, make sure all of the information is complete and accurate.\n3. On the Credentials page, create an **Android** type client ID for your app if you don't already have one. You will need to specify your app's package name and SHA-1 certificate fingerprint. See [Authenticating Your\n Client](https://developers.google.com/android/guides/client-auth) for more information.\n\nGet your backend server's OAuth 2.0 client ID\n---------------------------------------------\n\nIf your app [authenticates with a backend server](https://developers.google.com/identity/sign-in/android/backend-auth) or\n[accesses Google APIs from your backend server](/identity/legacy/gsi/offline-access), you need to get\nthe OAuth 2.0 client ID that represents your backend server.\n\nTo create a client ID for your server:\n\n1. Open your project in the [API console](https://console.cloud.google.com/).\n\n2. On the Credentials page, create a **Web application** type client ID. Take\n note of the client ID string, which you will need to pass to the\n `requestIdToken` or `requestServerAuthCode` method when you create the\n `GoogleSignInOptions` object.\n\nNext steps\n----------\n\nNow that you have configured a Google API Console project and set up your\nAndroid Studio project, you can [integrate Google Sign-In](/identity/legacy/gsi/legacy-sign-in) into\nyour app."]]