--- title: Android Buy SDK description: Set up the Android Buy SDK for product browsing and cart management. source_url: html: 'https://shopify.dev/docs/storefronts/mobile/buy-sdk-android' md: 'https://shopify.dev/docs/storefronts/mobile/buy-sdk-android.md' --- # Android Buy SDK The Android Buy SDK provides a typed Kotlin interface to the Storefront API. Use it to fetch products, manage carts, and produce a `checkoutUrl` you can hand to Checkout Kit. *** ## What the Buy SDK does The Buy SDK wraps the Storefront API in typed Kotlin methods. Each capability has a recommended alternative: | Task | Buy SDK | Alternative | | - | - | - | | Fetch products and collections | Yes (typed Kotlin interface) | Direct [Storefront API](https://shopify.dev/docs/api/storefront) calls | | Create and manage carts | Yes (typed Kotlin interface) | Direct Storefront API calls | | Present checkout | No (use Checkout Kit) | [Checkout Kit](https://shopify.dev/docs/storefronts/mobile/checkout-kit) | *** ## Requirements * Android SDK 23 or higher (Android 6.0 Marshmallow). * JDK 11 or higher (JDK 17 if using Checkout Kit). * Android Studio Arctic Fox or higher. * A [Storefront API access token](https://shopify.dev/docs/storefronts/headless/building-with-the-storefront-api/getting-started). *** ## Step 1: Generate an access token To generate an access token, you can [generate one in the Shopify admin](https://shopify.dev/docs/apps/build/authentication-authorization/access-tokens/generate-app-access-tokens-admin). Alternatively, you can create a custom app and use [authorization code grant](https://shopify.dev/docs/apps/build/authentication-authorization/access-tokens/authorization-code-grant). *** ## Step 2: Make your products and collections available After you've generated an access token, you need to make products and collections available to your custom app to access them from your app. After the products and collections are available, you can retrieve them using their respective IDs. **Tip:** If you have many products or collections, then you can use [bulk actions](https://help.shopify.com/manual/shopify-admin/productivity-tools/bulk-actions) to make them available in one step. ### Make a product available 1. From your Shopify admin, go to **Products**. 2. From the **Products** page, click the product you want to make available. 3. Next to **SALES CHANNELS AND APPS** click **Manage**. 4. In the **Sales channels and apps** dialog box, select the box next to the name of your custom app. ### Make a collection available 1. From your Shopify admin, go to **Products** and click **Collections**. 2. From the **Collections** page, click the collection you want to make available. 3. Next to **SALES CHANNELS AND APPS** click **Manage**. 4. In the **Sales channels and apps** dialog box, select the box next to the name of your custom app. *** ## Step 3: Install the SDK Add the Buy SDK to your `build.gradle`: ## build.gradle ```kotlin dependencies { implementation("com.shopify.mobilebuysdk:buy3:12.0.0") } ``` *** ## Step 4: Initialize the client Create a client instance with your shop domain and Storefront API access token: ## Kotlin ```kotlin import com.shopify.buy3.GraphClient import com.shopify.buy3.Storefront val client = GraphClient.build( context = applicationContext, shopDomain = "{shop}.myshopify.com", accessToken = "{your_storefront_access_token}" ) ``` *** ## Step 5: Fetch products Query the Storefront API to get products. Save the variant ID for creating a cart: ## Kotlin ```kotlin import com.shopify.buy3.Storefront import com.shopify.buy3.GraphCallResult fun fetchProducts() { val query = Storefront.query { root -> root.products({ args -> args.first(10) }) { connection -> connection.edges { edge -> edge.node { product -> product.id() product.title() product.description() product.featuredImage { image -> image.url() } product.variants({ args -> args.first(1) }) { variants -> variants.edges { variantEdge -> variantEdge.node { variant -> variant.id() variant.title() variant.price { price -> price.amount() price.currencyCode() } } } } } } } } client.queryGraph(query).enqueue { result -> when (result) { is GraphCallResult.Success -> { val products = result.response.data?.products?.edges products?.forEach { edge -> Log.d("Products", "Product: ${edge.node.title}") } } is GraphCallResult.Failure -> { Log.e("Products", "Error: ${result.error}") } } } } ``` *** ## Step 6: Create a cart Use the variant ID to create a cart and get a `checkoutUrl`: ## Kotlin ```kotlin import com.shopify.buy3.Storefront import com.shopify.graphql.support.ID fun createCart(variantId: ID) { val input = Storefront.CartInput.builder() .lines(listOf( Storefront.CartLineInput.builder() .merchandiseId(variantId) .quantity(1) .build() )) .build() val mutation = Storefront.mutation { root -> root.cartCreate(input) { cartCreate -> cartCreate.cart { cart -> cart.id() cart.checkoutUrl() // Use this URL with Checkout Kit } cartCreate.userErrors { errors -> errors.field() errors.message() } } } client.mutateGraph(mutation).enqueue { result -> when (result) { is GraphCallResult.Success -> { val checkoutUrl = result.response.data?.cartCreate?.cart?.checkoutUrl // Pass this URL to Checkout Kit to present checkout Log.d("Cart", "Checkout URL: $checkoutUrl") } is GraphCallResult.Failure -> { Log.e("Cart", "Error: ${result.error}") } } } } ``` *** ## Step 7: Present checkout with Checkout Kit With the `checkoutUrl` from the cart, use [Checkout Kit](https://shopify.dev/docs/storefronts/mobile/checkout-kit) to present checkout: ## Kotlin ```kotlin import com.shopify.checkoutsheetkit.ShopifyCheckoutSheetKit fun presentCheckout(checkoutUrl: String) { ShopifyCheckoutSheetKit.present(checkoutUrl, this, checkoutEventProcessor) } ``` See [Embed Checkout Kit](https://shopify.dev/docs/storefronts/mobile/checkout-kit) for complete checkout setup. *** ## Configure Android App Links (optional) Set up [Android App Links](https://developer.android.com/training/app-links/) to integrate your app with Android web browsers. When a buyer taps a link to your website, then your app opens if they have it installed. 1. From your Shopify admin, go to [**Apps**](https://www.shopify.com/admin/apps). 1) Click **Develop apps**. 2) Click the name of your app. 3) Click **API Integrations**. 4) In the **Storefront API integration** section, click **Configure**. 5) Expand the **Android Buy SDK configuration** section. 6) Enter your **Android application ID** and your **SHA-256 certificate fingerprints**. *** ## Next steps [Build a mobile storefront\ \ ](https://shopify.dev/docs/storefronts/mobile/build-mobile-storefront?extension=kotlin) [Build a complete shopping experience with products, cart, and checkout using the Storefront API and Checkout Kit.](https://shopify.dev/docs/storefronts/mobile/build-mobile-storefront?extension=kotlin) [Android Buy SDK on GitHub\ \ ](https://github.com/Shopify/mobile-buy-sdk-android) [SDK source code and sample apps.](https://github.com/Shopify/mobile-buy-sdk-android) *** ## Where to get help Shopify support covers issues with the Android Buy SDK itself, but not general mobile app development. Here's how to get help: ### [Hire a Shopify Partner](https://www.shopify.com/partners/directory) Find a Shopify Partner for hire in our ecosystem of talented development agencies. ### [.dev Community](https://community.shopify.dev) Ask questions and share knowledge with other Shopify developers. ### [Open a GitHub issue](https://github.com/Shopify/mobile-buy-sdk-android/issues) Report bugs or request features for the Android Buy SDK. ***