Android Studio error with ServiceStack Plugin

I’m building a mobile app using Android Studio, and thought I’d use the ServiceStack Add Reference plugin documented here:

I imported the plugin, but the menu item doesn’t show up to launch the add reference tool. Looking at the Android Studio logs, I see the following error:

cannot create class "UpdateServiceStackReference" [Plugin: net.servicestack.ideaplugin]
    com.intellij.diagnostic.PluginException: cannot create class "UpdateServiceStackReference" [Plugin: net.servicestack.ideaplugin]
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convertStub(ActionManagerImpl.java:176)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convert(ActionManagerImpl.java:516)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.getActionImpl(ActionManagerImpl.java:496)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.getAction(ActionManagerImpl.java:489)
    	at com.intellij.openapi.actionSystem.DefaultActionGroup.unStub(DefaultActionGroup.java:354)
    	at com.intellij.openapi.actionSystem.DefaultActionGroup.getChildren(DefaultActionGroup.java:312)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl$5.compute(ActionManagerImpl.java:1310)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl$5.compute(ActionManagerImpl.java:1303)
    	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:894)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1303)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1297)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.doPreloadActions(ActionManagerImpl.java:1287)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.access$200(ActionManagerImpl.java:76)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl$4.run(ActionManagerImpl.java:1268)
    	at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:405)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    	at java.lang.Thread.run(Thread.java:695)
    	at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:56)
    Caused by: com.intellij.diagnostic.PluginException: UpdateServiceStackReference : Unsupported major.minor version 51.0 [Plugin: net.servicestack.ideaplugin]
    	at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:130)
    	at com.intellij.ide.plugins.cl.PluginClassLoader.tryLoadingClass(PluginClassLoader.java:77)
    	at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:66)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Class.java:249)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convertStub(ActionManagerImpl.java:152)
    	... 21 more
    Caused by: java.lang.UnsupportedClassVersionError: UpdateServiceStackReference : Unsupported major.minor version 51.0
    	at java.lang.ClassLoader.defineClass1(Native Method)
    	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
    	at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    	at java.lang.ClassLoader.defineClass(ClassLoader.java:471)
    	at com.intellij.util.lang.UrlClassLoader._defineClass(UrlClassLoader.java:259)
    	at com.intellij.util.lang.UrlClassLoader.defineClass(UrlClassLoader.java:255)
    	at com.intellij.util.lang.UrlClassLoader._findClass(UrlClassLoader.java:231)
    	at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:124)
    	... 27 more
    
    
    
    com.intellij.diagnostic.PluginException: cannot create class "AddServiceStackReference" [Plugin: net.servicestack.ideaplugin]
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convertStub(ActionManagerImpl.java:176)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convert(ActionManagerImpl.java:516)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.getActionImpl(ActionManagerImpl.java:496)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.getAction(ActionManagerImpl.java:489)
    	at com.intellij.openapi.actionSystem.DefaultActionGroup.unStub(DefaultActionGroup.java:354)
    	at com.intellij.openapi.actionSystem.DefaultActionGroup.getChildren(DefaultActionGroup.java:331)
    	at com.intellij.ide.actions.WeighingActionGroup.getChildren(WeighingActionGroup.java:61)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl$5.compute(ActionManagerImpl.java:1310)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl$5.compute(ActionManagerImpl.java:1303)
    	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:894)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1303)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1318)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.preloadActionGroup(ActionManagerImpl.java:1297)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.doPreloadActions(ActionManagerImpl.java:1287)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.access$200(ActionManagerImpl.java:76)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl$4.run(ActionManagerImpl.java:1268)
    	at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:405)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    	at java.lang.Thread.run(Thread.java:695)
    	at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:56)
    Caused by: com.intellij.diagnostic.PluginException: AddServiceStackReference : Unsupported major.minor version 51.0 [Plugin: net.servicestack.ideaplugin]
    	at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:130)
    	at com.intellij.ide.plugins.cl.PluginClassLoader.tryLoadingClass(PluginClassLoader.java:77)
    	at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:66)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Class.java:249)
    	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.convertStub(ActionManagerImpl.java:152)
    	... 23 more
    Caused by: java.lang.UnsupportedClassVersionError: AddServiceStackReference : Unsupported major.minor version 51.0
    	at java.lang.ClassLoader.defineClass1(Native Method)
    	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
    	at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    	at java.lang.ClassLoader.defineClass(ClassLoader.java:471)
    	at com.intellij.util.lang.UrlClassLoader._defineClass(UrlClassLoader.java:259)
    	at com.intellij.util.lang.UrlClassLoader.defineClass(UrlClassLoader.java:255)
    	at com.intellij.util.lang.UrlClassLoader._findClass(UrlClassLoader.java:231)
    	at com.intellij.ide.plugins.cl.PluginClassLoader.loadClassInsideSelf(PluginClassLoader.java:124)
    	... 29 more

