Integrating and Playing with CodeGPT on Android Studio

Luis Diaz
Globant
Published in
6 min readMay 16, 2023

Artificial Intelligence (AI) has become increasingly important in Technology and IT. AI algorithms can analyze large amounts of data faster than humans, identify patterns and correlations, and make predictions or recommendations based on that data.

CodeGPT is a plug-in developed by OpenAI that provides an interface for developers to interact with GPT-3, a state-of-the-art language generation model developed by OpenAI. With CodeGPT, developers can easily integrate language generation capabilities into their applications and automate tasks such as generating code, writing articles, answering questions, and more. CodeGPT supports several programming languages, such as Python, Java, JavaScript, Ruby, PHP, and more.

In this article, we will focus on how we could add this plug-in into the most popular Android IDE with Kotlin programing language.

DISCLAIMER: remember that all the code you ask for a review or share with the AI will be public, so be careful in what you share. If not, you can have legal issues.

Let’s take a look!

  1. First, on Android Studio, open the Settings window.
Android Studio -> Settings
Android Studio -> Settings

2. Then select the “Plug-ins” option, and you’ll see a lot of available plug-ins for Android Studio. On the search bar, type “CodeGPT,” then some options will show up; in this case, we will choose the one with the official Open AI logo and install it.

Preferences -> Plugins -> Bar search “codegpt”
Preferences -> Plug-ins -> Bar search “codegpt”

3. You’ll find the plug-in now on the right panel side (by default); click on it.

ChatGPT, chat window open on Android Studio
ChatGPT, chat window open on Android Studio

4. You have to create a free account to get an API Key here: https://platform.openai.com/account/api-keys

https://platform.openai.com/account/api-key
https://platform.openai.com/account/api-key

5. Now set the API Key to CodeGPT settings. You can click on preferences and search it or try to write something on the chat plug-in and just click on the link “Open Settings” and paste the API Key you created before.

Preferences -> Tools -> CodeGPT -> Paste API Key

That’s all you can start using this plug-in; let’s see how useful it is.

Exploring all its power!

Now we can start playing with ChatGPT, so let’s begin with some of the repetitive tasks that for sure a lot of projects contain. Let’s ask about some implementation for an adapter (RecyclerView), and we’ll try to build a simple list using RecyclerView first.

Chat from Plugin CodeGPT
Chat from Plug-in CodeGPT

So we realized that we need to be more specific with our requests and think exactly what we want since I was expecting ChatGPT building for me all code needed for implementation; as Adapter and ViewHolder.Another thing to remember is that ChatGPT is not losing the context we are discussing, which is very cool. Let’s continue.

Ask to CodeGPT for an Adapter with 2 views

Observe that we can continue working on the same code generated already.

Not bad for an Android beginner, isn’t it? Let’s increase the difficulty.

Increasing code difficulty!

So I ask the same layout but now using ConstraintLayout, and ChatGPT gives me the result very well. Then I ask the following question: “Give me xml code for a layout using constraint layout on android with one image to left (square) and on right side you’ll set 4 text, one for date, another for title, description and the last one for “learn more” do it with a good UX/UI”.

Gift asking about building a custom UI
Gift asking about building a custom UI

Let’s copy and paste the code already generated by CodeGPT to see how good the result is.

UI built by codeGPT
UI built by codeGPT

Here come the difficulties. On that view we see two texts overlapping (title and date), and ChatGPT was able to assume that “Learn More” was an actionable thing and did it differently than the rest of the views.

Exploring the plug-in, we count with multiple chats (it looks like every chat has a limit to interact with ChatGPT), also we can find conversation histories, and by looking at the code, if we highlight a piece of code (right click) we have some extra options.

Exploring some useful options from plugin CodeGPT
Exploring some useful options from plug-in CodeGPT

Playing a little bit with this, I was able to ask for some unit tests for the UI on onBindViewHolder.

CodeGPT provides good possible options to be applied for unit tests, even though some of them were a little bit hard to figure out, and also some of them look not so helpful but are valid.

Every option on that menu launches the property action to ChatGPT with some context already about the code; of course, we have to be specific with the tasks that we need to take all the power of ChatGPT and make faster our daily tasks!

If the code is not valid for any of those actions, ChatGPT will tell you. And also, keep in mind the free version has a limit for every “chat/session” with ChatGPT; you can open a new chat just by tapping on “+”, and that’s all, but it will be a new chat with no context.

Could CodeGPT really help us with our daily tasks?

With the results that we get practicing a little bit more with plug-in CodeGPT, we can say that it is beneficial, especially for people who don’t have so much experience 1–2 years writing Android code, the options “Explain”, “Refactor” and “Optimize” are the ones that could reduce the learning time and deliver a better result most optimally, but optimal from a code point of view, we have to take care on the readable part of code of course. The other great option for this plug-in is the action “Write Test”, this task always be with us in our projects, and also the true for most of the developers is that we feel that it is not a challenging activity that we enjoy, so this could save us a lot of time for sure.

Deliver tasks without looking at generating code by ChatGPT first?

No way, this kind of AI is really awesome. Still, it has just a little time from its launching, now is saving all the information that the AI can, and the supervision to see and apply the code generated by ChatGPT has to be done by experts on the matter, that are the only ones that could understand and do the proper changes to the code to work correctly, also remember we have to take care of privacy policies for our clients to implement this kind of technology.

In conclusion, the plug-in CodeGPT is a great tool to integrate; as mentioned above, it has some great functions, and I didn’t see any slow performance on Android Studio. The answers were always fast; maybe an improvement could be seeing the possibility of removing the animation typing and just showing the code immediately. AI will help us more and more in our daily activities; let’s look for some new excellent alternatives.

As an Android developer, using plug-ins could be a little harder at the beginning since we are used to searching on Google and finding some StarckOverflow links when we have a doubt related to code, so maybe with time, the use of the plug-in could decrease our searching time to look for a bug, maybe look for some examples related to how to do a UT, and of course at the end of building a feature, see how applies the optimized code instead of waiting for a code reviewer who could suggest any improvements so that you can find those results, of course, searching on google but probably you will spend more time doing that instead of using the plug-in. For sure, a good recommendation is to start using the CodeGPT plug-in.

--

--