BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Google Introduces Gemini AI Features to Android Studio

Google Introduces Gemini AI Features to Android Studio

Google has released a set of updates to Gemini in Android Studio, aiming to enhance the developer productivity through AI-powered features. This release is designed to bring AI to every stage of the development lifecycle, such as AI-assisted coding, refactoring, generating documentation, analyzing and test code, and suggesting fixes.

Gemini now allows developers to prompt from the code editor for code suggestions to modify, optimize, or even add code.

(image taken from android developers blog)

To see an input field for the prompt, developers have some possibilities: right click in the code editor and select Gemini > Generate code from the context menu; or highlight code desidered to Gemini to modify, right-click in the code editor, and select Gemini > Transform code from the context menu; or press CTRL+\ (Command+\ on macOS). After prompting Gemini with a description of what is desired to modify/add, Gemini will process the request and show a code diff, so the developer can decide to refine and try a new prompt or just accept all changes.

AI code completion of code is now available in Android Studio; this feature aims to save time and let developers complete coding faster by suggesting full functions. It is important to note that when AI code completion is enabled, Gemini might send additional information to provide context to the LLM, such as pieces of code, file types and other necessary information to provide more relevant suggestions.

To get started with AI code completion in the latest version of Android Studio Jellyfish or higher, open an Android Studio project and click View > Tool Windows > Gemini, sign into the Google account and allow Gemini to access context from the codebase. This can be done any time through Android Studio > Settings > Gemini > Augment responses with information from your codebase.

Now developers can enhance code organization with AI-powered refactoring and documentation features. Let's take a look at:

  • Documentation Generation: allow generating documentation drafts for functions by selecting a snippet, right-clicking, and selecting Gemini > Document Function. Gemini provides suggestions that can be applied or refined.

  • Intelligent Renaming: Gemini offers context-aware suggestions for variable names, classes, and methods to maintain consistency throughout the project when using Refactor > Rename action.
  • Variable Name Refinement: based on the code context, Gemini can suggest names for variables or methods, aiming to make the names more intuitive and descriptive. It is accessible by right-clicking in the editor and selecting Gemini > Rethink variable names.

  • Commit Message Suggestions: Gemini can generate commit messages based on context from the code changes in the current commit and recent past commits to suggest a detailed commit message. Click the Suggest commit message button in the Commit tool window to receive context-relevant commit messages.

Developers can use Gemini to analyze apps crash reports, generate insights, provide a crash summary, and when possible recommend next steps, including sample code and providing guidance and links to relevant documentation. The crashes reported by Android Vitals and Firebase Crashlytics can be analyzed into the IDE's App Quality Insights tool window.

When writing unit tests for an app, Gemini can suggest test scenarios using the context of the code. During the generation of unit test scenarios, Gemini includes detailed names and descriptions for the tests, aiming to improve the understanding of each suggested test. By now the developer still needs to implement the test behavior itself. To generate unit test scenarios the developer just needs to right-click on a class and select Gemini > Unit test scenarios.

According to Google, Android Studio does not send source code to servers without user consent, ensuring privacy and security. Developers can opt-in to enable Gemini's features and have control over their data. Google states it is committed to the responsible use of AI.

More details about Gemini features in Android Studio can be found in the Android developers blog.

About the Author

Rate this Article

Adoption
Style

BT