If you want to use ant with a buld.xml file to one of the operations that needs to be done is to convert a “.class” files to a “.dex”. One way to do this using dx is to convert an entire “.jar” file. The following command converts com.saville.android.debug.jar, a jar file with two classes, Log and Timing, to a dex file:
wink@ic2d1:$ dx –dex –output=classes.dex –locals=full –positions=lines com.saville.android.debug.jar
wink@ic2d1:$ ls -al classes.dex
-rw-r–r– 1 wink wink 3971 2007-12-23 18:50 classes.dex
See dx -help for other parameters, –locals=full and –positions=lines is used because thats what the build.xml file generated by activityCreator.py uses.
To disassemble an entire jar file as a disassembled dex use the following:
dx –dex –dump-to=abc –locals=full –positions=lines com.saville.android.debug.jar
Click here to see the output.
Here is an example of using dx, the android jvm-byte-code to dex converter to disassemble a method in a class. The input is a “.jar” file of my debug class and I’m dumping the print method of class Log:
wink@ic2d1:$ dx –dex –dump-method=com.saville.android.debug.Log.print com.saville.android.debug.jar
com/saville/android/debug/Log.print:(Ljava/lang/String;[Ljava/lang/Object;)V:
0000: move-object v0, v6
0001: move-object v1, v7
0002: const/4 v2, #int 4 // #4
0003: const-string v3, “” // string@0000
0005: move-object v4, v0
0006: move-object v5, v1
0007: invoke-static {v4, v5}, java/lang/String.format:(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String; // method@0014
000a: move-result-object v4
000b: invoke-static {v2, v3, v4}, android/util/Log.println:(ILjava/lang/String;Ljava/lang/String;)I // method@0000
000e: move-result v2
000f: return-void
source positions
0000: 56
000f: 57
source file: Log.java
I wanted to disassemble a class using javap but unzipping android.jar navigating to android/os where Message.class resided and then executing:
javap -c Message.class
results in:
Couldnot find Message.class
I then searched for <javap Could not find> and found that specifying the class path and then the package name worked:
javap -c -classpath ~/android/android_sdk_linux_m3-rc37a/android.jar android.os.Message
Also, I could specify the unzipped jar, assume android.jar unzipped to android.xx and that works also:
javap -c -classpath ~/android/android_sdk_linux_m3-rc37a/android.xx android.os.Message
And the simplest was cd’ing into the directory with message and using “.” for classpath, that worked also:
cd android.xx/android/os/
javap -c -classpath . Message
Actually it turns out that if we go back to the original attempt but don’t leave off .class all is well , so assuming were still in android.xx/android/os then we just need:
javap -c Message
After creating a new local repository either brand new or cloning an existing repo typically I want to push it to my server for backup purposes. To do so I create a bare repository on the server:
mkdir <path-to-repo>/<name-of-repo.git>
cd <path-to-repo>/<name-of-repo.git>
git --bare init --shared
The repo is now created go back to the local repo and have the local master branch track the remote origin and push it to the remote which we’ve named ‘origin’:
cd <path-to-local-repo>
git remote add -t master origin git://<server>/<name-of-remote.git>
git push origin master
I had trouble testing xmpp, I created a simple app, txmpp based on the sample code XmppDataMessageSend and couldn’t get it to work. The ServiceConnection call back was never executed.
Turns out you need to run the emulator and go into Dev Tools/XMPP Settings and add a valid gmail account, then it works as expected, see here. This doesn’t seem to allow general peer to peer connections between apps and in particular seems to require all messages to go through a central service. Not what I was looking for:(
Here other people are looking at similar issues and Dan Morrill replies here that Xmpp isn’t intended for adhoc communication and suggests Blue tooth. Interesting that wifi isn’t mentioned?
As of today, Dec 21 here is a short list of <peer to peer> hits when searching the Android-developer list:
Here, here, here, here, …
There was two pages worth.
Here was a question about getting the local IP address, someone wants to do RTP.
I wanted to start eclipse using a different workspace than the default. I searched for <eclipse new workspace> and here it said to use the -data option and so that you know which workspace your in use the showlocatin option:
eclipse –data ws-android –showlocation
I then added -showlocation to the the gnome application lanuch icon.
To install Eclipse you need to install sun-java, the gcj version installed in Ubuntu 7.10 isn’t capable of fully supporting Eclipse. What I did was install sun-java-6-* via synaptic, but of course its not that simple.
I installed all of the sun-java6-* files via synaptic, of course that didn’t install flawlessly as you need to download jdk-6-doc.zip from here selecting download for “Java SE 6 Documentation” which was here (you need to “Accept the license agreement”) and place it in /tmp/. Next I downloaded Eclipse from here and untar’d it into /usr. I then setup a symbolic link from /usr/local/bin/eclipse to /usr/eclipse/eclipse, the I ran ecplise. It boots but said “Error creating the view”. I did a little searching, turns out had the wrong jvm. I needed to uninstall java-gc-compat and create a symbolic link from /etc/alternatives/java to /usr/lib/jvm/java-6-sun/bin/java. Then it finally ran!
The short list of instructions:
*) Download Eclipse I chose “Eclipse Classic 3.3.1.1″.
*) Download jdk-6-doc.zip and place in /tmp/
*) Uninstall java-gcj-compat via synaptic or apt
*) Install all sun-java-6-* via synaptic or apt
*) Besure there is a symbolic link from /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/bin/java
sudo ln -sf /usr/lib/jvm/java-6-sun/bin/java /etc/alternatives/java
*) Untar Eclipse into /usr (creates /usr/eclipse/)
cd /usr
sudo tar -xvf ~/downloads/eclipse-SDK-3.3.1.1-linux-gtk-x86_64.tar.gz
You should now be able to run eclipse and the Welcome screen should appear, if you drop right into Eclipse and a warning that you couldn’t create a view then you’re executing the wrong jvm. Start by using the comand:
wink@ic2d1:$ which java
/usr/bin/java
wink@ic2d1:$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 2007-12-04 09:55 /usr/bin/java -> /etc/alternatives/java
wink@ic2d1:$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 32 2007-12-04 20:59 /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/bin/java
wink@ic2d1:$ ls -l /usr/lib/jvm/java-6-sun/bin/java
lrwxrwxrwx 1 root root 15 2007-12-04 17:53 /usr/lib/jvm/java-6-sun/bin/java -> ../jre/bin/java
wink@ic2d1:$ ls -l /usr/lib/jvm/java-6-sun/jre/bin/java
-rwxr-xr-x 1 root root 50650 2007-09-24 23:34 /usr/lib/jvm/java-6-sun/jre/bin/java
As you can see on my machine there are several links before getting to the actual executable.
A BuildID is being added to the gnu linker, ld, by Roland McGrath. I saw this mentioned in these instructions for building the Android kernel from source, which didn’t support the new switch and it had to be disabled.
Anyway, Roland had a problem where he wanted to identify exactly where the binaries came from when inspecting a post-mortem dump. Especially when the dump could have happened long after the build was actually done. While at nxp we had this problem and generally relied upon the svn release number. That worked but isn’t actually unique enough especially when a particular build might be one by a developer and not an official release.
Anyway, this looks to be a possible solution
For my state machine code I’d like to determine at runtime what states the user has created and what there hierarchy. I’ve created an interface that all states of a state machine must implement. My first thought was to use Annotation, but that didn’t work out, Android doesn’t seem to implement retrieving the annotation at runtime. So today I came up with the idea of using getClasses():
Class cl = this.getClass();
Class classes[] = cl.getClasses();
Log.v(df, “Hsm: Hsm() classes.length=” + classes.length);
for (Class c : classes) {
Log.v(df, “Hsm: class %s”, c.getName());
}
But that doesn’t work either:
I/ ( 587): Client: MyHsm() E name=TestHsmClient0
W/dalvikvm( 587): No implementation found for native java/lang/Class.getDeclaredClasses (Ljava/lang/Class;Z)[Ljava/lang/Class;
D/dalvikvm( 587): Exception java/lang/UnsatisfiedLinkError from Class.java:414 not caught locally
W/dalvikvm( 587): threadid=15: thread exiting with uncaught exception (group=0×4000e648)
E/AndroidRuntime( 587): Uncaught handler: thread TestHsmClient0 exiting due to uncaught exception
E/AndroidRuntime( 587): java.lang.UnsatisfiedLinkError: getDeclaredClasses
E/AndroidRuntime( 587): at java.lang.Class.getDeclaredClasses(Native Method)
E/AndroidRuntime( 587): at java.lang.Class.getFullListOfClasses(Class.java:414)
E/AndroidRuntime( 587): at java.lang.Class.getClasses(Class.java:172)
E/AndroidRuntime( 587): at com.saville.android.testhsm1.TestHsmClient$MyHsm.build(TestHsmClient.java:40)
E/AndroidRuntime( 587): at com.saville.android.testhsm1.TestHsmClient$MyHsm.<init>(TestHsmClient.java:34)
E/AndroidRuntime( 587): at com.saville.android.testhsm1.TestHsmClient.InitHsm(TestHsmClient.java:21)
E/AndroidRuntime( 587): at com.saville.android.hsm1.ActiveHsm.run(ActiveHsm.java:59)
E/AndroidRuntime( 587): at java.lang.Thread.run(Thread.java:896)
I/Process ( 461): Sending signal. PID: 587 SIG: 3
I/dalvikvm( 587): threadid=7: reacting to signal 3
Bummer.
I then searched for <java find all private classes> and came across this. “Locating all classes implementing a given interface?”. Exactly what I wanted, there were two replies to the post. One says use “ServiceLoader” the other says; “Manually scan the classes in the jar file” or “in your manifest.mf file”. Its interesting that Android has taken the approach of a manifest file. I did a quick search for ServiceLoader its manifest based also.
I had a little trouble doing an nfs mount today. I wanted to mount a directory on my laptop onto my desktop so I could do some backups. I modified /etc/exports on my laptop, which has successfully exported nfs mount file systems for a long time, by having /etc/exports be:
/home/wink *:(rw,no_root_squash,no_all_squash,sync,nohide)
Then on my destop I did:
mkdir mntdir
sudo mount 192.168.0.1:/home/wink mntdir
But this didn’t work it generated an error saying I was stupid:) After trying a bunch of permutations I did some google searching and found this. Turns out that on my desktop I didn’t have portmap or nfs-common installed. After installing them all was well, and the above mount worked.