https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

petersommerhoff

04/19/2018, 9:14 AM
How can I pass a compiler flag like -Dkotlinx.coroutines.debug when running an app in Android Studio?
c

christophsturm

04/19/2018, 9:20 AM
in idea you can select “edit configuration” in the run configurations selector in the toolbar next to the play button. or in the Run pull down menu there is also a Edit Configuration option
p

petersommerhoff

04/19/2018, 9:31 AM
i know but there's no such option in Android Studio unfortunately...
c

christophsturm

04/19/2018, 9:37 AM
I just opened Android Studio 3.0.1 and it has both options
p

petersommerhoff

04/19/2018, 9:38 AM
Should have been more precise, I mean there's no "JVM flags" option for an "Android App" config
c

christophsturm

04/19/2018, 9:40 AM
ah ok. that’s probably because its not using the jvm
p

petersommerhoff

04/19/2018, 9:40 AM
Yep, question is if there's any way to pass the -Dkotlinx.coroutines.debug flag (or any other)
that’s what you’re after
You can declare extra data in your Intent and pick it up in your launch Activity
or any activity really
if you see, there are intent arguments specced here: https://developer.android.com/studio/command-line/adb.html#IntentSpec
p

petersommerhoff

04/19/2018, 10:04 AM
Hmm not sure how to solve it with this, I don't really want to process an extra in the MainActivity, the idea is that Kotlin automatically adds coroutine ids to thread names as described here: https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md#debugging-coroutines-and-threads
d

Dmytro Danylyk

04/19/2018, 10:19 AM
@petersommerhoff if you want to enable debug on android, create
Application
class
And inside
onCreate
add this:
System.setProperty("kotlinx.coroutines.debug", if (BuildConfig.DEBUG) "on" else "off")
In next release, there will be public constants, to get rid of magic strings
on
, `off`…
👍 4
p

petersommerhoff

04/19/2018, 10:21 AM
Thanks, I'll try that!
That works @Dmytro Danylyk, thanks so much, also thanks to Christoph and Paco for helping!
👍 1
Quick follow-up: does anyone know what the difference is between -ea flag and -Dkotlinx.coroutines.debug?
Oh, that's "enable assertions", works for coroutines in IntelliJ as well
20 Views