Paramjit Singh Rana
Paramjit Singh Rana

Reputation: 809

Converting my existing android studio project to kotlin?

Error:Could not find com.android.tools.build:gradle:3.0.0-alpha2

Searched in the following locations:

file:/User/3.0/android-studio/gradle/m2repository/com/android/tools/build/gradle/3.0.0-alpha2/gradle-3.0.0-alpha2.pom

https://jcenter.bintray.com/com/...

Required by: project

It is working fine with Android studio 2.3.

I have tried cleaning project, deleting build folder from the project, invalidate and restart.

What can I do?

Upvotes: 1

Views: 2499

Answers (2)

Ramanjeet
Ramanjeet

Reputation: 680

Converting an android project to kotlin

This is a small write-up of my experiences from converting a native android-app from java to kotlin.

Convert your project!

The first step is easy, android-studio will do most of the work for you. To convert the existing java code into kotlin, simply select the src/main/java folder in the project and choose Code->“Convert Java File to Kotlin File”. Android studio will then try as best as it can to convert all your java-code to kotlin-code.

Android studio will convert all your .java files into .kt files in-place, leaving them in src/main/java.

Your project will probably not compile now, because of differences in how java and kotlin handle #nullability.

nullability(.!!?) issues One of the big advantages kotlin has over java is the handling of nullability. By default, an object is non-nullable and has to explicitly specified to be nullable.

Android-annotations (if applicable)

To use android-annotations, add the kotlin-kapt plugin to your build-script and add the android-annotations-dependency to the kapt-configuration:

...
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
...

dependencies{
...
    kapt "org.androidannotations:androidannotations:4.3.1"

}

Upvotes: 5

nhaarman
nhaarman

Reputation: 100388

Include maven { url 'https://maven.google.com' } in your repositories sections:

buildscript {
  repositories {
    /* ... */
    maven { url 'https://maven.google.com' }
  }
}

repositories {
   /* ... */
   maven { url 'https://maven.google.com' }
}

If you use Gradle 4+, you can use google() instead.

Upvotes: 0

Related Questions