It doesn't appear that there are very many tutorials at the Android Developer site. And the ones that I have read so far are pretty lightweight. So I'm thinking that I should get an Android book for when I've completed the tutorials.
Looking over the books at Amazon for Android app development (here's a good search for that), I'm thinking I want a gentle, guided approach instead of a heavy reference manual type book. Checking out ratings, reviews, and how recent the books are, I decided to try Hello, Android: Introducing Google's Mobile Development Platform, Third Edition, by Ed Burnette. It covers audio and video support, 2D and 3D graphics, web pages and web services, storing data, and publishing to Android Market.
What really sold me were the reviews that said you could learn Android in just a few days with this book, that it's easy enough to read in a weekend. Now I have no intention of doing that. I want to take my time and let things sink in. And I'm not spending a lot of time per day on this project. But I do want to take an easy learning curve, and this book sounds like it's got that.
Into Apps
I want to learn how to program apps for Android. I plan on taking a gentle approach.
Monday, August 23, 2010
Sunday, August 22, 2010
Roadblock to Running Tutorials
I go on to the next tutorial, Relative Layout, which is again extremely simple. And like the previous simple tutorial, it won't run for me either. I was careful to run it as an Android Application, but still no go. Worse, I could no longer run the previous tutorials either. Something was seriously hosed.
The last message on the console is "Installing RelativeLayout.apk..." and it just stays there forever, instead of going on to the "Success" message. So the app isn't loading. Visually, what is happening on the emulator is that it starts with the "A N D R O I D" phase, goes on to the chrome "android" phase, goes on to the home page, and then the little animating battery icon stops moving. After that we go back to the chrome "android" and just stay there forever. Quitting the emulator and rerunning the app didn't help.
The Android Developers site has a Troubleshooting page. I was very interested to find out about the adb tool (Android Debug Bridge tool). In a Terminal window I fiddled with it a bit. I followed the suggestion of quitting Eclipse, killing the server (which is apparently the process that runs the Android Virtual Device on the emulator), and rerunning the app, but that was no help. I ran adb with the logcat option and watched all the log output while trying to run the app, but there was way too much stuff and it went by too fast. So I redirected it to a file:
I ended up spending a couple days stuck on this issue. I tried rebooting my Mac. I fiddled with the adb tool some more. I found the DDMS perspective in Eclipse which has many cool-looking things, including being able to explore the files on the AVD, but I couldn't find anything helpful there. I noticed that much of its functionality shows up as tabs on the console pane in the Java perspective. I figured there must be a forum somewhere which might be helpful, and I found links on the Android Developer site. However, the link to the beginner's forum told me that they were just shutting it down and to go to Stack Overflow instead. I signed up there and searched through the Android stuff, but didn't find anything that addressed my issue.
Eventually I decided to try starting the first tutorial over from scratch. If that didn't accomplish anything, I was going to try reinstalling the Android SDK and Eclipse. Fortunately, I didn't have to go that far. In the first tutorial we create an AVD and in the redoing I made a new AVD. The tutorial ran and the other tutorials also ran, somehow using the new AVD. I kept fiddling and the tutorials all stopped running again, even using the new AVD. I kept poking around in Eclipse and ended up at Window --> Android SDK and AVD Manager which has a list of the AVD's if you click on "Virtual Devices" on the left. What I discovered to work is to quit the emulator, then in this window to select the AVD I'm trying to use, click "Start..." on the right, then in the Launch Options box that comes up, check Wipe user data, then hit Launch. The emulator will run until the home page shows up, then I can run my tutorial just fine. I don't really have a clue as to what is going wrong or how this fixes it, but at least this way I have a method of getting a dead AVD to start working again.
This was a massively frustrating exercise.
The last message on the console is "Installing RelativeLayout.apk..." and it just stays there forever, instead of going on to the "Success" message. So the app isn't loading. Visually, what is happening on the emulator is that it starts with the "A N D R O I D" phase, goes on to the chrome "android" phase, goes on to the home page, and then the little animating battery icon stops moving. After that we go back to the chrome "android" and just stay there forever. Quitting the emulator and rerunning the app didn't help.
The Android Developers site has a Troubleshooting page. I was very interested to find out about the adb tool (Android Debug Bridge tool). In a Terminal window I fiddled with it a bit. I followed the suggestion of quitting Eclipse, killing the server (which is apparently the process that runs the Android Virtual Device on the emulator), and rerunning the app, but that was no help. I ran adb with the logcat option and watched all the log output while trying to run the app, but there was way too much stuff and it went by too fast. So I redirected it to a file:
./adb logcat > log.txtand ran the app again. Looking at the file in TextEdit, there are lots of error-appearing messages, but none of them are obviously my issue. I do see something curious though. At one point the log lists service after service that died. This occurs right after this log message:
D/Zygote ( 32): Process 59 terminated by signal (11)When I run adb logcat without redirecting the output and have the emulator window visible at the same time, I can see that the battery icon stops animating just about when this message appears. Very interesting, but I have no idea what to do with this information.
I ended up spending a couple days stuck on this issue. I tried rebooting my Mac. I fiddled with the adb tool some more. I found the DDMS perspective in Eclipse which has many cool-looking things, including being able to explore the files on the AVD, but I couldn't find anything helpful there. I noticed that much of its functionality shows up as tabs on the console pane in the Java perspective. I figured there must be a forum somewhere which might be helpful, and I found links on the Android Developer site. However, the link to the beginner's forum told me that they were just shutting it down and to go to Stack Overflow instead. I signed up there and searched through the Android stuff, but didn't find anything that addressed my issue.
Eventually I decided to try starting the first tutorial over from scratch. If that didn't accomplish anything, I was going to try reinstalling the Android SDK and Eclipse. Fortunately, I didn't have to go that far. In the first tutorial we create an AVD and in the redoing I made a new AVD. The tutorial ran and the other tutorials also ran, somehow using the new AVD. I kept fiddling and the tutorials all stopped running again, even using the new AVD. I kept poking around in Eclipse and ended up at Window --> Android SDK and AVD Manager which has a list of the AVD's if you click on "Virtual Devices" on the left. What I discovered to work is to quit the emulator, then in this window to select the AVD I'm trying to use, click "Start..." on the right, then in the Launch Options box that comes up, check Wipe user data, then hit Launch. The emulator will run until the home page shows up, then I can run my tutorial just fine. I don't really have a clue as to what is going wrong or how this fixes it, but at least this way I have a method of getting a dead AVD to start working again.
This was a massively frustrating exercise.
Running a Tutorial Wrong
I move on to the first of the view tutorials, Linear Layout. The tutorial is dead simple, but when I run it, things go nuts. I get these errors in the console in Eclipse:
I try deleting the bogus main.out.xml file and trying again, but same result. After much thrashing and swearing I finally figured it out. I had gotten used to just doing a Run on the previous tutorial as I modified it and built it several times. So when it came time to run this new project, I did the same thing. (It's command-shift-F11 on my Mac.) When I didn't do was to run it the first time with Run As Android Application, so that Eclipse would know how to run it for this time and all future runs. You'd think that creating it as an Android Project would have given Eclipse a clue, but nope. It tried to run my main.xml file instead.
[2010-08-18 02:27:04 - HLL] Error in an XML file: aborting build.Say what? There was no main.out.xml file before I ran it. Eclipse created that empty file and then complains about it? And somehow this empty file has already defined something so that the real file, main.xml, gets an error? The error messages are totally unhelpful. The Problems pane down at the bottom is no help either.
[2010-08-18 02:27:04 - HLL] res/layout/main.xml:0: error: Resource entry main is already defined.
[2010-08-18 02:27:04 - HLL] res/layout/main.out.xml:0: Originally defined here.
[2010-08-18 02:27:04 - HLL] /Users/zaradaqaw/Documents/Development/EclipseWorkspaces/AndroidPlay/HLL/res/layout/main.out.xml:1: error: Error parsing XML: no element found
I try deleting the bogus main.out.xml file and trying again, but same result. After much thrashing and swearing I finally figured it out. I had gotten used to just doing a Run on the previous tutorial as I modified it and built it several times. So when it came time to run this new project, I did the same thing. (It's command-shift-F11 on my Mac.) When I didn't do was to run it the first time with Run As Android Application, so that Eclipse would know how to run it for this time and all future runs. You'd think that creating it as an Android Project would have given Eclipse a clue, but nope. It tried to run my main.xml file instead.
Hello World
With everything installed, time to try a tutorial. The first one on the Android site Hello World has a fair number of steps because it covers creating an Android Virtual Device (AVD), two different ways of doing UI, and a first look at debugging. Everything worked just as expected when I tried it.
When you create an Android project, one of the fields is "Min SDK Version". The tutorial doesn't have you fill it in, and that's OK. When you run the app, you will get a complaint but nothing bad beyond that seems to happen. If you do want to fill it in, for example if you want to require Android 2.2, you need to specify 8, the API version, rather than 2.2 as you might expect.
The emulator is sooo slow to load. For me, it takes about 1 minute and 45 seconds, and my Mac runs at 2.8GHz with 8 cores. In the emulator window, first I see a black screen with "A N D R O I D" in the middle, looking like that, a normal font. After a while it switches to "android" in a fancy font, chrome colored with light sweeping across it. After another while I get the home screen, which has a nice picture of a lake as the background. Then finally the app runs.
If you don't already know how to do debugging in Eclipse, this tutorial is no help. You set a breakpoint and can stop on it, but then what? It's certainly not obvious. And if I step until the bug happens, it's even more mysterious because my code that has the bug doesn't appear to be on the stack.
BTW, when the debugging stuff is up, you are in a different Eclipse perspective from where you were before. To get back to seeing your project you can click in the very upper right of the window to bring up the Java perpective or you can do it via menus: Window --> Open Perspective --> Java.
When you create an Android project, one of the fields is "Min SDK Version". The tutorial doesn't have you fill it in, and that's OK. When you run the app, you will get a complaint but nothing bad beyond that seems to happen. If you do want to fill it in, for example if you want to require Android 2.2, you need to specify 8, the API version, rather than 2.2 as you might expect.
The emulator is sooo slow to load. For me, it takes about 1 minute and 45 seconds, and my Mac runs at 2.8GHz with 8 cores. In the emulator window, first I see a black screen with "A N D R O I D" in the middle, looking like that, a normal font. After a while it switches to "android" in a fancy font, chrome colored with light sweeping across it. After another while I get the home screen, which has a nice picture of a lake as the background. Then finally the app runs.
If you don't already know how to do debugging in Eclipse, this tutorial is no help. You set a breakpoint and can stop on it, but then what? It's certainly not obvious. And if I step until the bug happens, it's even more mysterious because my code that has the bug doesn't appear to be on the stack.
BTW, when the debugging stuff is up, you are in a different Eclipse perspective from where you were before. To get back to seeing your project you can click in the very upper right of the window to bring up the Java perpective or you can do it via menus: Window --> Open Perspective --> Java.
Increase Java Heap memory?
In the release notes for Eclipse (readme/readme_eclipse.html in the Eclipse folder), in the Running Eclipse section, it talks about allocating extra memory for the Java VM. I have 6GB of RAM in my Mac so that sounded like a nice thing to do, to try to help Java to run faster. It says to use "
One of the lines in my eclipse.ini file is just: -vmargs
so I edited it to look like this: -vmargs -Xmx1024M
since the default is "256M". However, when I run Eclipse this way, it runs out of memory very quickly. Clearly something is wrong. So I try again with: -vmargs -Xmx512M
This also causes Eclipse to run out of memory. Since I clearly don't know what I'm doing, I just revert it back to the way it was and leave it alone for now. I may revisit this later.
eclipse -vmargs -Xmx<memory size>"
when launching Eclipse. On a Mac, you typically would just click on the icon instead of running from the command line, so they have a link just above this in the notes to special instructions for running on a Mac. There it tells you to edit the eclipse.ini file in order to fiddle with command line arguments.One of the lines in my eclipse.ini file is just: -vmargs
so I edited it to look like this: -vmargs -Xmx1024M
since the default is "256M". However, when I run Eclipse this way, it runs out of memory very quickly. Clearly something is wrong. So I try again with: -vmargs -Xmx512M
This also causes Eclipse to run out of memory. Since I clearly don't know what I'm doing, I just revert it back to the way it was and leave it alone for now. I may revisit this later.
Install Stuff
First step is to get Android and get a development environment set up. I did this a bit ago so this post and maybe a couple more will be catching up with what I've already done.
Located the Android development site. I'm starting from scratch, so I went for the SDK starter package. I'm on a Mac Pro running OS X 10.5.8 (not the latest; saw no reason to upgrade to Snow Leopard 10.6) so I downloaded the Mac zip file, getting me Android 2.2. The Quick Start follows on that page, and yeah, my System Requirements are fine. I assume I have a JDK installed (not sure how to check this) and if it turns out that I don't, I'll deal with it then.
I read (somewhere) that by far the easiest way to develop Android apps is using Eclipse and the Android Development Tools (ADT) plugin. The Quick Start points out that I need to stick with Eclipse 3.4 or 3.5 and not use the latest. Following the Eclipse link it gives takes me to a bunch of Eclipse downloads that are all version 3.6. Following a couple links from there I arrive here to get the latest release of 3.5. But which package do I want? Not only are there several Eclipse packages, each one has three Mac versions.
Googled around a bit to try to get some help with this. These two posts on Zviki Cohen's blog were just what I needed to pick which of the three Mac versions of Eclipse to use. For me, Mac Cocoa 32-bit. I picked the Eclipse IDE for Java EE Developers as it had the most downloads and seemed to be the most comprehensive general version. So, that combo resulted in me downloading this package. Zviki's second post had an "Installing Eclipse" section, and I followed his recommendations. My workspaces folder I put under Documents/Development. I decided some time ago to try to keep anything I create somewhere under Documents. Eclipse ran fine after it was installed.
Instead of continuing to follow the Quick Start at this point I backtracked to the Installing the SDK guide which has more detail. It recommends using the "Eclipse Classic" package instead of the EE one I chose. Oh well. It seemed to be a suggestion rather than a must-have so I'll stick with EE package which looks like it might be a superset.
I unzipped the Android SDK I downloaded at the start, and stuck in it my Documents/Development folder. The SDK guide points to a page with instructions on installing the ADT plugin into Eclipse and that all went fine, just as described. Then I went back to the SDK guide and did the step where you you set up Eclipse to go download the rest of the SDK and get you the latest stuff. That all worked. Then I went back to the ADT plugin page and did the Configure step where you point the plugin at the SDK.
I don't recommend letting Eclipse check for new versions of things every time you start it, or every so often. It would be crazy-making to be in the middle of working on something or debugging something and have Eclipse pull the rug out from under you by changing things around. You can do manual updates when you know your project is quiescent and can take some disruption.
Located the Android development site. I'm starting from scratch, so I went for the SDK starter package. I'm on a Mac Pro running OS X 10.5.8 (not the latest; saw no reason to upgrade to Snow Leopard 10.6) so I downloaded the Mac zip file, getting me Android 2.2. The Quick Start follows on that page, and yeah, my System Requirements are fine. I assume I have a JDK installed (not sure how to check this) and if it turns out that I don't, I'll deal with it then.
I read (somewhere) that by far the easiest way to develop Android apps is using Eclipse and the Android Development Tools (ADT) plugin. The Quick Start points out that I need to stick with Eclipse 3.4 or 3.5 and not use the latest. Following the Eclipse link it gives takes me to a bunch of Eclipse downloads that are all version 3.6. Following a couple links from there I arrive here to get the latest release of 3.5. But which package do I want? Not only are there several Eclipse packages, each one has three Mac versions.
Googled around a bit to try to get some help with this. These two posts on Zviki Cohen's blog were just what I needed to pick which of the three Mac versions of Eclipse to use. For me, Mac Cocoa 32-bit. I picked the Eclipse IDE for Java EE Developers as it had the most downloads and seemed to be the most comprehensive general version. So, that combo resulted in me downloading this package. Zviki's second post had an "Installing Eclipse" section, and I followed his recommendations. My workspaces folder I put under Documents/Development. I decided some time ago to try to keep anything I create somewhere under Documents. Eclipse ran fine after it was installed.
Instead of continuing to follow the Quick Start at this point I backtracked to the Installing the SDK guide which has more detail. It recommends using the "Eclipse Classic" package instead of the EE one I chose. Oh well. It seemed to be a suggestion rather than a must-have so I'll stick with EE package which looks like it might be a superset.
I unzipped the Android SDK I downloaded at the start, and stuck in it my Documents/Development folder. The SDK guide points to a page with instructions on installing the ADT plugin into Eclipse and that all went fine, just as described. Then I went back to the SDK guide and did the step where you you set up Eclipse to go download the rest of the SDK and get you the latest stuff. That all worked. Then I went back to the ADT plugin page and did the Configure step where you point the plugin at the SDK.
I don't recommend letting Eclipse check for new versions of things every time you start it, or every so often. It would be crazy-making to be in the middle of working on something or debugging something and have Eclipse pull the rug out from under you by changing things around. You can do manual updates when you know your project is quiescent and can take some disruption.
What and Why
I want to learn how to program apps for Android. I started to do this a couple of years ago, but I tried to dive too deeply to start with and it was at a time when I was pretty burned out. It didn't take. So this time I'm going to take a gentler approach.
I want to do this because programming apps is a really good match for my programming skills and my interests. And when I do job searches for "embedded" on Dice most of the time there are job openings for people with Android skills.
I will write about the steps I take and how it goes. Good luck to me.
I want to do this because programming apps is a really good match for my programming skills and my interests. And when I do job searches for "embedded" on Dice most of the time there are job openings for people with Android skills.
I will write about the steps I take and how it goes. Good luck to me.
Subscribe to:
Posts (Atom)