Wink Saville’s Blog

February 12, 2008

Eclipse – ant and build.xml

Filed under: Android, Ant, Eclipse, java — wink @ 1:31 pm

This week I converted async-msgcomp to use ant for building rather than the internal Eclipse builders because it was the only way I could figure out to get jar files automatically built. After some trial an error I came up with common-build.xml which are common tasks for all sub-project and resides at the root of my build tree. I also created android-build.xml which is in the android sub-directory and is the common Ant tasks for Android. Then within each sub-project is a build.xml, for instance java/debug/build.xml and android/debug/build.xml as well as a global build.xml file in my root. For full disclosure; common-build.xml was based on the build.xml file emitted by:

File -> Export -> General -> Ant Buildfiles

And android-build.xml is based on the build.xml file emitted by running:

android-sdk/tools/activityCreator.py

The build.xml files are then used by executing ant in the appropriate sub directory. By executing ant in the root all of the sub-projects are built. Eclipse is also capable of building using Ant but you have setup the properties for each sub-project, which I’ll try to outline below. Sometimes Eclipse has trouble and either won’t execute saying they are still errors or it won’t execute because the classpath isn’t set properly.

One solution that has helped is to delete all projects and re-import them. Two other important items is that the Run parameters must be setup properly in <Run/Open Run Dialog> must be set properly and Build parameters for must be good.

Anyway, here is an example of setting the project properties so that external Ant files are used for compiling, in the example below I’m setup the sub-project “debug”. We assume there is a build.xml file in the sub-project.

Project -> Properties -> Builders -> new:

Main.Name: = debug-build.xml
Main.Buildfile: = Browse Worksapce => debug/build.xml
Main.Base Directory: = Browse Workspace => debug
Targets.After a “Clean”: = <default target selected>
Targets.Manual Build: = <default target selected>
Targets.Auto Build: = <default target selected>
Targets.During a “Clean”: = clean

Project -> Properties -> Builders = select only debug-build.xml deselect all others
Project -> Propertiers -> java Build Path -> Libraries = Add appropriate Libraries
Project -> Propertiers -> java Build Path -> Order and Export = the Libraries
Project -> Propertiers -> Project References -> Project references for debug: = select appropriate projects

In the Project -> Properties -> Builders where we select only debug-build.xml and deselect all others includes the following if it is an Android sub-project:

Android Resource Manager
Android Pre Compiler
Java Builder
Android Package Builder

If it is “pure java” project than you just deselect Java Builder.

February 11, 2008

Android – Eclipse “Could not find xxxx.apk”

Filed under: Android, Eclipse — wink @ 10:45 am

Today started off poorly, I decided to create ews (eclipse workspace) directory and then put the workspaces in that sub-directory. I started with an empty workspace as I have my sources separate from the workspace and then added in debug. I was able to compile fine but when I tried to run the android application I got:

[2008-02-11 10:36:03 - mc-android] Android Launch!
[2008-02-11 10:36:03 - mc-android] Could not find /bin/mc-android.apk!

Of course there was an mc-android.apk but it’s not in “/bin” (off the root) its at “bin” relative to the sub-project. Anyway, the solution appears to be to remove the project and import it again.

January 14, 2008

Eclipse – settings and moving workspaces

Filed under: Eclipse, programming — wink @ 11:08 am

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.

January 5, 2008

Eclipse – line wrapping and indentation when formatting

Filed under: Eclipse, java — wink @ 11:45 am

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!

December 21, 2007

Eclipse – multiple/new workspace

Filed under: Android, Eclipse, programming — wink @ 11:31 am

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.

December 15, 2007

Eclipse – install

Filed under: Android, Eclipse, linux, programming — wink @ 3:37 pm

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.

Powered by WordPress