How can I pass a compiler flag like -Dkotlinx.coro...
# coroutines
p
How can I pass a compiler flag like -Dkotlinx.coroutines.debug when running an app in Android Studio?
c
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
i know but there's no such option in Android Studio unfortunately...
c
I just opened Android Studio 3.0.1 and it has both options
p
Should have been more precise, I mean there's no "JVM flags" option for an "Android App" config
c
ah ok. that’s probably because its not using the jvm
p
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
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
@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
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