Using Gemini in Android Studio

Using Gemini in Android Studio

/ Today’s Tech News /

Recently, the Shanghai Municipal Science and Technology Commission released the “2024 Technology Innovation Action Plan” project application guidelines in the field of 6G frontier technology, soliciting key technologies including: co-frequency interference and spectrum sharing key technologies for 6G mobile phones directly connected to satellites, high-order electromagnetic modulation communication technology using intelligent transmission metasurfaces, AI empowerment key technologies for 6G wireless information center networks, and key technologies for 6G millimeter wave and terahertz RF chips.

/ Author Introduction /

This article is adapted from ChenYhong‘s blog, which mainly shares how to use Gemini in Android Studio. I believe it will be helpful to everyone!

Original article address:

https://juejin.cn/post/7382979793741135912

/ Introduction /

Gemini is an AI tool embedded in the latest version of Android Studio, which helps developers improve coding efficiency through code completion, code explanation, providing improvement suggestions, error analysis, and more. Of course, like most AI tools currently available, Gemini may sometimes provide inaccurate or erroneous information, or code that does not actually run, so developers need to check the answers given by Gemini before use.

Starting from Android Studio Koala (2024.1.1), Gemini can be used in Android Studio. This article briefly introduces how to use Gemini in Android Studio.

/ Enable Gemini Functionality /

Countries Providing Services

Gemini in Android Studio is currently available in many countries, and more countries will be added in compliance with national regulations. The list of countries where services are currently available can be viewed on the official website.

There are actually no services available in China on the official website, but after using a scientific internet access method, Gemini can still be used normally.

Log in to Google Account

To use Gemini in Android Studio, you need to log in with a Google account.

Previously, in an environment with scientific internet access, when I used Google login in Android Studio, the redirected web page had already logged into the Google account and authorized it, but Android Studio still prompted a connection timeout, as shown in the image below:

Using Gemini in Android Studio

After consulting the information, the solution is to set the HTTP Proxy’s Host and Port to the Host and Port used by the scientific internet access tool in an environment with scientific internet access.

In Settings -> Appearance & Behavior -> HTTP Proxy, select Manual proxy configuration -> HTTP, set the Host name to 127.0.0.1 (or localhost), and set the Port number to the port number used by the scientific internet access tool (each tool may use different ports, set according to the tool you are using).

Using Gemini in Android Studio

After setting, you can log in to your Google account normally.

Using Gemini in Android Studio

Enable Gemini

After logging into the Google account, authorize Gemini to use data on the add account page.

Using Gemini in Android Studio

Then you can find the Gemini plugin in the sidebar for further configuration.

Agree to Some Agreements

Using Gemini in Android Studio

Using Gemini in Android Studio

Using Gemini in Android Studio

Set the Scope of Shared Data

Set this to share all project codes for now.

Using Gemini in Android Studio

Start Using Gemini

Using Gemini in Android Studio

/ Data Sharing Settings /

The code completion feature of Gemini will be more accurate after enabling data sharing. Since the code will be shared, it still needs to be used with caution in company projects. You can select the data sharing mode in Settings -> Tools -> Gemini -> Context Awareness, as shown below:

Using Gemini in Android Studio

Set Sharing Scope via Configuration File

You can set the scope of data not to be shared by creating a .aiExclude file (similar to .gitignore).

Create a file named .aiExclude under the project.

Using Gemini in Android Studio

Configure the files or folders that are not allowed to be shared in .aiExclude.

Using Gemini in Android Studio

Syntax setting examples can be viewed on the official website.

/ Using Gemini /

Code Completion

After setting up data sharing, you can use Gemini’s code completion feature. This feature can be toggled in Setting -> Tools -> Gemini.

Using Gemini in Android Studio

When enabling code, Gemini provides suggestions based on the context of the code before and after the cursor. Press the Tab key to use the suggestion and Esc key to clear the suggestion.

Using Gemini in Android Studio

Explain Code

Right-click -> Gemini -> Explain Code to use Gemini to help understand the selected code snippet.

Using Gemini in Android Studio

Improvement Suggestions

Right-click -> Gemini -> Suggest Improvements to use Gemini to help optimize the selected code snippet.

Using Gemini in Android Studio

Error Analysis

If a crash occurs during application debugging, you can click Ask Gemini in Logcat to let Gemini help analyze why the crash happened and provide solutions.

Using Gemini in Android Studio

Recommended Reading:

My new book, “The First Line of Code, 3rd Edition” has been published!

New features in Android 15, enforcing edge-to-edge full-screen experience.

How to create an excellent experience on Android watches and foldable devices? Come and take a look.

Welcome to follow my public account.

Learn technology or submit articles.

Using Gemini in Android Studio

Using Gemini in Android Studio

Long press the image above to scan the QR code to follow.

Leave a Comment