Developing applications for Android often begins with choosing a programming language, and although in recent years Kotlin has become a de facto standard, many developers still prefer Java. There can be many reasons: from the need to support legacy code to personal preferences or the requirements of a specific employer. However, having created a project in Android Studio with the Kotlin language of choice, beginners are often faced with the question of whether it is possible to completely return to the classic approach.
The transition process is not a trivial one-button click, since it affects the project structure, build files and compiler configuration. You will need to perform a series of steps to deactivate plugins, remove dependencies, and manually convert files. Below we will detail each step necessary to get your project back to full health. Java-based.
It is worth noting right away that mixing languages โโin one project is technically possible and supported by the development environment, but if your goal is a clean environment without unnecessary code, a deep cleaning of the configuration files will be required. Let's proceed to a detailed examination of the procedure.
Analysis of the current project configuration
Before making any changes, you need to understand which components are responsible for support Kotlin in your current project. Open the file build.gradle (project level) and carefully study the block dependencies. This is where libraries are most often written, without which compilation of Kotlin code is impossible.
Particular attention should be paid to lines containing a reference kotlin-stdlib. This library is fundamental to the operation of any code in this language. If you plan to abandon it completely, the presence of this dependency will be an obstacle to building a pure Java project.
Also check the file settings.gradle. In modern versions Android Studio there may be plugins that automatically enable language support when the project is initialized. Ignoring this step may result in the IDE continuing to suggest creating new classes in a language you don't like.
Before making any changes, take a full backup of the project or create a new branch in Git version control so that you can rollback in case of an error.
It is important to understand the difference between having a plugin in the IDE and having dependencies in the project. Even if the plugin is disabled, but references to standard libraries remain, the project will not be built as pure Java. Therefore, the analysis must be comprehensive. build.gradle there are still references to standard libraries, the project will not be built as pure Java. Therefore, the analysis must be comprehensive.
Disabling the Kotlin plugin in the IDE settings
The first logical step is to disable built-in language support in the development environment itself Android Studio. By default, this plugin is active, which allows the code editor to highlight syntax and offer autocompletion for Kotlin. However, for working with pure Java it is not strictly necessary, although it does not interfere.
To remove unnecessary load on the interface and avoid accidentally creating files with the extension .kt, go to the settings menu. On Windows or Linux, the path looks like File โ Settings โ Plugins, and on macOS - Android Studio โ Preferences โ Plugins. In the list of installed plugins, find "Kotlin".
After detecting the plugin, uncheck the box or click the "Disable" button. The system will require a restart of the IDE for the changes to take effect. This step is critical for those who want to completely eliminate the possibility of using the syntax of another language in the production environment.
- ๐ Disabling the plugin prevents the creation of new Kotlin files through the project wizard.
- โ๏ธ The RAM consumption of the development environment itself is reduced by disabling the code analyzer.
- ๐ The interface will become cleaner, and unnecessary menu items related to conversion will disappear.
โ ๏ธ Attention: If you work in a team where other developers use Kotlin, disabling the plugin on your machine may result in you not being able to correctly read their code or resolve merge conflicts in such files.
Remember that disabling the plugin in the IDE does not remove code from the project. Files with the extension .kt will remain on disk, the environment will simply stop highlighting and compiling them unless you remove the corresponding settings from the build scripts.
Modifying Gradle build scripts
The most important part of the process is editing the build files Gradle. They are the ones who dictate to the compiler which language functions to use. Open the file build.gradle at the project level (root level). In the block plugins you will most likely see a line like id 'org.jetbrains.kotlin.android' version '...' .
This line must be deleted. It tells the build system that this project is a Kotlin project and requires the use of the appropriate plugin. Without removing it, attempting to build the project after removing the libraries will result in a configuration error.
Next, go to the file build.gradle at the module level (usually app). Here you need to find dependencies. Remove all lines containing implementation "org.jetbrains.kotlin:kotlin-stdlib.... Also check the block android { defaultConfig ... } for specific Kotlin compiler settings.
// Example of what needs to be removed from build.gradle (Project level):
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android' version '1.8.0' // Remove this line
}
After making changes, be sure to click the Sync Nowbutton that appears at the top of the editor. This action will update the dependency tree and rebuild the project indexes. If the synchronization was successful without errors, then you have successfully removed the language lock.
Sometimes a project may use annotations or functions specific only to Kotlin that have been added to Java classes. After clearing the configs, such places can cause compilation errors that will have to be corrected manually by removing unsupported imports.
Converting existing code to Java
If your project already has code written in Kotlin, simply removing the settings will not turn it into Java. The files will remain dead weight. Fortunately, Android Studio provides a powerful built-in tool for automatic conversion.
Open any file with the extension .kt. In the top menu, select Code โ Convert Kotlin to Java. The editor will analyze the code and create a new file .java with equivalent logic. This process can take time on large projects.
Automatic conversion is not always ideal. Complex constructs such as coroutines or extended functions can be converted into bulky code using anonymous classes or callbacks. You will need to manually optimize the result.
| Kotlin design | Analog in Java | Conversion complexity |
|---|---|---|
| Data Class | POJO with getter/setter | Low |
| Lambda expressions | Anonymous classes | Medium |
| Null safety (?, !!) | Checks if != null | High |
| Coroutines | AsyncTask / Threads | Very high |
After successfully converting all files, do not forget to delete the original .kt files from the project directory so as not to clog the repository. Also check the manifest and resources for references to classes that were renamed during the conversion process.
โ ๏ธ Warning: When converting code that uses Coroutines, the automated tool may produce ineffective code. In such cases, it is recommended to rewrite the asynchronous logic manually using modern Java approaches, for example,
java.util.concurrent.
โ๏ธ Check after conversion
Clearing the cache and rebuilding indexes
After all manipulations with files and settings Android Studio may continue to behave strange, offering old import options or highlighting the code with errors that actually do not exist. This is due to the fact that the IDE maintains a deep cache of indexes.
To completely reset the state, go to the menu File โ Invalidate Caches / Restart. In the dialog box that appears, check the boxes next to all the items, especially โClear file system cache and Local Historyโ. This will force the environment to rescan the entire project using the new rules.
The reboot may take several minutes, especially if the project is large. Do not interrupt the indexing process as this may corrupt the IDE's internal databases. Once completed, you will see a clean project, ready to work exclusively with Java.
If after a reboot you are still seeing warnings about Kotlin, check your global settings. Sometimes the New Project Wizard will remember the last language selection. Resetting the IDE settings to default may be necessary as a last resort.
What to do if the project does not build after cleaning?
If, after removing dependencies, the project gives "Unresolved reference" errors, check whether you are using libraries that are themselves written in Kotlin and require stdlib. In this case, you will have to either leave minimal support or find Java analogues of these libraries.
Setting up templates for creating new files
To prevent Android Studio from prompting you to create activities or fragments on Kotlinin the future, you need to change the template settings. Go to Settings โ Editor โ File and Code Templates.
In the list on the left, find the section Code and select templates such as "Activity", "Fragment", "Service". Make sure that the file extension field is .javaand that the template contents follow Java syntax. If there is code in another language, replace it.
It also makes sense to check the settings of the New Project Wizard. When creating a new application (File โ New โ New Project), at the language selection stage, make sure that Javais selected. The IDE may remember this choice for the current session, but reset it when refreshing.
Properly setting up templates saves the developer time by eliminating the need to manually change the file extension and rewrite the code when creating each new class.
Frequently asked questions (FAQ)
Is it possible to use Java and Kotlin in one project at the same time?
Yes, this is a fully supported practice. You can have files .java and .kt in the same folder. The main thing is to leave plugins and dependencies for Kotlin connected in files build.gradle. Conversion is only needed if you want to completely get rid of one of the languages.
Does the abandonment of Kotlin affect the size of the APK file?
The abandonment of Kotlin allows you not to include the library in the APK kotlin-stdlib, which can reduce the size of the application by approximately 500 KB - 1 MB (depending on the version and compression). However, modern ProGuard and R8 tools can trim unused parts of the library, making the difference less noticeable.
Why does Android Studio keep offering to convert Java to Kotlin?
This is a standard IDE feature designed to help developers migrate to a modern stack. If the Kotlin plugin is enabled, the convert button will always be available. To remove it, you need to disable the plugin in the settings, as described at the beginning of the article.
Will there be problems with Google libraries if you remove Kotlin?
Most Google libraries (AndroidX) are written in Java or are fully compatible. However, some new libraries, especially those related to Jetpack Compose, require Kotlin. If you use only the classic View approach, there should be no problems.