gRPC는 모든 환경에서 실행할 수 있는 최신 오픈소스 고성능 RPC 프레임워크입니다. 부하 분산, 추적, 상태 점검, 인증에 대한 플러그형 지원을 통해 데이터 센터 내부 및 데이터 센터 간에 서비스를 효율적으로 연결할 수 있습니다. 또한 분산 컴퓨팅의 라스트 마일에서 기기, 모바일 애플리케이션, 브라우저를 백엔드 서비스에 연결할 수 있습니다. gRPC 공식 웹사이트에서 문서를 찾고 오픈소스 커뮤니티의 지원을 받을 수 있습니다. 이 가이드에서는 gRPC를 사용하여 Android 앱을 빌드하는 솔루션을 설명합니다.
gRPC.io는 gRPC 프로젝트의 공식 웹사이트입니다. gRPC의 작동 방식에 관한 자세한 내용은 gRPC란 무엇인가요?
및 gRPC 개념을 참조하세요.
Android 앱에서 gRPC를 사용하는 방법을 알아보려면 gRPC Android 자바 빠른 시작의 Hello World 예를 참조하세요.
또한 GitHub에서 몇 가지 다른 gRPC Android 예도 찾아볼 수 있습니다.
기능
프로시저 호출로 간편성 제고
RPC이기 때문에 프로그래밍 모델은 프로시저 호출입니다. 기술의 네트워킹 측면은 애플리케이션 코드에서 추상화되어 마치 일반적인 프로세스 내 함수 호출처럼 보입니다. 클라이언트-서버 상호작용은 HTTP 리소스 메서드(예: GET, PUT, POST, DELETE)의 의미 체계에 의해 제한되지 않습니다. REST API에 비해 HTTP 프로토콜 메타데이터를 처리할 필요가 없으므로 더 자연스럽게 구현할 수 있습니다.
HTTP/2를 통한 효율적인 네트워크 전송
휴대기기에서 백엔드 서버로 데이터를 전송하는 작업은 리소스를 매우 많이 사용하는 프로세스일 수 있습니다. 표준 HTTP/1.1 프로토콜을 사용하면 휴대기기에서 클라우드 서비스에 자주 연결할 경우 배터리가 소모되고 지연 시간이 증가하며 다른 앱의 연결을 차단할 수 있습니다. 기본적으로 gRPC는 HTTP/2를 기반으로 실행되며 양방향 스트리밍, 흐름 제어, 헤더 압축, 단일 TCP/IP 연결을 통해 요청을 다중화하는 기능을 제공합니다. 결과적으로 gRPC는 리소스 사용량을 줄여 클라우드에서 실행 중인 앱과 서비스 간의 응답 시간을 단축하고 네트워크 사용량을 줄이며 휴대기기에서 실행되는 클라이언트의 배터리 수명을 늘릴 수 있습니다.
내장 스트리밍 데이터 교환 지원
gRPC는 처음부터 HTTP/2의 전이중 양방향 스트리밍 지원을 염두에 두고 설계되었습니다. 스트리밍을 사용하면 많은 양의 정보를 업로드하거나 다운로드해야 하는 작업과 같이 요청 및 응답이 임의의 크기를 가질 수 있습니다. 스트리밍을 사용하면 클라이언트와 서버가 동시에 메시지를 읽고 쓸 수 있으며 리소스 ID를 추적하지 않고도 서로 구독할 수 있습니다. 이렇게 하면 앱을 더 유연하게 구현할 수 있습니다.
프로토콜 버퍼와의 원활한 통합
gRPC는 Android에 최적화된 codegen 플러그인 (Protobuf Java Lite)과 함께 프로토콜 버퍼(Protobuf)를 직렬화/역직렬화 방법으로 사용합니다.
Protobuf는 텍스트 기반 형식 (예: JSON)에 비해 마샬링 속도와 코드 크기 측면에서 더 효율적인 데이터 교환을 제공하므로 모바일 환경에서 사용하기에 더 적합합니다. 또한 Protobuf의 간결한 메시지/서비스 정의 구문을 사용하면 앱의 데이터 모델과 애플리케이션 프로토콜을 훨씬 더 쉽게 정의할 수 있습니다.
프로토콜 버퍼를 사용하여 RPC 서비스를 정의하고 gRPC 클라이언트 인터페이스를 생성합니다.
클라이언트와 서버 간 RPC 호출의 매체 역할을 하는 채널을 빌드합니다.
클라이언트 측에서 RPC 호출을 시작하기 위한 진입점으로 클라이언트 스텁을 만듭니다.
로컬 프러시저 호출을 수행할 때처럼 원격 서버에 RPC를 호출합니다.
시연을 위해 제공된 예에서는 바이트가 일반 텍스트로 전송됩니다. 그러나 앱은 프로덕션 단계에서 항상 네트워크 데이터를 암호화해야 합니다. gRPC는 SSL/TLS 암호화 지원뿐만 아니라 인증을 위한 OAuth 토큰 교환(Google 서비스와 OAuth2)을 제공합니다. 자세한 내용은 Android의 TLS 및 OAuth2 사용을 참고하세요.
전송
gRPC는 Android 클라이언트를 위한 두 가지 전송 구현 옵션인 OkHttp와 Cronet을 제공합니다.
Cronet은 모바일용 라이브러리로 패키징된 Chromium의 네트워킹 스택입니다. 최신 QUIC 프로토콜로 강력한 네트워킹 지원을 제공하므로 신뢰할 수 없는 네트워크 환경에서 특히 효과적입니다. Cronet에 관한 자세한 내용은 Cronet을 사용하여 네트워크 작업 실행을 참고하세요.
앱에서 Cronet을 gRPC 전송으로 사용하려면 CronetChannelBuilder로 채널을 구성합니다.
사용 예는 gRPC-자바 Cronet 전송에 제공됩니다.
일반적으로 최신 SDK 버전을 타겟팅하는 앱은 더 강력한 네트워크 스택을 제공하는 Cronet을 사용하는 것이 좋습니다. Cronet 사용의 단점은 APK 크기가 증가한다는 것입니다. 바이너리 Cronet 종속 항목을 추가하면 앱 크기가 1MB 이상 늘어나지만 OkHttp의 경우 약 100KB가 되기 때문입니다. GMSCore v.10부터 Google Play 서비스에서 최신 Cronet 사본을 로드할 수 있습니다. 최신 GMSCore가 설치되지 않은 기기는 여전히 OkHttp 사용을 선호할 수 있지만 APK 크기는 더 이상 문제가 되지 않을 수 있습니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Build client-server applications with gRPC\n\ngRPC is a modern, open-source, high-performance RPC framework that can run in any\nenvironment. It can efficiently connect services in and across data centers with\npluggable support for load balancing, tracing, health-checking, and\nauthentication. It is also applicable in the last mile of distributed computing\nto connect devices, mobile applications, and browsers to backend services. You\ncan find documentation on gRPC's official website and get support from\nopen source communities. This guide points you to solutions for\nbuilding Android apps using gRPC.\n\n[grpc.io](https://grpc.io) is the official website for the\ngRPC project. To learn more about how gRPC works, see [What is gRPC?](https://grpc.io/docs/guides/)\nand [gRPC Concepts](https://grpc.io/docs/guides/concepts/).\nTo learn how to use gRPC in an Android app, see the Hello World example in\n[gRPC Android Java Quickstart](https://grpc.io/docs/quickstart/android/).\nYou can also find several other gRPC Android examples [on GitHub](https://github.com/grpc/grpc-java/tree/v1.24.0/examples/android).\n\nFeatures\n--------\n\n**Procedure call makes it simple**\n: Because it's RPC, the programming model is procedure calls: the networking\n aspect of the technology is abstracted away from application code, making it\n look almost as if it was a normal in-process function call. Your client-server\n interaction will not be constrained by the semantics of HTTP resource methods\n (such as GET, PUT, POST, and DELETE). Compared to REST APIs, your implementation\n looks more natural, without the need for handling HTTP protocol metadata.\n\n**Efficient network transmission with HTTP/2**\n: Transmitting data from mobile devices to a backend server can be a very\n resource-intensive process. Using the standard HTTP/1.1 protocol, frequent\n connections from a mobile device to a cloud service can drain the battery,\n increase latency, and block other apps from connecting. By default, gRPC runs on\n top of HTTP/2, which introduces bi-directional streaming, flow control, header\n compression, and the ability to multiplex requests over a single TCP/IP\n connection. The result is that gRPC can reduce resource usage, resulting in\n lower response times between your app and services running in the cloud,\n reduced network usage, and longer battery life for client running on mobile\n devices.\n\nBuilt-in streaming data exchange support\n: gRPC was designed with HTTP/2's support for full-duplex bidirectional\n streaming in mind from the outset. Streaming allows a request and response to\n have an arbitrarily large size, such as operations that require uploading or\n downloading a large amount of information. With streaming, client and server\n can read and write messages simultaneously and subscribe to each other without\n tracking resource IDs. This makes your app implementation more flexible.\n\n**Seamless integration with Protocol Buffer**\n: gRPC uses Protocol Buffers (Protobuf) as its\n serialization/deserialization method with optimized-for-Android codegen plugin\n ([Protobuf Java Lite](https://github.com/protocolbuffers/protobuf/blob/v3.9.0/java/lite.md)).\n Compared to text-based format (such as JSON), Protobuf offers more efficient data\n exchanging in terms of marshaling speed and code size, which makes it more\n suitable to be used in mobile environments. Also Protobuf's concise\n message/service definition syntax makes it much easier to define data model\n and application protocols for your app.\n\nUsage overview\n--------------\n\nFollowing the [gRPC Basics - Android Java](https://grpc.io/docs/tutorials/basic/android/)\ntutorial, using gRPC for Android apps involves four steps:\n\n- Define RPC services with protocol buffers and generate the gRPC client interfaces.\n- Build a Channel that serves as the medium for RPC calls between client and server.\n- Create a client Stub as the entry point for initiating RPC calls from client side.\n- Make RPC calls to remote server as you would when performing local procedure calls.\n\nFor demonstration purposes, bytes are transmitted in plain text in the provided\nexample. However, your app should always encrypt network data in production.\ngRPC provides SSL/TLS encryption support as well as OAuth token exchanging\n(OAuth2 with Google services) for authentication. For more details, see\n[TLS on Android](https://github.com/grpc/grpc-java/blob/v1.24.0/SECURITY.md#tls-on-android)\nand [Using OAuth2](https://github.com/grpc/grpc-java/blob/v1.24.0/SECURITY.md#using-oauth2).\n| **Note:** If you are using Gradle as the build tool for your app, the Protobuf Gradle plugin is a handy tool for automating the process of generating and building gRPC Java code into your app. For more information, see [Protobuf Plugin for Gradle](https://github.com/google/protobuf-gradle-plugin#protobuf-plugin-for-gradle-).\n\nTransport\n---------\n\ngRPC provides two choices of Transport implementations for Android clients:\nOkHttp and Cronet.\n| **Note:** Creating channels with transport-specific channel builders (such as [`OkHttpChannelBuilder`](https://github.com/grpc/grpc-java/blob/v1.24.0/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java#L57) or [`CronetChannelBuilder`](https://github.com/grpc/grpc-java/blob/v1.24.0/cronet/src/main/java/io/grpc/cronet/CronetChannelBuilder.java#L49)) is for more advanced usage. If you build the channel with [`ManagedChannelBuilder`](https://github.com/grpc/grpc-java/blob/v1.24.0/api/src/main/java/io/grpc/ManagedChannelBuilder.java#L31), the class loader will load the plain [`OkHttpChannelBuilder`](https://github.com/grpc/grpc-java/blob/v1.24.0/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java#L57) as the default implementation at runtime. Starting from gRPC's 1.24 release, we recommend using [`AndroidChannelBuilder`](https://github.com/grpc/grpc-java/blob/v1.24.0/android/src/main/java/io/grpc/android/AndroidChannelBuilder.java#L54), which is similar, but with some Android-specific optimizations.\n\n**Choose a transport (advanced)**\n\n-\n\n OkHttp\n : OkHttp is a light-weight networking stack designed for use on mobile. It is\n gRPC's default transport for running in Android environment. To use OkHttp as\n gRPC transport for your app, construct the channel with [`AndroidChannelBuilder`](https://github.com/grpc/grpc-java/blob/v1.24.0/android/src/main/java/io/grpc/android/AndroidChannelBuilder.java#L54),\n which wraps [`OkHttpChannelBuilder`](https://github.com/grpc/grpc-java/blob/v1.24.0/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java#L57)\n and will register a network monitor with the Android OS to quickly respond to\n network changes. An example usage can be found in [gRPC-Java AndroidChannelBuilder](https://github.com/grpc/grpc-java/blob/v1.24.0/documentation/android-channel-builder.md#example-usage).\n-\n\n Cronet (experimental)\n : Cronet is Chromium's Networking stack packaged as a library for mobile. It\n offers robust networking support with state-of-the-art QUIC protocol, which can\n be especially effective in unreliable network environments. To learn more\n details about Cronet, see [Perform network operations using Cronet](/guide/topics/connectivity/cronet).\n To use Cronet as gRPC transport for your app, construct the channel with\n [`CronetChannelBuilder`](https://github.com/grpc/grpc-java/blob/v1.24.0/cronet/src/main/java/io/grpc/cronet/CronetChannelBuilder.java#L49).\n An example usage is provided in [gRPC-Java Cronet Transport](https://github.com/grpc/grpc-java/tree/v1.24.0/cronet#grpc-cronet-transport).\n\n| **Note:** Cronet's bidirectional streaming feature is still experimental. Therefore, [`CronetChannelBuilder`](https://github.com/grpc/grpc-java/blob/v1.24.0/cronet/src/main/java/io/grpc/cronet/CronetChannelBuilder.java#L49) is marked as an experimental API.\n\nGenerally speaking, we recommend apps targeting recent SDK versions use Cronet\nas it offers a more-powerful network stack. The downside of using Cronet is the\nAPK size increase, as adding the binary Cronet dependency will add \\\u003e1MB to the\napp size, versus \\~100KB for OkHttp. Starting with GMSCore v.10, an\nup-to-date copy of Cronet can be loaded from Google Play Services. The APK size\nmay no longer be a concern, although devices without the latest GMSCore\ninstalled may still prefer using OkHttp.\n| **Note:** When loading Cronet from Google Play services, call [`CronetProviderInstaller.installProvider(Context)`](https://developers.google.com/android/reference/com/google/android/gms/net/CronetProviderInstaller) before creating [`CronetEngine/ExperimentalCronetEngine`](https://developer.android.com/guide/topics/connectivity/cronet/reference/org/chromium/net/CronetEngine) objects to prevent unexpected exceptions from being thrown due to errors like devices requiring an updated version of Google Play services."]]