Coding Academy - Android Get started - package R

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Coding Academy - Android Get started - package R

Postby Wooster » Tue Jul 19, 2011 8:04 pm

Hi,

I am having a problem compiling the "countdown" project. I created the project using "android", I copied the CountdownActivity.java and main.xml from the DVD and put them in the appropriate directories. When I run "ant debug" the project fails to compile stating "package R does not exist".

What do I have to do to overcome this problem?

Thanks.
Wooster
 
Posts: 2
Joined: Tue Jul 19, 2011 7:47 pm

Postby AndyBaxman » Wed Jul 20, 2011 9:53 am

I tend to use Eclipse for my Android dev work, so I can't tell you specifically how to fix your problem, but I can tell you what the problem is.

The "R" package is the compiled resource file generated from the resource XML files. In Eclipse the build scripts build it automatically when you run (and, therefore, build) the app.

You should have a "res" folder with sub folders like "drawable" and "values". These contain the XML resource definitions. For example you should see "strings.xml" in the values folder.

if strings.xml contains a definition for a string resource "foobar", then you can access in in your code using R.string.foobar once the resource has been compiled.

I imagine that you are not building the resource file. The tool you need to do this manually is called aapt (Android Asset Packaging Tool) and is in the SDK.
Bomb #20: "Let there be light"
User avatar
AndyBaxman
LXF regular
 
Posts: 523
Joined: Tue Oct 04, 2005 8:47 am

Postby Wooster » Wed Jul 20, 2011 6:48 pm

Many thanks for taking the time to reply.

I have now solved the problem although I still don't know what caused it.

Solution:
What I did was to remove the project, then re-create it, then copy the CountdownActiviy.java and main.xml to the appropriate folders and then I ran "ant debug".

When I first created the project I ran "ant debug" before changing the code. After I had modified the code I kept getting the failure.

Do you have to run "ant" in a different way if you have already built the binary once?
Wooster
 
Posts: 2
Joined: Tue Jul 19, 2011 7:47 pm

Postby AndyBaxman » Thu Jul 21, 2011 7:54 am

As I said, I'm afraid I don't use ANT, directly for Android development. I use Eclipse with the ADT plugin

It makes development, particularly resource editing, less of a grind.

If you do want to use Eclipse, you will need the "Eclipse for Java development" version. The Google info suggests the "classic" version will work, but it doesn't (missing dependencies).
Bomb #20: "Let there be light"
User avatar
AndyBaxman
LXF regular
 
Posts: 523
Joined: Tue Oct 04, 2005 8:47 am


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron