Sunday 29 July 2012

Android and NDK[ VS Android ]

Hello World!
Well, i don't know what introduction to give to this topic, but the main idea is to use C/C++ code to develop Android applications with Visual Studio. This post is not about what the NDK is or how to write applications. This is a post just on how to get started.

I googled around a little, found some videos on YouTube. Most of them suggest using the typical Eclipse way. But i am more used to Visual Studio and was looking for a way use it for writing code for Android. And there is a way to do it!

  \m/   VS Android  \m/

There was some searching i had to do in order to get this working. But all in all, it was quite easy to actually get started and build an Android app. All thanks to Google(not referring to the search engine :D) and the guys who develop the Android SDK(oh and of course VS Android guys!),  I was able to get stared on a simple app in about 3 days(including time for downloading all necessary stuff, plus i wasted some time too.). So, quite an easy task. But, i had not found a single place that explained(and provided links) in order to get started. So, i thought of writing a post here!

So, here it goes:

(i) Downloading the SDK and other dependencies:

1) Download the SDK

2) Download the NDK
3) Download Cygwin

4) Download the JDK

5) Download VS 2010.  This version is very essential because VS Android is not compatible with any other VS version

6) Download VS Android

7) Apache Ant download

8) Set environment variables:
  [ To set environment variables, do:
    MyComputer->Right click->Properties->Advanced->Environment variables. 
  ]
      a) ANDROID_NDK_ROOT = <install_path>:\android-ndk-r8-windows\android-ndk-r8
      b) ANT_HOME  = <install_path>:\apache-ant-1.8.4-bin\apache-ant-1.8.4
      c) JAVA_HOME = <install_path>\Java\jdk1.7.0_05
      d) _JAVA_OPTIONS = -Xms256m -Xmx512m

Make sure you have set your environment variables correctly.

And that is it! Using VS Android, things are so much easy!

---------------------x ---------------------

(ii) Download samples from the VS Android download site:
http://code.google.com/p/vs-android/downloads/detail?name=vs-android_samples.zip

Put your device into debug mode and then plug it via USB and build your app. It should run on the device.

---------------------x ---------------------

(iii) Errors that you might face:

When i tried to build my first program, i.e the sample provided by VS Android, i got the following error.
Unable to resolve target 'android-4'
This can be solved by changing the following in the project.properties file:
target=android-xx
Set this to the proper version to get rid of the error.
 Well, this was the only error i got. In fact i had another error. But that was solved by changing an environment variable. I had to edit _JAVA_OPTIONS to add an entry. But since i have already provided both the environment variables, it should work just fine.
---------------------x ---------------------

 (iv) Some tools that might come in handy:

1) ADB pusher:  This can be used to transfer files to your device very easily:

2) You can find some nice tools at
<install_path>\Android\android-sdk\platform-tools
---------------------x ---------------------

Well, i hope that this was of some help. Using VS Android was certainly a LOT easier than the usual Eclipse path. It feels "at home" using Visual Studio :D. Many of you maybe used to using Visual Studio and this is the best solution(i feel) available.


I have added a video of a sample program that i wrote: I used the the hello-gl2 project. wrote code to do some simple animation. The phone is a Samsung Galaxy Ace.
---------------------x ---------------------

I hope this helps. If there is something wrong in the information, or if there are errors you face after following this, kindly let me know. I will modify this. If there is anything else, please leave a comment.

Bye!

---------------------x ---------------------
(v)Some useful links:
1) http://www.youtube.com/watch?v=5yorhsSPFG4
  A Google I/O video

2 comments :

  1. Hi bro !!! The best article i have seen so far android with Visual Studio........

    If i include cocos2d-x setup of visual studio and work for android then debugging will work ?

    ReplyDelete
    Replies
    1. Hi techGuy,

      I'm sorry, your comment had been reported as "spam" by blogger, so i hadn't seen your comment. About your question, i have never used Cocos2d-x with Visual Studio, so i have no idea about that.

      Delete