Is there a work around for the Android error "Unable to resolve virtual method java/beans/PropertyDescriptor"?
Asked Answered
S

2

9

I am trying to use a third party jar file within an Android application. I have been able to use some of the classes in the jar file just fine. However, one of the classes references some Java classes that don't appear to be supported by the dalvik vm. These are some of the errors I am seeing in LogCat:

Unable to find class referenced in signature java/beans/PropertyDescriptor.
Unable to resolve virtual method java/beans/PropertyDescriptor.getName().
Unable to resolve virtual method java/beans/PropertyDescriptor.getReadMethod().
Unable to resolve static method java/beans/Introspector.getBeanInfo().
Unable to resolve exception class java/beans/IntrospectionException.

It appears that Java classes related to introspection and reflection are not supported by dalvik. I would like to find out two things. Is that a plan to support this in dalvik in the near future? Secondly, does anyone have a suggestion for a work around that would get around this problem?

Scholl answered 30/3, 2011 at 15:12 Comment(0)
M
9

It appears that Java classes related to introspection and reflection are not supported by dalvik.

Not on a blanket basis, AFAIK. One objective of the core Android team is to keep the firmware small, to reduce the cost of devices. One side-effect of this is to only include classes from java.* and javax.* that they feel are essential. Originally, none of java.beans.* existed in Android; now, a few classes and interfaces are available, but not the whole package.

Is that a plan to support this in dalvik in the near future?

You will know when the rest of us know, which is to say, only if it shows up in a release.

Secondly, does anyone have a suggestion for a work around that would get around this problem?

If the third-party JAR is an open source project:

  1. Grab the necessary java.beans classes from Apache Harmony and put them in your project
  2. Refactor them into a separate package (e.g., bondy.beans), since Android will not like it much if you try loading java.beans classes into your project
  3. Modify the third-party JAR to use your refactored edition of the classes

It is possible that jarjar can do something about this as well -- I have not yet used the tool and do not know the extent of its capabilities.

Makhachkala answered 30/3, 2011 at 15:31 Comment(4)
This advice is perfect. Further jarjar technical details are described here: code.google.com/p/dalvik/wiki/JavaxPackagesOneself
Modifying 3th party jars just to please android is very painful (you basically have to rebuild them from source). It's a pity that Android doesn't support something basic as BeanInfo.Haruspex
"since Android will not like it much if you try loading java.beans classes into your project" does it mean it is not allowed? or we still can do that?Railroader
@GMsoF: "does it mean it is not allowed?" -- AFAIK, yes, that is still the case.Makhachkala
D
1

Apache harmony is retired for a long time now. I am using openbeans. And it solves all the problem for me.

Diffident answered 26/6, 2013 at 11:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.