Skip to content
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

Is paranamer supposed to work on Android ? #31

Open
om26er opened this issue Dec 22, 2017 · 1 comment
Open

Is paranamer supposed to work on Android ? #31

om26er opened this issue Dec 22, 2017 · 1 comment

Comments

@om26er
Copy link

om26er commented Dec 22, 2017

I tried paranamer on Android but it does not work. Is this library supposed to work on Android ? below is my code.

Paranamer paranamer = new DefaultParanamer();
for (Method method: MainActivity.class.getDeclaredMethods()) {
    String[] names = paranamer.lookupParameterNames(method, false);
    // This is always zero.
    System.out.println(names.length);
    for (String name: names) {
        System.out.println(name);
    }
}
@paul-hammant
Copy link
Owner

Java sources compiled directly to Dalvik bytecode will not work with BytecodeReadingParanamer specifically, no. That's because ASM (which it relies on at runtime) does not work with Dalvik bytecode.

The original mode of operation used generated tables of data in the same class files - https://github.com/paul-hammant/paranamer#feeding-defaultparanamer. That's standard Java's bytecode format again. If your app compiles to standard Java bytecode the and that is then translated into Dalvik bytecode then those sections will be preserved. That's the way the Android toolchain used to work. See https://www.guardsquare.com/en/blog/the_upcoming_jack_and_jill_compilers_in_android. More recently the Android compiler has change to support Java8 syntax and skips the standard Java intermediate, so we're back to no again. No matter Java8 has it's own APIs that negate the need for Paranamer completely so you should use them.

Some of the other specialized Paranamer implementations should work just fine on android (via reflection, although that comes with a speed cost on Android).

Pull Requests accepted if you think enhancements could be made.

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

No branches or pull requests

2 participants