Skip to content

Make debug module Android-compatible #948

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

Closed
LouisCAD opened this issue Jan 21, 2019 · 16 comments
Closed

Make debug module Android-compatible #948

LouisCAD opened this issue Jan 21, 2019 · 16 comments

Comments

@LouisCAD
Copy link
Contributor

LouisCAD commented Jan 21, 2019

Here's a permalink to the target doc: https://github.com/Kotlin/kotlinx.coroutines/blob/8f1c728bade0416037793900355de31e064a1dae/core/kotlinx-coroutines-debug/README.md

UPDATE: Note that the most recent version of documentation mentions Android incompatibility. See: https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-debug/README.md#debug-agent-and-android

Leaving this issue open as a change request for future support of Android on-device debugging.

@Mygod
Copy link

Mygod commented Jan 31, 2019

So how are we supposed to debug deadlocks on Android?

@elizarov
Copy link
Contributor

You can write unit / integration tests and debug your logic with them.

@Mygod
Copy link

Mygod commented Apr 14, 2019

So I need to write (AND keep) two copies of my logic just to debug deadlocks?

@elizarov
Copy link
Contributor

We don't have a good answer yet.

@Mygod
Copy link

Mygod commented Apr 20, 2019

Any reasons we need to use Ljava/lang/management/ManagementFactory? I don't see android-gradle-aspectj updating any time soon.

@elizarov
Copy link
Contributor

On JVM we can inject debugger into running code. This is done via ManagementFactory. On Android this is not possible. We need to weave the corresponding debug code into the kotlin-stdlib.jar before it gets dexed and put onto device. Weaving itself is quite easy (we just need to replace a few methods), but maintaining the corresponding gradle plugin is not -- we don't have time at the moment. If somebody can contribute Android-compatible gradle plugin that we can use to weave our debugging aspect that would be great.

@elizarov elizarov changed the title Specify debug module is not Android compatible Make debug module Android-compatible Apr 21, 2019
@Mygod
Copy link

Mygod commented Apr 22, 2019

Can't kotlin-stdlib have hooks or something to make this compatible?

@elizarov
Copy link
Contributor

elizarov commented Apr 22, 2019

kotlin-stdlib has special debug hook, but it is static -- to use this hook you must rewire a specifically designed class inside kotlin-stdlib. You don't even need AOP framework for that. You can simply replace the corresponding class. On JVM we can do it at run-time. On Android it has to be a part of dexing toolchain.

The trick is that we need to maintain Gradle plugin that does this reliably and is tested and integrated with Android toolchain. And that is quite painful.

@Mygod
Copy link

Mygod commented Apr 22, 2019

What I was thinking is that maybe we can update kotlin-stdlib and relax the restrictions on the debug hook so that we can do this without using ManagementFactory nor gradle plugin dexing. I am not sure how exactly things go under the hood but I think this should work.

@elizarov
Copy link
Contributor

elizarov commented Apr 22, 2019

The is no way to make it work in a reliable and modular way -- we cannot use ServiceLoader in kotlin-stdlib, we cannot hard-code kotlinx.coroutines class names there either, and we cannot make this hook dynamic -- it has to be static for performance reasons. All we need it some simple AOP Gradle plugin that is compatible with Android toolchain. It does not even has to as complex as AspectJ.

@Mygod
Copy link

Mygod commented Apr 22, 2019

For performance issues, can we do something like build variants that disables the dynamic hook for release builds?

@elizarov
Copy link
Contributor

That is exactly why we need Gradle plugin on Android. We need it to hook a special "debug-enabled" (appropriately patched) version of kotlin-stdlib when building a debug version of application.

@LouisCAD
Copy link
Contributor Author

LouisCAD commented Sep 6, 2019

Is this planned anytime soon?
I have a channel closed exception crashing my app that I struggle a lot to debug. This would be very helpful.

@eric-labelle
Copy link

UPDATE: Note that the most recent version of documentation mentions Android incompatibility. See: https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-debug/README.md#debug-agent-and-android

It is also mentioned that it will be possible when AGP 3.3 will be supported (they actually stated it support up to Actual version supporting of AGP 3.6.+

Nevertheless, it will be possible to support debug agent on Android as soon as GradleAspectJ-Android will support android-gradle 3.3

So what is the current status on this?

@qwwdfsad
Copy link
Member

We decided not to implement this request ourselves.
Google has work-in-progress and is planning to provide coroutines debugging support in one of the upcoming versions of Android Studio

@LikeTheSalad
Copy link

Do you guys think that instead of AspectJ you could use Byte Buddy on Android with https://github.com/LikeTheSalad/android-buddy instead?

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

No branches or pull requests

6 participants