question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Backdoor couldn't find methods on target : application / activity if the code written in Kotlin

See original GitHub issue

So I have 2 android application written in Kotlin and Java …

I tried to call public method on my Java Android Application both inside activity and application. It worked!

ImmutableMap<String, Object> scriptArgs = ImmutableMap.of(
                "target", "application",
                "methods", Arrays.asList(ImmutableMap.of(
                        "name", "createToast",
                        "args", Arrays.asList(ImmutableMap.of(
                                "value", "Hello",
                                "type", "String"
                        ))
                ))
        );

androidDriver.executeScript("mobile: backdoor", scriptArgs);

But when i want to try it on Kotlin Android Application, somehow espresso couldn’t find any public methods inside activity nor application. So I tried to use companion object and moved the function inside and marked it with @JvmStatic annotation.

ImmutableMap<String, Object> scriptArgs = ImmutableMap.of(
                "target", "application",
                "methods", Arrays.asList(ImmutableMap.of(
                        "name", "com.xxx.xxxxAplication.Companion.createToast",
                        "args", Arrays.asList(ImmutableMap.of(
                                "value", "Hello",
                                "type", "String"
                        ))
                ))
        );

androidDriver.executeScript("mobile: backdoor", scriptArgs);

Is there anything that i can do to get the list of methods inside Java Code / Kotlin Code with backdoor ? Just for debugging purpose.

And is there any solution for this ?

Thank you !

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
KazuCocoacommented, Jul 18, 2019

Thanks! I took a glance at the code and found setAccessible(true);. ah… final modifier affected. Will add the kotlin case in doc.

1reaction
aldochristiaancommented, Jul 18, 2019

Hey guys @dpgraham @rajdeepv @KazuCocoa … I found out that we have to put open in front of the methods 😁

open fun methodName() will be decompiled into public void methodName()

Case closed! Thanks @KazuCocoa for pointing out kotlin bytecode … Maybe we have to add documentation about this on appium mobile native command especially for kotlin app 🥇

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not find method kapt() for arguments - Stack Overflow
In my case,I was missing apply plugin: 'kotlin-kapt'. Hope it helps someone as blind as me.
Read more >
Crashes - Android Developers
An app that is written using Java or Kotlin crashes if it throws an unhandled exception, represented by the Throwable class.
Read more >
0xdf hacks stuff | CTF solutions, malware analysis, home lab ...
I'll take advantage of two mistakes in the coding to write a binary that escapes the jail and reads the database for the...
Read more >
Black Hat USA 2022 | Trainings Schedule
Start your journey into information security with a hands-on course which will expose you to the technical fundamentals of penetration testing and security ......
Read more >
Kotlin Android Extensions: Say goodbye to findViewById (KAD ...
Let's see the code it generates if we move it to a fragment. I'm creating this simple fragment, that uses the same XML...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found