Build an API with Kotlin on Google Cloud Platform | raywenderlich.com

In this tutorial you will learn how to build a server side API using Kotlin and Ktor that you can host on Google Cloud Platform and use with your Android app.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4656683-build-an-api-with-kotlin-on-google-cloud-platform

When I try to open the Ray-Conf-Starter project in IntelliJ/Android Studio and run ./gradlew appengineRun, I get an error -
Unresolved reference - kotlinx
What should I do?

Looks like @Serializable was already added to the AgendaEntry class in the starter project. All I needed to do was to add the gradle plugin and dependencies. You should move the block to add the gradle dependencies at the top or include them in the starter project

I’m also trying to execute appengineRun using the finished project and I’m getting an exception. I can’t clearly see what’s causing the exception . Thanks

> Task :server:appengineRun FAILED
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.appengine.tools.development.StreamHandlerFactory (file:/Users/A076766/Library/Application%20Support/google-cloud-tools-java/managed-cloud-sdk/LATEST/google-cloud-sdk/platform/google_appengine/google/appengine/tools/java/lib/impl/appengine-local-runtime.jar) to method java.net.URL.getURLStreamHandler(java.lang.String)
WARNING: Please consider reporting this to the maintainers of com.google.appengine.tools.development.StreamHandlerFactory
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
java.lang.NullPointerException
        at java.base/java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011)
        at java.base/java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006)
        at java.base/java.util.Properties.put(Properties.java:1316)
        at java.base/java.util.Collections$CheckedMap.put(Collections.java:3636)
        at com.google.appengine.tools.development.SharedMain.setTimeZone(SharedMain.java:219)
        at com.google.appengine.tools.development.SharedMain.postServerActions(SharedMain.java:188)
        at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:398)
        at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:45)
        at com.google.appengine.tools.development.DevAppServerMain.run(DevAppServerMain.java:257)
        at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:248)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':server:appengineRun'.
> com.google.cloud.tools.appengine.AppEngineException: com.google.cloud.tools.appengine.operations.cloudsdk.process.ProcessHandlerException: com.google.cloud.tools.appengine.AppEngineException: Non zero exit: 1

Hi Rmatze,

What you mention can sometimes occur when using a local Java SDK that is higher than the one used in the application.

Here is an example of a similar situation:

Java 9 introduced restrictions when accessing resources across packages.

Such restriction means that if an SDK is using setAccessible for a class on a separate package, then you get the error that you’ve reported.

Google makes use of reflexion in their AppEngine SDK, and therefore, we are forced to use Java 8 for now. I imagine that they’ll update bit in the future.

If you are in this situation, you have to downgrade the local Java SDK to be 8. Such downgrade may not be desirable if you have other projects that rely on newer versions of Java. On the other hand, if you are an Android developer, there is only support for Java 8, so it’s safe to downgrade. Maybe one day we can upgrade :]

If you want to switch versions quickly or to have an easier downgrade, sdkman is a great tool

Let me know if it works for you.

Hi,

I’ll give it a whirl. Thanks for the quick response!

Update: Using sdkman to downgrade my java version worked as you suggested. Thanks again!

1 Like