Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Order Breaks Other Objects Before Client() (Kotlin) #17

Open
Zakkumaru opened this issue Feb 26, 2021 · 0 comments
Open

Import Order Breaks Other Objects Before Client() (Kotlin) #17

Zakkumaru opened this issue Feb 26, 2021 · 0 comments

Comments

@Zakkumaru
Copy link
Contributor

Not sure how to put this, but I just spent the better part of the past few days hitting my head on the wall to figure this out (new to Kotlin), so maybe this will be beneficial to others, maybe it's an obscure bug, Idk.

Here's the signup sample code, verbatim, from the docs:

import com.etebase.client.*
import okhttp3.OkHttpClient;

val httpClient: OkHttpClient = Builder().build()

val user = User("username", "[email protected]")
// serverUrl can obtained from the dashboard (or null for default)
val client = Client.create(httpClient, serverUrl)
val etebase = Account.signup(client, user, "password")

However, there is a project that this is for which uses strict styleCheck asserts that fail if importing with asterisks. Thus, my import looks more like this:

import com.etebase.client.Account
import com.etebase.client.Client
import com.etebase.client.User
import com.etebase.client.Utils.randomBytes
import com.etebase.client.Utils.toBase64
import okhttp3.OkHttpClient
...

This caused the User() method to fail, not knowing what to do with the abstract code that Flapigen generated (User.java):

E/i.[].debu: No implementation found for long com.etebase.client.User.init(java.lang.String, java.lang.String) (tried Java_com_etebase_client_User_init and Java_com_etebase_client_User_init__Ljava_lang_String_2Ljava_lang_String_2)
E/ACRA: ACRA caught a UnsatisfiedLinkError for []
    java.lang.UnsatisfiedLinkError: No implementation found for long com.etebase.client.User.init(java.lang.String, java.lang.String) (tried Java_com_etebase_client_User_init and Java_com_etebase_client_User_init__Ljava_lang_String_2Ljava_lang_String_2)

This drove me absolutely nuts for a long time, even to the point of skipping class to try to knock it out. Several hours later, after so many reinstalls and searching the web without rest, I finally decided to try putting the User() call under the Client() call. It worked but then I got another error, which prompted me to try also putting toBase64() under Client(), and then I suddenly (finally) had my first successful account registration. Why this works, don't ask me. I assume maybe it's common sense to Kotlin experts, but I nearly gave up on the project when I hit this wall.

Also, this:

...
        val httpClient: OkHttpClient = Builder().build()
...

Gets some complaints because there are apparently hundreds of Builder() classes. Meaning, you have to do one of two things:

import okhttp3.OkHttpClient
import okhttp3.OkHttpClient.Builder

... or:

...
        val httpClient: OkHttpClient = okhttp3.OkHttpClient.Builder().build()
...

... which looks a bit tacky and many stylists would complain about in an official repo.

Anyway, I was just laying down this information because I was asked to, and maybe someone will find it useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant