Ran into the problem of running out of heap space when running my program on Eclipse the other day. It just so happens that the heap space that is allocated for my programs in Eclipse on my Mac at home is less than what is supplied for my work laptop, thus making my program crash at home and not on my laptop. When dealing with a huge amount of data and objects in a large hash array of trees, heap space can run out pretty quick. So, after digging around a bit on Google I found two simple solutions that I continued to run into. Click here or the Read More link for solutions…
Tag Archives: Eclipse
Changing Android SDK Versions in Eclipse mid-development
First of all, let me say that you should definitely avoid being in a position to need this guide if at all possible. I would highly reccomend ignoring anything that tells you to use a version older than that absolute newest one possible, because you’ll probably end up doing a lot of work to fix it later. Should you end up in this unfortunate circumstance like I did, here is how you change your SDK version in Eclipse the ugly “I don’t actually know how to fix this but I can hack it” way:
1) Create a new project (you can’t name it the same as your old one, name it something similar). This time use the new SDK version.
2) Delete the following files out of your new project, and copy-paste the ones from your old project in their place: all src->’your.package.name’ files, all res->layout and res->value files, and finally, your Android manifest. Note that you may want to double check your Android manifest to see that the min SDK version variable updates itself. It did so for Daniel, but it may not for everyone.
3) Right click your old project, Refactor->Rename to old[ProjectName]. Right click your new project, Refactor->Rename to [ProjectName].
4) (Optional) if you’re using subclipse, it is now mad at you. You will still have a connection between your repository and what is new old[ProjectName]. To correct this, just do a commit of the newly made [ProjectName] directory, by going through all the steps associated with that. (Right-click, Team->Share Project, set up repository info, write commit comment etc). It will warn you that it needs to check out the most recent version, this should be fine since you likely have the most recent anyway, it does some magic and you get your pretty black asterisk back. Hurray!
Note that I am 100% sure all of this hackery is completely unncessary and that Eclipse has in it some magical function which would’ve just upgraded the SDK cleanly. However, I spent about an hour looking for said magic button and didn’t find it. In a pinch, you can use my foolish method to change your Android SDK version over!
EEEBuntu wireless gotcha & connecting an Android by USB
A few misc. Ubuntu and Android notes today:
1) I said a couple days back that I’d write up some EEEbuntu gotchas that I had a whole barrel of laughs with over the weekend. This one had me reformatting my EEEPC, so I think it qualifies. In the USB stick install, there is a nice convenient wifi notification on the top/right portion of the screen. When you actually install the OS, however, this isn’t present. I’m not good enough at linux (apparently) to figure out how to launch that wifi app, so this left me without a way to connect wirelessly. I did some googling and it turns out that you need to Right-click the menu bar at the top, and navigate to ‘add a notification’ (I can’t recall the exact path and I couldn’t google up any guides). NOTE: At this point you MUST restart EEEbuntu. You won’t get any confirmation that you added your notification successfully, and it will not show up until you restart. This is all you have to do to fix the wifi. (I won’t tell the whole story, but the basic jist of my reformat is that I sat there and added about 8 notification areas without rebooting, and when I tried to delete them I blew up the whole top menu bar and couldn’t get it back…)
2) Preparing your Android development environment to include real-phone testing! (This one is pretty cool once you get it working)
Essentially, just follow this guide, however there are a few little tricks. First of all, if you’re doing it on Ubuntu, all of those steps may not make it ‘just work’. As for which of the two strings to put in your rules file, Dapper and Gusty/Hardy are older version of Ubuntu, but string that worked for me was: SUBSYSTEM==”usb_device”, SYSFS{idVendor}==”0bb4″, MODE=”0666″
Secondly, keep in mind you’re going to need to use the sudo command before just about every command related to this setup. (For those of you who, like me, aren’t well versed in linux, this gives you ‘root’ priveleges to do administrative stuff. If you don’t include it, the terminal will complain that you don’t have the rights to do things like save your rules file). My third tip is to restart your udev, which I found on the anddev.org forums. Use: sudo /etc/init.d/udev reload. Finally, use adb kill-server before you adb-devices if your device still doesn’t show up (but is connected). This was the magic trick that made it finally work for me (also from the same anddev.org forum post-that place is great).
Android Manifest & Permissions
Another in my series of ‘Android development gotchas’.
At Google I/O they made a very big deal over how programs need to request permission from the user in order to access most resources (user’s GPS location, the internet, files, etc). This is an easy one to forget during development however, and it slipped through the cracks on me twice. I actually corrected this problem early this week, but we had to remake our project from scratch due to other issues and I forgot to add the permissions again. Since it caused me a fair bit of headache I thought I’d write up a quick how-to on permissions in Android.
There is a file called the Android Manifest which holds various information about the program (this is generated for you when you make an Android project in Eclipse). Included here is a list of permissions that the program requires. Without these, attempts to do things like accessing the internet will fail. To add permissions, you basically:
Double click AndroidManifest.xml, Click the Permissions tab (at the bottom of the window it brings up), Click add, Click ‘Uses Permission’, Click the ‘name’ dropdown, Find the permission you need and click it. That’s all!
If my pure-text description is less than helpful, I used this link as a guide to figure this all out.
Debugging Android apps in Eclipse
This proved to be a little tricky for me. I ran into a problem where Eclipse wouldn’t show me my variables in my Android app.
Apparently, you can only inspect variables in a specific scope within an Android program. You can’t see class variables, etc. In order to see any variables at all, you need to set a breakpoint somewhere near the area you suspect is a problem.
I’m not sure if I needed to do this, but one other thing I did before I got the debugger to finally show me variables was adding the tools directory to my PATH. The explanation for this can be found in this guide. Note that those files are hidden, so you’ll have to learn how to view them on whatever OS you’re using!
Using Subclipse
This guide is very useful for setting up Eclipse and Subversion to work together.
However, one issue that Daniel and I had today is that it is not immediately obvious how to check out a project if you aren’t the person who uploads it originally.
Clicking the Import option in the Eclipse package explorer results in a number of options being displaying. One of these should be SVN (if not it will be under ‘Other’). From this menu option, you can specify an svn directory online to check out a project from.
I’m still having some issues with getting Eclipse to be happy with things imported from our svn directory, however. I’ll try to remember to update this with the fixes when I find them!
Setting up Android development environment in Eclipse
This post will consist of mainly links to guides which I used in setting up my development environment to write Android apps.
Step 1. Install Eclipse as per usual http://www.eclipse.org/downloads/ (I always install the Classic package, but I’m not sure if that is the best way to go)
Step 2. Download the Android SDK http://developer.android.com/sdk/1.5_r2/index.html (I don’t think it matters where you unzip it to, as long as you can find it later)
Step 3. Follow set up instructions http://developer.android.com/sdk/1.5_r2/installing.html
Step 4. Learn about how to create and run Android projects http://developer.android.com/
A few gotchas:
Android has a built in JSON feature which is explained here: http://developer.android.com/reference/org/json/JSONObject.html
Java does not ordinarily have JSON packages included (as far as I know), and if you include json_simple or similar packages, Eclipse will no longer recognize the Android JSON package.
This happened to me, and I had trouble figuring out how to tell Eclipse to ignore the package I no longer wanted. An easy work-around is to remake your project and copy/paste source files.