Help with possible external annotation problems with IDE plugin in Android Studio


#1

Hi,

I’m running into some trouble trying to use Android Studio to develop a Kotlin-based simple Android application. It appears that I cannot get the IDE plugin and the gradle plugin to agree on the type signatures of the various Android SDK methods that I am overriding.

I’m running:
Android Studio Preview 0.4.0 with embedded Android SDK
OS X 10.9.1
Java 1.6.0_65
Kotlin IDE plugin 0.6.1683
kotlin-gradle-plugin 0.6.1673
kotlin-stdlib 0.6.1673
Android compile SDK version 19
Build Tools 19.0.0

I was following the guide from the Kotlin blog[1], which recommends that the version of the stdlib and gradle-plugin should match the IDE plugin. However, there is no 0.6.1683 version in Maven Central for either of these. I tried version 0.6.1910, which is the newest, but this also resulted in the same problem.

The issue is, the IDE is flagging various overrides in my test activity and fragment with errors, but the gradle plugin is building OK. If I change the signatures to make the IDE happy, the  gradle plugin fails to build.

A specific example is the override for:
android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)

The IDE wants every parameter type to be nullable, however, the gradle plugin wants the first parameter to be non-nullable.

I have tried configuring the gradle plugin to use the same external annotations jar the IDE plugin is using, but it seems that I can only specify additional external annotation jars and not actually replace the default one, as the errors remain. I have also tried configuring the Android SDK inside the IDE to use the same external annotation jar the gradle plugin is using, but this seems to have no effect (other than the IDE complaining that external annotations are not configured).

Does anyone have any suggestions? It seems I can work around the issues in a one-off fashion by specifying custom Kotlin signatures in my project for the problematic methods, but I’d love to find a more general solution.

If I can provide any more information, please let me know. Thanks in advance!

[1] http://blog.jetbrains.com/kotlin/2013/08/working-with-kotlin-in-android-studio/


#2

Ok, now I'm really confused. Previously I installed the stable version of Android Studio (with the embedded Android SDK) and then used "Check for Updates" to upgrade to 0.4.0. For kicks I installed 0.4.0 directly from the zip file at http://tools.android.com/download/studio/canary/0-4-0, and configured it to use an existing Android SDK I had installed on my machine. Following the same steps I followed before, everything appears to be working now.

I’m not sure why it would make a difference to upgrade 0.3.2 to 0.4.0 vs installing 0.4.0 directly. It’s quite possible I made some sort of error, however, I followed the exact same procedure a half dozen times and only installing the standalone 0.4.0 zip has worked.

So, I appear to be working now, but I’d love to hear anyone’s thoughts on what this might be, or how I could troubleshoot it…


#3

Hello, Let's try to understand what happened...

but this seems to have no effect (other than the IDE complaining that external annotations are not configured).

Am I right that you saw a notification that Android SDK Annotations are missed? What happen after you click on it?

and configured it to use an existing Android SDK I had installed on my machine.

Is it possible that you have already configured annotations for this existing SDK?

Note,  than now, unfortunatly, there isn’t any way in UI of Android Studio to  see a list of annotation roots that are added to SDK.


#4

Maybe you could try  removing kotlin plugin first from android studio then restart the IDE.

After that  open one of your .kt file, and wait until IDE tells us there is plugin for .kt extension.
Then just follow the instruction to install the plugin.

Once this finished, maybe you need to regenerate (or recreate) onCreateView method again.
Hope this work.

In my case i had this problem(both in android studio and intellij 13.0.1) when creating a class derived from ContentProvider.
And managed to solve the problem by reinstalling the plugin and regenerate the ContentProvider methods.

BTW, I’m on linux and using kotlin plugin 1673, android studio 0.4.3