Android Novice – Unable to build android project?

Eclipse not creating .R in gen folders

  1. Clean and refresh
    • Right Click on Your Project
    • Select Refresh
    • Select Project from Top Menu and press Clean
  2. If project error is still shown. Delete gen folder and do the above step

Invalid Java compiler error

  1. Right Click on Your Project
  2. Select Properties
  3. Select Java Compiler
  4. Check Enable project specific settings
  5. Compiler compliance level should be 1.6

Suppressing Lint Warnings

  1. Right Click on Your Project
  2. Select Properties
  3. Select Android Lint Preferences
  4. Select Ignore All
  5. Select Apply

Importing the right .R file

We mainly have 2 R files.

  1. One is specific to our Project. For example if com.ourcompany.myproject is our package name, then the import should look like
    import com.ourcompany.myproject.R and this import helps our class to refer to our project specific resources (drawbles, layouts, styles, values etc) coming under the res folder.
  2. One is default to Android. The import should look like
    import android.R and this import helps our class to refer to all the default resources(like R.anim or R.simple_list_item_1) part of android

How to solve the issue

  1. Check your imports.
  2. If there is an import line like import android.R remove it.
  3. Instead of that add import yourpackagename.R eg. import com.ourcompany.myproject.R

import android.R;
import com.ourcompany.myproject.R;

Missed to add jar files or jar files not in the right location

For more info please go through How to add jar files. In some sample projects downloaded from different sites, the jars may not be properly linked. To solve that follow the below steps.

  1. Right Click on Your Project
  2. Select Properties
  3. Select Java Build Path
  4. Select Libraries
  5. Select Add JARs
  6. Select the jar files which needs to be imported from libs folder

Library Project not properly linked

For more info go through How to link/add library projects to our app.

Usually happens when we checkout code from different version controls and the library project path in our system doesn’t match with the code we checked out.

  1. Right Click on Your Project
  2. Select Properties
  3. Select Android
  4. Scroll down to Library section
  5. Check whether there is a red cross over there. It means one or more library projects are not properly linked. Reason may be
    • Invalid library path(usually when we checkout code from another location)
    • Library not imported to eclipse workplace

Happy new year and happy coding guys 🙂
Have a great year ahead!!
By Suslov Babu

Advertisements

One thought on “Android Novice – Unable to build android project?

  1. Pingback: Android Novice – Unable to build android project? | High on Science & Tech - H.O.S.T

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s