Thanks @mjc for reporting the issue, could you give me some more info?

Which version of Android Studio?
Which version of the plugin? (latest is 1.04).
What OS you are running (and version, eg OSX 10.x.x).

It looks like Android Studio is having a problem just initializing the plugin. This was an issue with an older version of the plugin and OSX due to OSX only officially supporting JDK 1.6 and not yet 1.7.

The latest version of the plugin was changed to support 1.6 and compiled targeting 1.6 which resolve this issue in my own testing.

Any more info you can provide would appreciated, cheers.

Thank you, yes, I just had to upgrade to the latest. ServiceStack makes developing mobile apps in Java a real awesome endeavor.

Couple things, and maybe these are for a separate thread:

  1. I’d like to be able to inject some kind of background task generically without having to wrap every getAsync, postAsync, deleteAsync, putAsync, etc… For example, across all my call, it would be nice to be able to have some logic that always gets run in the same AsyncTask that all those calls run, without having to individually wrap everything. Useful for example to do an internet connection test check, etc… Maybe there’s a way to do it already, but I don’t see it, or maybe you have a cool tip to advise.

  2. I love all those dtos you create, but extending them is a pain. So for example I want to extend a few of the DTOs to cache and work with them locally in a sqlite db or on the file system, but extending inner static classes isn’t so simple. Not sure if you have some suggestions there.

  3. I’m using a custom AndroidServiceClient and JsonServiceClient because of one “bug” (I think) in the Utils.java class.

line 513 (around there) in Utils.java
else if (varName.toLowerCase().equals(“stacktrace”)) {
//MJC: throws UnsupportedNullException when stacktrace = “null” (authenticate)
//status.setStackTrace(jsonElementEntry.getValue().getAsString());
}

I’m using the authenticate service in my app, and the stacktrace comes back with “null”, and this line blows up and the object that’s returned then is JsonNull … When I comment it out, I get my nice response with a responseStatus object with the errors in it like I’d expect.

That’s it for now, but it’s a REAL pleasure to work with ServiceStack in the Android Studio IDE!!! THANKS!

1 Like

Thanks for the feedback :slight_smile:

  1. Have you tried setting a RequestFilter or GlobalRequestFilter? e.g:

    AndroidServiceClient.GlobalRequestFilter = new ConnectionFilter() {
    @Override public void exec(HttpURLConnection conn) {
    events.add(“GlobalRequestFilter”);
    }
    };

    client.RequestFilter = new ConnectionFilter() {
    @Override public void exec(HttpURLConnection conn) {
    events.add(“RequestFilter”);
    }
    };

There’s also an opportunity to extend AndroidServiceClient and override execTask() which gets called before every async request. Let me know if the above options aren’t suitable.

  1. Can’t nested classes be extended like normal?

    public class ExtendedRockstar extends dto.Rockstar {
    public Integer ExtendedId = null;

     public ExtendedRockstar(Integer extendedId) {
         ExtendedId = extendedId;
         super.Id = extendedId;
     }
    

    }

You can also extend multiple nested classes in 1 static class.

  1. I’d like to reproduce this error so it’s part of our test suite before resolving the issue, what’s the best way to reproduce it? Can you show an example Service we can test this on?

I’ll try to get to 2 and 3 a little later.

But as for #1, I ran into a few things… So I’m posting some images of what I did to fix these.
When I was trying to use the request filters, I ran into errors saying that the request can’t be altered after it’s already connected (i.e.: was using the request filter to inject basic auth headers).

So this was the fix:

In a similar way, ran into an issue where the Request filters were also on the response side of things. So those were causing problems, so I switched those out to Response filters… See image below:

Yeah I noticed it should’ve called the Response Filters which I’ve changed yesterday in this commit and added tests.

If you can provide a repro of the StackTrace issue we can provide a fix and redeploy the Java clients.

Cool. I also had to modify the code here:

If you do a POST with a request body and try to add a basic auth header or modify the request, the GlobalRequest and FilterRequest blows up, because the req.getOutpuStream line already connected on line 165.

I just moved lines 171 through 177 above 163

I’ve made the suggested changes to the client library.

Could you test the aar packages here with the changes and let me know this works for you?

This SO answer shows how you can reference local libs.