michkaravolos / android-scripting

Automatically exported from code.google.com/p/android-scripting
0 stars 0 forks source link

Importing java class files within beanshell #423

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What device(s) are you experiencing the problem on?
HTC Legend

What firmware version are you running on the device?
2.1-update1

What steps will reproduce the problem?
1. I put 2 java6 classes (MyStaticClass.class and MyDynamicClass.class) in 
/sdcard/myjavaclasses

2. MyStaticClass.doIt() prints "do it"
MyDynamicClass.doIt() returns "do it" String

3. I executed the useMyClasses.bsh script, this is the code:

addClassPath( "/sdcard/myjavaclasses" );

try {
    MyStaticClass.doIt();
} catch( e ){
    print( e + "\n" );
}

try {
    MyDynamicClass p = new MyDynamicClass();
    print( p.doIt() );
} catch( e ){
    print( e + "\n" );
}

What is the expected output? What do you see instead?
I have the following error. Evaluation error: Sourced file: [...] unknown 
error: can't load this type of class file : at line 3 : in file [...]

What version of the product are you using? On what operating system?
sl4a_r2.apk beanshell_for_android_r1.apk on Android 2.1

Please provide any additional information below.

Original issue reported on code.google.com by andrea.i...@gmail.com on 9 Sep 2010 at 3:04

GoogleCodeExporter commented 9 years ago
You probably need to convert your files to dex format first.

See: 
http://davanum.wordpress.com/2007/12/04/command-line-java-on-dalvikvm/
for examples on how to use dx and aapt.

Original comment by rjmatthews62 on 19 Jan 2011 at 1:05

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This is how it works:

1. On the PC, dexify your standard Java jar file with the dx tool from the 
Android SDK
2. Copy the dexified jar to your Android device
3. Use following code to use the Java classes:

//***********
//bsh
import dalvik.system.PathClassLoader;
ClassLoader cl = new 
PathClassLoader("/mnt/sdcard/sl4a/scripts/javalibs/NanoXML-Lite-2-2-3ta1-3_droid
.jar",ClassLoader.getSystemClassLoader ());
this.interpreter.setClassLoader(cl);
nanoxml.XMLElement x = new nanoxml.XMLElement();
print ("Class instance created");
//************ 

Original comment by tom.ar...@gmail.com on 13 Apr 2011 at 6:32