Hi Guy’s Welcome to Proto Coders Point. In this android studio article will learn to how to convert java file to kotlin & some developer are facing some error while converting java to kotlin let’s fix it.
How to Convert Android jave code to kotlin
Time needed: 1 minute
- Step 1
Select the java file that you want to convert
- Step 2
In Android Studio menubar goto Code
- Step 3
In code menu you will see a option “convert java file to kotlin file”, Click on it and your file will get converted automatically to .kt.
Android Studio Convert Java to Kotlin not working
I was just trying to convert my old android project which is in JAVA language to kotlin but encounter and error:
Build was configured to prefer settings repositories over project repositories but repository ‘MavenRepo’ was added by build file ‘app\build.gradle.
Then after lot’s of research and solution by developer on stackoverflow I finally found out the 100% working solution on Android Convert Java File to Kotlin Not working.
Solution
You need to update settings.gradle
Replace this line
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
with this
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
Refer below screenshot for easily understanding
Now hit on sync now, and try to convert file by following above steps.
Thanks Me, By Subscribing me on youtube ProtoCodersPoint.