Tag Archives: Gemini in Android Studio

Gemini in Android Studio for businesses: Develop with confidence, powered by AI

Posted by Sandhya Mohan – Product Manager

To empower Android developers at work, we’re excited to announce a new offering of Gemini in Android Studio for businesses. This offering is specifically designed to meet the added privacy, security, and management needs of small and large organizations. We’ve heard that some people at businesses have additional needs that require more sensitive data protection, and this offering delivers the same Gemini in Android Studio that you've grown accustomed to, now with the additional privacy enhancements that your organization might require.

Developers and admins can unlock these features and benefits by subscribing to Gemini Code Assist Standard or Enterprise editions. A Google Cloud administrator can purchase a subscription and assign licenses to developers in their organization directly from the Google Cloud console.

Your code stays secure

Our data governance policy helps ensure customer code, customers' inputs, as well as the recommendations generated will not be used to train any shared models. Customers control and own their data and IP. It also comes with security features like Private Google Access, VPC Service Controls, and Enterprise Access Controls with granular IAM permissions to help enterprises adopt AI assistance at scale without compromising on security and privacy. Using a Gemini Code Assist Standard or Enterprise license enables multiple industry certifications such as:

    • SOC 1/2/3, ISO/IEC 27001 (Information Security Management)
    • 27017 (Cloud Security)
    • 27018 (Protection of PII)
    • 27701 (Privacy Information Management)

More details are at Certifications and security for Gemini.

IP indemnification

Organizations will benefit from generative AI IP indemnification, safeguarding their organizations against third parties claiming copyright infringement related to the AI-generated code. This added layer of protection is the same indemnification policy we provide to Google Cloud customers using our generative AI APIs, and allows developers to leverage the power of AI with greater confidence and reduced risk.

Code customization

Developers with a Code Assist Enterprise license can get tailored assistance customized to their organization’s codebases by connecting to their GitHub, GitLab or BitBucket repositories (including on-premise installations), giving Gemini in Android Studio awareness of the classes and methods their team is most likely to use. This allows Gemini to tailor code completion suggestions, code generations, and chat responses to their business's best practices, and save developers time they would otherwise have to spend integrating with their company's preferred frameworks.

Designed for Android development

As always, we've designed Gemini in Android Studio with the unique needs of Android developers in mind, offering tailored assistance at every stage of the software development lifecycle. From the initial phases of writing, refactoring, and documenting your code, Gemini acts as an intelligent coding companion to boost productivity. With features like:

    • Build & Sync error support: Get targeted insights to help solve build and sync errors
screenshot of build and sync error support by Gemini in Android Studio

    • Gemini-powered App Quality Insights: Analyze crashes reported by Google Play Console and Firebase Crashlytics
screenshot of app quality insights by Gemini in Android Studio

    • Get help with Logcat crashes: Simply click on “Ask Gemini” to get a contextual response on how to resolve the crash.
screenshot of getting contextual responses on how to resolve a crash from by Gemini in Android Studio

In Android Studio, Gemini is designed specifically for the Android ecosystem, making it an invaluable tool throughout the entire journey of creating and publishing an Android app.

Check out Gemini in Android Studio for business

This offering for businesses marks a significant step forward in empowering Android development teams with the power of AI. With this subscription-based offering, no code is stored, and crucially, your code is never used for model training. By providing generative AI indemnification and robust enterprise management tools, we're enabling organizations to innovate faster and build high-quality Android applications with confidence.

Ready to get started? Here’s what you need

To get started, you'll need a Gemini Code Assist Enterprise license and Android Studio Narwhal or Android Studio for Platform found on the canary release channel. Purchase your Gemini Code Assist license or contact a Google Cloud sales team today for a personalized consultation on how you can unlock the power of AI for your organization.

Note: Gemini for businesses is also available for Android Studio Platform users.

We appreciate any feedback on things you like or features you would like to see. If you find a bug, please report the issue and also check out known issues. Remember to also follow us on X, LinkedIn, Blog, or YouTube for more Android development updates!

3 fun experiments to try for your next Android app, using Google AI Studio

Posted by Paris Hsu – Product Manager, Android Studio

We shared an exciting live demo from the Developer Keynote at Google I/O 2024 where Gemini transformed a wireframe sketch of an app's UI into Jetpack Compose code, directly within Android Studio. While we're still refining this feature to make sure you get a great experience inside of Android Studio, it's built on top of foundational Gemini capabilities which you can experiment with today in Google AI Studio.

Specifically, we'll delve into:

    • Turning designs into UI code: Convert a simple image of your app's UI into working code.
    • Smart UI fixes with Gemini: Receive suggestions on how to improve or fix your UI.
    • Integrating Gemini prompts in your app: Simplify complex tasks and streamline user experiences with tailored prompts.

Note: Google AI Studio offers various general-purpose Gemini models, whereas Android Studio uses a custom version of Gemini which has been specifically optimized for developer tasks. While this means that these general-purpose models may not offer the same depth of Android knowledge as Gemini in Android Studio, they provide a fun and engaging playground to experiment and gain insight into the potential of AI in Android development.

Experiment 1: Turning designs into UI code

First, to turn designs into Compose UI code: Open the chat prompt section of Google AI Studio, upload an image of your app's UI screen (see example below) and enter the following prompt:

"Act as an Android app developer. For the image provided, use Jetpack Compose to build the screen so that the Compose Preview is as close to this image as possible. Also make sure to include imports and use Material3."

Then, click "run" to execute your query and see the generated code. You can copy the generated output directly into a new file in Android Studio.

Image uploaded: Designer mockup of an application's detail screen
Image uploaded: Designer mockup of an application's detail screen

Moving image showing a custom chat prompt being created from the imagev provided in Google AI Studio
Google AI Studio custom chat prompt: Image → Compose

Moving image showing running the generated code in Android Studio
Running the generated code (with minor fixes) in Android Studio

With this experiment, Gemini was able to infer details from the image and generate corresponding code elements. For example, the original image of the plant detail screen featured a "Care Instructions" section with an expandable icon — Gemini's generated code included an expandable card specifically for plant care instructions, showcasing its contextual understanding and code generation capabilities.


Experiment 2: Smart UI fixes with Gemini in AI Studio

Inspired by "Circle to Search", another fun experiment you can try is to "circle" problem areas on a screenshot, along with relevant Compose code context, and ask Gemini to suggest appropriate code fixes.

You can explore with this concept in Google AI Studio:

    1. Upload Compose code and screenshot: Upload the Compose code file for a UI screen and a screenshot of its Compose Preview, with a red outline highlighting the issue—in this case, items in the Bottom Navigation Bar that should be evenly spaced.

Example: Preview with problem area highlighted
Example: Preview with problem area highlighted

    2. Prompt Gemini: Open the chat prompt section and enter

    "Given this code file describing a UI screen and the image of its Compose Preview, please fix the part within the red outline so that the items are evenly distributed."
Screenshot of Google AI Studio: Smart UI Fixes with Gemini
Google AI Studio: Smart UI Fixes with Gemini

    3. Gemini's solution: Gemini returned code that successfully resolved the UI issue.

Screenshot of Example: Generated code fixed by Gemini
Example: Generated code fixed by Gemini

Example: Preview with fixes applied
Example: Preview with fixes applied

Experiment 3: Integrating Gemini prompts in your app

Gemini can streamline experimentation and development of custom app features. Imagine you want to build a feature that gives users recipe ideas based on an image of the ingredients they have on hand. In the past, this would have involved complex tasks like hosting an image recognition library, training your own ingredient-to-recipe model, and managing the infrastructure to support it all.

Now, with Gemini, you can achieve this with a simple, tailored prompt. Let's walk through how to add this "Cook Helper" feature into your Android app as an example:

    1. Explore the Gemini prompt gallery: Discover example prompts or craft your own. We'll use the "Cook Helper" prompt.

Gemini prompt gallery in Google AI for Developers
Google AI for Developers: Prompt Gallery

    2. Open and experiment in Google AI Studio: Test the prompt with different images, settings, and models to ensure the model responds as expected and the prompt aligns with your goals.

Moving image showing the Cook Helper prompt in Google AI for Developers
Google AI Studio: Cook Helper prompt

    3. Generate the integration code: Once you're satisfied with the prompt's performance, click "Get code" and select "Android (Kotlin)". Copy the generated code snippet.

Screengrab of using 'Get code' to obtain a Kotlin snippet in Google AI Studio
Google AI Studio: get code - Android (Kotlin)

    4. Integrate the Gemini API into Android Studio: Open your Android Studio project. You can either use the new Gemini API app template provided within Android Studio or follow this tutorial. Paste the copied generated prompt code into your project.

That's it - your app now has a functioning Cook Helper feature powered by Gemini. We encourage you to experiment with different example prompts or even create your own custom prompts to enhance your Android app with powerful Gemini features.

Our approach on bringing AI to Android Studio

While these experiments are promising, it's important to remember that large language model (LLM) technology is still evolving, and we're learning along the way. LLMs can be non-deterministic, meaning they can sometimes produce unexpected results. That's why we're taking a cautious and thoughtful approach to integrating AI features into Android Studio.

Our philosophy towards AI in Android Studio is to augment the developer and ensure they remain "in the loop." In particular, when the AI is making suggestions or writing code, we want developers to be able to carefully audit the code before checking it into production. That's why, for example, the new Code Suggestions feature in Canary automatically brings up a diff view for developers to preview how Gemini is proposing to modify your code, rather than blindly applying the changes directly.

We want to make sure these features, like Gemini in Android Studio itself, are thoroughly tested, reliable, and truly useful to developers before we bring them into the IDE.

What's next?

We invite you to try these experiments and share your favorite prompts and examples with us using the #AndroidGeminiEra tag on X and LinkedIn as we continue to explore this exciting frontier together. Also, make sure to follow Android Developer on LinkedIn, Medium, YouTube, or X for more updates! AI has the potential to revolutionize the way we build Android apps, and we can't wait to see what we can create together.