Tuesday 15 July 2014

Unable to add google play services library to the android project in eclipse and/or it shows as red cross.


Problem: When you try to add google-play-services_lib project to your android project in eclipse, it lets you
add it , but when u check back it show as a red cross with a question mark.

Soln: This could happen for three reasons:

1. The project.properties file of your project is read only. Sometimes by default (specially in widows 8) eclipse files are in read only stage and so when you add google play services  library from eclipse ui it is unable to edit the project.properties file and fails silently.

How to fix:

To fix this rt click on project.properties go to properties and check if the file read only check box is checked. If checked , uncheck clean build and re add the library.

2. The project.properties file is placed in an inaccessible location in your computer.

how to fix:

Restart your eclipse and run it as an administrator. Or
Change the location of your workspace.

3. The google play services library project is not imported properly into your workspace. This happens most of the time ,  if your project is kept in a different drive than your sdk tools folder. Eclipse while trying to import library sometimes (most of the times) changes or misses some file in the library. To verify this rt click on the imported library and check the size and file count , it would be different from the orginal copy of the library in sdk tools folder.

How to fix:

Create the workspace in the same drive as that of sdk installation, Or
copy the library project manually into ur workspace and then add itfrom there. Dont usethe eclipse import wizard.

Saturday 12 July 2014

how to build an android project in eclipse from command line using ant?


case: to build an android project in eclipse from command line using ant.

Soln:

Before starting I assume you have a running android project in eclipse. Now.

1.  Before even touching ant , first make your project  'ant ready'. To do this:
     Open command line and navigate to <ADT ISTALLATION>/sdk/tools directory.
     Run the command android update project --path <Complete path of your project directory>.
    Doing this will add build.xml file in your project. This file is read by ant during build.
    Do this for all library projects that you have.
    Doing this will make your projects 'ant ready'.
 

2. Now install ant latest version from here and set the relevant environment variables.
   http://ant.apache.org/bindownload.cgi
  If you use an old version of ant then there are chances of conflict with your adt installation.

3. Create a file named ant.properties file in you root folder of main project and specify your keystore          information on it like this:

  key.store=< your keystore file location>    (make sure u use forward slash '/' between folders)
  key.alias=<alias name>
  key.store.password=<store pwd>
   key.alias.password=<alias pwd>

If you dont specify the passwords, it will prompt you during the run and you can enter it on the command line.


4. Navigate to your project root directory in cmd line  and run the command:
       ant release

5. Wait for the build to run. After completion you will see build success in your screen. Go to the bin        directory of your project, you will see your_project_name-release.apk file. The fruit of all your effort.






Android build fails with ant on eclipse project says - "invalid resource directory name: [...]/google-play-services_lib/bin/res/crunch"


case: when you try to build and an eclipse android project externally using ant, it fails saying the crunch inside the bin/res/ folder of google-play-services_lib is not valid.

soln: what the heck is the crunch folder , is yet to be investigated, as long as it is in bin folder I dont give much importance to it. There is a bug for the same issue here

https://code.google.com/p/android/issues/detail?id=60496

but the bug status at the time of writing this was new.

So how to fix it?

Disable automatic build in eclipse project temporarily, delete the crunch folder, run the ant script. Done -Simple.
Enable the auto build again when you are coding.

If you are using ant from command line then do a 'ant clean release' instead of 'ant release'.