Services folder not included in META-INF for kotlin coroutine MainDispatcherFactory
Created by: rifqimfahmi
When I try to install apk that has coroutines-android lib as dependency, It cause error when you pass the Dispatchers.Main
in one of coroutine builder like Globalscope.launch(coroutineContext)
. On the other hand, installing the app with Gradle has no problem at all. After comparing the apk build by Buck and Gradle, buck didn't include the services
folder that contains kotlinx.coroutines.internal.MainDispatcherFactory
and kotlinx.coroutines.CoroutineExceptionHandler
files. I am using OkBuck, but I try using the latest version of buck the problem still occurs. I provide the example that you can try in the following repos:
- You can build with OkBuck and Gradle (from Android Studio): https://github.com/rifqimfahmi/coroutines-sample
- Only with Buck: https://github.com/rifqimfahmi/basic-android-app-with-buck-build
The error log is as follow:
2019-06-28 23:55:40.406 971-971/? E/Zygote: isWhitelistProcess - Process is Whitelisted
2019-06-28 23:55:40.407 971-971/? E/Zygote: accessInfo : 1
2019-06-28 23:55:40.503 971-983/? E/oroutinessampl: Failed to send DDMS packet REAQ to debugger (-1 of 20): Broken pipe
2019-06-28 23:55:45.574 971-971/tokopedia.coroutinessample E/AndroidRuntime: FATAL EXCEPTION: main
Process: tokopedia.coroutinessample, PID: 971
java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android'
at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.missing(MainDispatchers.kt:73)
at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.isDispatchNeeded(MainDispatchers.kt:54)
at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:373)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:25)
at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:109)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:160)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:54)
at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
at tokopedia.coroutinessample.MainActivity2.execute(MainActivity2.kt:36)
at tokopedia.coroutinessample.MainActivity2$onCreate$1.onClick(MainActivity2.kt:26)
at android.view.View.performClick(View.java:7352)
at android.widget.TextView.performClick(TextView.java:14177)
at android.view.View.performClickInternal(View.java:7318)
at android.view.View.access$3200(View.java:846)
at android.view.View$PerformClick.run(View.java:27801)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7045)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
Dirty workaround using apk_genrule() uber/okbuck#839