3

I'm trying to convert a normal Java application library for use on Android. The library dates from Java 1.1 and has been maintained, improved, etc, all this time, and is in service on other platforms so it's unlikely that the source code is involved.

Normally, due to the details of deployment, this library is not encapsulated in a jar, but is merely kept in a tree where CLASSPATH does its magic. However, for purposes of putting it on Android, a jar was created. That went fine - no warnings or errors.

As there will be some new development - and therefore debugging - the step of processing through ProGuard was skipped - the time will come for that later.

The error comes in the next step, running dx to convert it for use with Android. The processing proceeds without error until the fatal one described here. (There's one minor warning.)

The error splash:

UNEXPECTED TOP-LEVEL ERROR:
java.lang.ExceptionInInitializerError
        at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
        at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:136)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:113)
        at com.android.dx.command.dexer.Main.processOne(Main.java:247)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:183)
        at com.android.dx.command.dexer.Main.run(Main.java:139)
        at com.android.dx.command.dexer.Main.main(Main.java:120)
        at com.android.dx.command.Main.main(Main.java:89)
        at com.spartacusrex.spartacuside.external.dx.main(dx.java:14)
        at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: native_get
        at android.os.SystemProperties.native_get(Native Method)
        at android.os.SystemProperties.get(SystemProperties.java:47)
        at com.htc.profileflag.ProfileConfig.<clinit>(ProfileConfig.java:168)
        ... 12 more

The development environment is Terminal-IDE. (Google code site here.)

I'm running Terminal-IDE v 2.02 - the very latest. My Android versions are:

Android 4.0.3
Software version 2.14.531.3 71ORD
(the rest aren't likely pertinent, but more on request)

EDIT - New Information

With the idea that there was something missing from the Terminal-IDE environment, I set about trying to run dx on a Windows 7 box running Eclipse. Eclipse is running DX somehow as its converting over the code from a plain .jar into something that actually runs as a part of an Android application. However, I was not able to get dx to run from the command line - it complains it can't find the source input file! (any clues?)

Meanwhile, at someones' suggestion, I set about doing the whole build in the Terminal-IDE environment. That meant a little hacking to simplify the scenario, and also it kept failing on not finding java.RMI, so I commented those sections out - I presume there's an Android-Ready RMI library I can just point to? ...Continuing on, everything worked without error until I got to DX again and had a VERY SIMILAR error as reported above:

UNEXPECTED TOP-LEVEL ERROR:
java.lang.ExceptionInInitializerError
        at com.android.dx.util.FileUtils.readFile(FileUtils.java:72)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:139)
        at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:196)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:127)
        at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:196)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:127)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:113)
        at com.android.dx.command.dexer.Main.processOne(Main.java:247)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:183)
        at com.android.dx.command.dexer.Main.run(Main.java:139)
        at com.android.dx.command.dexer.Main.main(Main.java:120)
        at com.android.dx.command.Main.main(Main.java:89)
        at com.spartacusrex.spartacuside.external.dx.main(dx.java:14)
        at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: native_get
        at android.os.SystemProperties.native_get(Native Method)
        at android.os.SystemProperties.get(SystemProperties.java:47)
        at com.htc.profileflag.ProfileConfig.<clinit>(ProfileConfig.java:168)
        ... 14 more
Richard T
  • 4,570
  • 5
  • 37
  • 49
  • Yep, as Gabe points out this is relatively simple to figure out, at least to the point of knowing the cause for the failure. While running a class initializer, an UnsatisfiedLinkError occurred, attempting to reference native method `native_get`. This probably indicates that something is wrong with your library path (since that's where you find native methods). – Hot Licks Apr 09 '13 at 01:56

2 Answers2

3

That bug means a JNI call was made and it couldn't find the native function it was trying to tie to. Looks like android.os.SystemProperties.get was trying to call a native library function called native_get to actually do some work. Do you have the library properly included in the project?

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • "Do you have the library properly included in the project?" ...I'm going to go WAY out on a limb here and say, "probably not!" -smile- I have noticed some environment variable differences worth looking more deeply into. TY for your comments.... – Richard T Apr 09 '13 at 03:02
  • As I read your comment carefully, maybe I wasn't clear that I'm building the library itself. It only has standard java dependencies (includes). The only one I know of that wasn't there (java.rmi) I decided to comment out because RMI is not a key part of what this code does. None of the environment variable details panned out, so far at least. – Richard T Apr 09 '13 at 17:12
0

I'm super-skeptical of the com.htc.profileflag.ProfileConfig.<clinit> entry in your stack trace. I suspect that maybe the environment on your device is slightly different than what terminal-ide expects, and it hasn't included the correct jni libraries for whatever that HTC specific thing is.

To check if this really is a device-specific issue, you might try setting up terminal-ide in an emulator and see if you get the same error when building your library.

JesusFreke
  • 19,784
  • 5
  • 65
  • 68
  • You may be on to something regarding my env vs what Terminal-IDE expects, but I haven't a clue how I'd emulate the build! (I'm fairly new to Android - I've run my own apps in emulation, but the _build_ environment? Hmmm...) – Richard T Apr 09 '13 at 03:04
  • It shouldn't be any different than running terminal-ide on your own device - you start up the android emulator, install terminal-ide, copy your project and try to build, just like you would on your device. – JesusFreke Apr 09 '13 at 03:35
  • Yesterday I spent hours trying to install terminal-ide on the android emulator in my Windows-7 based Eclipse development environment; try as I might, I could not find a way to install an app into the emulator that I did not create as a project. There was no "install" feature! I even updated the installation using the update tools - still no joy. – Richard T Apr 10 '13 at 14:31
  • Huh? You can use adb to install an application on the emulator, just like you would for a device. – JesusFreke Apr 10 '13 at 23:43