I checkout ws-msgcomp onto my laptop and wanted to move the settings from my main machine to the laptop. I found that Eclipse really doesn’t like to do that and when you do things still need tweaking.
Here was a link on what someone did for moving the settings so I created a tar script to save the settings:
tar -cjvf $1.tbz .metadata/.plugins/org.eclipse.core.runtime .metadata/.plugins/org.eclipse.ui.workbench
I saved this as backup-eclipse-settings.sh in my local bin file and executed:
backup-eclipse-setting.sh settings
creating settings.tbz I scp that to the laptop and untared it. then executed eclipse. First problem was I had my old files but no projects were imported. I imported the projects but they wouldn’t compile because “aapt” couldn’t be found even though it was there in the path it said it expected it to be. Turns out I needed to reset the android SDK path; In the Eclipse menu “Windows -> Preferences -> Android -> SDK Location:” I used Browse to reset it, even though it was correct.
Next I had to goto each of the projects and “Browse” to each of the imported libraries by selecting the Project then using the Eclipse menu; “Project -> Properties -> Java Build Path -> Libraries” and then select each of the jar’s Editing the location browsing to the actual location.
So it seems that even though the textual path is the same that isn’t enough, its almost seems it keeps the inode. Bottom line Eclipse doen’t handle paths well.
Eclipse is a reasonable IDE and it has a reasonable pretty printer (Source/Format or Shift+Ctrl+F) except for one thing; when a function call exceeds 80 characters the formatting is terrible in my opinion:
/**
* Arguments
*/
class Example {
void foo() {
Other
.bar(
100, 200, 300,
400, 500, 600,
700, 800, 900);
}
}
Anyway, this can be changed by going to menu:
Window/Preferences/Java/Code Style/Formatter
Here you should make a “New” profile from an existing profile that is close to what you want, I used “Eclipse [built-in]” for my base, it was the default. And then select “Edit”. In the dialog box “Profile ‘….’” select “Line Wrapping” tab and then I changed “Maximum line width:” to 100 from 80 and then selected “Function Calls/Arguments” in the window below and then in the “Settings for agruments/Indentation policy:” selected “indent by one” this cured the formatting problem and now the above is:
/**
* Arguments
*/
class Example {
void foo() {
Other.bar(100, 200, 300, 400,
500, 600, 700, 800, 900);
}
}
Much better!
Been a few days, had a nice Christmas and New Years. Did work on Android and made good steady progress and nothing real interesting to report until today.
What was interesting is that I leaned that instance variables of class are initialized twice. The first time is before the constructor gets called the variables are initialized to the expected “zero” type defaults. boolean = false, byte/char/short/int = 0, float/double = 0.0 and object references to null.
Next the constructor is called and as the first instruction of the constructors executes values are at there defaults NOT any specific initialization, so don’t assume as I did. Usually this isn’t a problem but if you have inheritance thing can be surprising. In the example below when you instantiate X (new X()) we see:
X#overrideMe(): m=0
X#X(): m=4;
I would have naively expected both to print m=4!
class B {
B() {
overrideMe();
}
void overrideMe() {
System.out.printf(”Not called\n”);
}
}
class X extends B {
X() {
System.out.printf(”X#X(): m=%d\n”, m);
}
@Override
void overrideMe() {
System.out.printf(”X#overrideMe(): m=%d\n”, m);
}
int m = 4;
}
What happens is that X#overrideMe is called while in the B#B() and m has only its default value zero and it doesn’t acquire its initialized value until after B#B() has completed.
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.