Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
1.5 release - DexClassLoader issue
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Eborix13  
View profile  
 More options Apr 16 2009, 9:24 am
From: Eborix13 <ebori...@yahoo.com>
Date: Thu, 16 Apr 2009 06:24:05 -0700 (PDT)
Local: Thurs, Apr 16 2009 9:24 am
Subject: 1.5 release - DexClassLoader issue
Hi,

   Seeing that the new 1.5 pre-release has support for loading classes
dynamically I immediately tried to see if it works. I used the
DexClassLoader(String dexPath, String dexOutputDir, String libPath,
ClassLoader parent) constructor. But I soon found out that it works
only partially.

   What I am trying to do is dynamically load a class from a given jar
file which contains a classes.dex file. If I try to use the current
class loader (this.getClass().getClassLoader()) as the "parent"
parameter I get a "java.lang.IllegalAccessError: cross-loader access
from pre-verified class" error. But if I use the SystemClassLoader as
the "parent" parameter everything works out nicely. But using the
SystemClassLoader is a problem for me because the class that is loaded
using the SystemClassLoader is a subclass of a class which was
previously loaded by the current class loader. Casting the derived
class to the base class generates a ClassCastException because the
base class was not loaded with the same class loader as the derived
class.

  Is there a way to solve this problem? Am I doing something wrong? Is
there a way to dynamically load a class using the current class loader
instead of the system class loader? Is this problem caused by the fact
that the 1.5 release is incomplete yet, so perhaps this problem is
going to be solved in the final release?

Thank you...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fadden  
View profile  
 More options Apr 16 2009, 5:31 pm
From: fadden <fad...@android.com>
Date: Thu, 16 Apr 2009 14:31:45 -0700 (PDT)
Local: Thurs, Apr 16 2009 5:31 pm
Subject: Re: 1.5 release - DexClassLoader issue
Most of what you're describing falls into the category of, "that's how
class loaders work in the Java programming environment".  If you
create a class loader, and load a class called MyClass from it, you
can't trivially refer to MyClass because the current class' loader
can't resolve it.  You have to use reflection to get at it.  Class
cast operations don't always do what you want.

You can see some twisted examples in dalvik/tests/068-classloader.

The cross-loader complaints arise when you do something like this:

  mystuff.dex has "MyClass" and "MyOtherClass"
  newstuff.dex has "NewClass" and "MyOtherClass"
  FancyClassLoader knows about mystuff.dex and newstuff.dex
  FancyClassLoader uses MyOtherClass from newstuff.dex

When mystuff.dex was run through "dexopt", it was verified and
optimized with the assumption that references from MyClass to
MyOtherClass would refer to the implementation in the same DEX file.
However, FancyClassLoader chose to load a different implementation of
MyOtherClass.  This can cause Issues, so it's not allowed.  (This
could work in a more traditional VM, where the verification and
optimization aren't performed ahead of time, but might not do what you
expect.)

If you want specifics about the classes involved, there's an intensely
cryptic message in the log file ("Class resolved by unexpected DEX")
that has some info.

You can avoid this situation by only having one implementation of a
given class.  And by not loading the same DEX file into multiple class
loaders.

BTW, just so we don't confuse each other with terminology:

(1) bootstrap class loader.  Path set by BOOTCLASSPATH.  Includes
core / ext / framework / android.policy / services.  Implemented
directly by the VM.

(2) system class loader, a/k/a application class loader.  Path set by
CLASSPATH.  I don't think this is used by the Android framework.

(3) user-defined class loader.  The Android app framework
implementation uses the ApplicationLoaders class to manage a
dalvik.system.PathClassLoader per app.

On Apr 16, 6:24 am, Eborix13 <ebori...@yahoo.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eborix13  
View profile  
 More options Apr 17 2009, 3:08 am
From: Eborix13 <ebori...@yahoo.com>
Date: Fri, 17 Apr 2009 00:08:00 -0700 (PDT)
Subject: Re: 1.5 release - DexClassLoader issue
Hi Fadden,

  My question was not: why can't I use 2 classes loaded with different
class loaders. My question has to do with the way Android implements
the dynamical class loading thing. It won't let you load a class using
this.getClass().getClassLoader() as the "parent" parameter in the
DexClassLoader(String dexPath, String dexOutputDir, String libPath,
ClassLoader parent) constructor. Instead you have to use
MyClass.getSystemClassLoader() as the "parent" parameter. Why is that?
Why can't I load the class using the classloader which loaded all my
classes up until then?

On Apr 17, 12:31 am, fadden <fad...@android.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fadden  
View profile  
 More options Apr 17 2009, 4:03 pm
From: fadden <fad...@android.com>
Date: Fri, 17 Apr 2009 13:03:19 -0700 (PDT)
Local: Fri, Apr 17 2009 4:03 pm
Subject: Re: 1.5 release - DexClassLoader issue
On Apr 17, 12:08 am, Eborix13 <ebori...@yahoo.com> wrote:

>   My question was not: why can't I use 2 classes loaded with different
> class loaders. My question has to do with the way Android implements
> the dynamical class loading thing. It won't let you load a class using
> this.getClass().getClassLoader() as the "parent" parameter in the
> DexClassLoader(String dexPath, String dexOutputDir, String libPath,
> ClassLoader parent) constructor. Instead you have to use
> MyClass.getSystemClassLoader() as the "parent" parameter. Why is that?

You can use this' class loader as the parent.  None of the problems
you described appeared to be related to problems of hierarchy, except
in so far as one combination resulted in a particular class being
resolved from an unexpected place.  It's possible I'm not fully
understanding your situation though.

> Why can't I load the class using the classloader which loaded all my
> classes up until then?

PathClassLoader, which is the underlying implementation for the system/
application loader and the user-defined loader that the app framework
uses, is constructed with an immutable path.  Additions and removals
are not allowed.  It doesn't *have* to work this way, but things are
more straightforward when it does.

I'm not sure how this question relates to your earlier question.  If
you create a class loader for Blah.dex, and want to load a class
called Splat from it, Blah.dex's class loader gets to decide how Splat
is found.  Blah's parent doesn't matter until Splat starts referring
to classes that aren't defined in Blah.dex.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lindley  
View profile  
 More options Oct 10 2012, 12:53 pm
From: Lindley <lindl...@gmail.com>
Date: Wed, 10 Oct 2012 09:53:21 -0700 (PDT)
Local: Wed, Oct 10 2012 12:53 pm
Subject: Re: 1.5 release - DexClassLoader issue

Sorry for the gravedig, but I have a related question. Let's say we have
the aforementioned situation:

  mystuff.dex has "MyClass" and "MyOtherClass"
  newstuff.dex has "NewClass" and "MyOtherClass"
  FancyClassLoader knows about mystuff.dex and newstuff.dex
  FancyClassLoader uses MyOtherClass from newstuff.dex

Let's say I want to assume that the "MyOtherClass" in both dex files is
identical. Is there any way to tell the DexClassLoader (or a subclass of
it) to always use the existing one the VM already knows about, and
explicitly ignore the one in newstuff.dex, and thereby avoid the
"unexpected DEX" error?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »