Hey,

The key information is found at

http://www.osgi.org/blog/2007/11/android-and-osgi.html

namely, the classes.dex must be inside a jar file. I jar'd up a
classes.dex file and fed it into the code for the osgi class loader
(see http://blog.luminis.nl/luminis/entry/osgi_on_google_android_using
) and all was happy.

hope this helps,

k

On Mar 6, 4:25 am, "Carl H." <[EMAIL PROTECTED]> wrote:
> Have you had any further luck on this?
>
> ./Carlhttp://androforge.net
>
> On Mar 3, 3:16 am, MoggoDude <[EMAIL PROTECTED]> wrote:
>
> > Gidday,
> >       I am very interested in being able to dynamically load classes
> > from within
> >       my Google Android Application at runtime. I have done some
> > research on
> >       this topic and some trial and error coding. From my
> > understanding so far, it appears
> >       that you have to load classess through a dex 
> > filehttp://groups.google.com/group/android-beginners/browse_thread/thread...
>
> >       I have utilised the code from that from that approach as
> > follows:
>
> > try {
>
> >      File file = new File("/data/data/com.mystuff.android/
> > classes.dex");
>
> >       Class dexFileClass =  Class.forName("android.dalvik.DexFile");
> >       Constructor dexFileClassConstructor =
> > dexFileClass.getConstructor(
> >          new Class[] { java.io.File.class  });
>
> >       ObjectdexFile= dexFileClassConstructor.newInstance(new
> > Object[] { file });
>
> >       Method dexFileClassLoadClass =
> > dexFileClass.getMethod("loadClass",
> >         new Class[] { String.class, ClassLoader.class });
>
> >       dexFileClassLoadClass.invoke(dexFile, new Object[]
> > { "com.somepackage.AClass", this.getClassLoader() });
>
> > } catch(Exception ex) {
> > }
>
> > The result of which is an Exception with a message: Unable to open DEX
> > file, which occurs on the line
> > ObjectdexFile= dexFileClassConstructor.newInstance(new Object[]
> > { file });.
>
> > I have also tried instantiatingtheDexFiledirectly, as follows
>
> > try {
>
> >       File file = new File("/data/data/com.mystuff.android/
> > classes.dex");
> >      DexFiledexFile= newDexFile(file);
>
> > } catch(Exception ex) {
> > }
>
> > And still get the same error: Unable to open DEX file.
>
> > I have also tried another approach useing a URLClassLoader, where I
> > place my class files in a directory:
> > /data/data/com.mystuff.android
>
> > try {
> >        URL url = new URL("file:/data/data/com.mystuff.android/");
>
> >        URLClassLoader ucl = URLClassLoader.newInstance(new URL[]
> > { url }, this.getClassLoader());
> >        Class clazz = ucl.loadClass("bsh.Interpreter");
>
> > } catch(Exception ex) {
> > }
>
> > This gives an Error of Unsupported Operation Exception.
>
> > Am I making the correct combination of method calls, or is there some
> > other way of Dynamically Loading Classes. Any help
> > on this issue would be greatly appreciated, as my application does
> > need to load classes dynamically.
>
> > Regards,
> >        MoggoDude
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to