Monday, February 2, 2015

Cordova Android Build Failed (build.xml)- Using old SDK path (Cordova Update Android SDK)


Recently in one of my cordova project I faced an issue. When I created a project, I was using adt-bundle-mac-x86_64-20131030 SDK. Later I upgraded my SDK to new one adt-bundle-mac-x86_64-20140702. Everything was working good since I updated this new SDK path in my .bash_profile file So creating new project was working.

After few months I have to add a new cordova plugin in project which I crated with old sdk. Plugin was added but when I tried to build android project, the build was failed since it was referring to old SDK path which does not exits anymore. I spent an hour to look for a solution to Google but could't find any solution. Later I checked build.xml file and found out that it was using env.ANDROID_HOME  variable to get SDK path. I added following two lines in .bash_profile.

export ANDROID_HOME=/Users/hirendave/Desktop/adt-bundle-mac-x86_64-20140702/sdk

export PATH=${PATH}:${ANDROID_HOME}/tools:${env.ANDROID_HOME}/platform-tools

And tried to build again but it was not working. Again I spent some time to find out a solution on Google but could not get it working. I again checked build.xml and suddenly following line caught my attention.

            message="sdk.dir is missing. Make sure to generate using 'android update project' or to inject it through the ANDROID_HOME environment variable."

I tried to search local. properties files, it was not there. So I generated it with android update project. Following are exact steps you need to do. First go to your cordova project directory and run following commands.

cd platforms
cd android
android update project -p .

This will update your android project and generated new files with latest SDK path and other configurations.

Now go to CordovaLib project and repeat the same steps.

cd CordovaLib
cd android update project -p .

This will update your CordovaLib project and generated new files with latest SDK path and other configurations.

That's it now run following command and it will build successfully.

cordova build android

Hope this helps you and saves your time.

No comments:

Post a Comment