3

My project has two projects: main project and library project.

The main project dependency library project.

Now I want to use kotlin both of them. I had added my common rx extension code into library project:

fun String.rxRequest(@NotNull builder: (Request.Builder) -> Unit): Observable<Response> = Observable.create<Response> {
  var mBuilder: Request.Builder = Request.Builder().url(this)
  builder.invoke(mBuilder);
  it.onNext(HttpClient.create().newCall(mBuilder.build()).execute())
  it.onCompleted()
}.subscribeOn(Schedulers.from(THREAD_POOL_NET));

And then I call this function in my main project:

"http://www.xxx.xxx".rxRequest {
        val requestBody = FormEncodingBuilder().add("code", code).build()
        it.post(requestBody)
                .header("XRDid", appInfo.deviceId)
    }

It build failed:

LoginPresenter.kt: Unresolved reference: rxRequest

library project build success, kotlin .class generated in build folder.

But main project build failed, have no kotlin .class file in build folder.

WangJie
  • 526
  • 3
  • 7

1 Answers1

1

I had the same issue, I fix it adding all the kotlin dependencies in both modules/projects and of course make sure to add also the kotlin plugin and setting the kotlin folder to be included in the javaSrc.

Juan Saravia
  • 7,661
  • 6
  • 29
  • 41