Wednesday, March 27, 2013

XP-Dev.com, Eclipse, and GIT

I wanted to use Eclipse with GIT and XP-Dev.com on Windows 7. Turns out this is more of a pain that I had originally imagined so I've written it here for future reference - and perhaps to help anyone else having this pain.

It didn't matter what I tried I couldn't get the HTTPS URL provided by xp-dev.com to work, which leaves us with SSH. I won't bother with all the other things I tried, but these steps finally worked.

Prerequisites

GIT (and the GIT Bash)
Eclipse
EGIT
An XP-Dev account

Steps

  1. Open Git Bash.
  2. Type ssh-keygen and press enter to all the questions. Make a note of where the file is saved.
  3. Open the file and copy the pass key but not the other stuff to your clipboard. That means everything in-between the "ssh-rsa" and your "username@computer".
  4. The folder path that the file is dumped to is the same file path that's in Eclipse's Preferences, General -> Network Settings -> SSH2 [SSH2 Home].
  5. Go to XP-Dev.com, select Dashboard, then "account" at the top right.
  6. Select "View Profile In Detail".
  7. Under "Add a New Public Key" give the key a name (doesn't matter what), then paste the key and save it. Any error messages means you copied the wrong part of the key (see step 3).
  8. Go back to your Git Bash.
  9. Type ssh @xp-dev.com. It should tell you "all shell logins disabled". That's fine because it means we at least got authenticated. 
  10. Go to the project in Eclipse you want hosted at XP-Dev.com.
  11. Make sure that this project is in it's own local GIT repository. If it isn't already, then follow the EGIT Getting Started Guide.
  12. Select Team->Remote->Push...
  13. Enter the URL which should be something like: ssh://@git.xp-dev.com/. Enter your password and select Next.
  14. Enter the other details that you want to push - I just selected [master - branch] under Source Ref, and then "Add Spec" and Finish.
  15. Hope it all works!

One Other Thing Of Note

  • I added the file generated in step 3 to the list of private key settings in Eclipse's Preferences, General -> Network Settings -> SSH2, but I don't believe I should have or it makes a difference. However, I'm not taking it out now it works.

Wednesday, November 9, 2011

Experience and Lessons Learned Publishing First Android App

Yesterday I published my first ever Android application to the Android market - Say It!. It's hardly ground-breaking, but I just wanted to get an application on there and have gone through the process before I went on to more fun things. "Say It!" just lets you type in some text and have it spoken back to you, which is pretty simple given Android's Text-To-Speech Engine.

It's important to note that it's taken me a long time to actually get an app on there, having previously wanted to think of THE idea that no-one else has thought of that was going to make me a fortune, and slowly realising that's never going to happen, that it doesn't matter if someone else has already done it, and that you can still add your own angle. In my case, I noticed most of the other text-to-speech apps looked pretty bad so I went to some effort to make it look good.

I want to summarize my experiences here as a reminder/reference for myself and possibly as a help for others. First up...

Tax Status
As far as I understand it, you need to be registered as a company in order to sell apps on the Android app store (and for the Apple app store). For an individual developer who is employed normally, and is just doing a few apps "on the side", this means you're going to have to register as self-employed. You can register as a sole trader, a partnership, or a limited company, but if it's just you then you probably want to just be a sole trader. Some points about this (this applies to the UK only):
  • You can be registered "self-employed" and still be payed via PAYE normally. You still have tax deducted in the normal way as you always have from your salary, but you also have to fill in a tax return for all your extra earnings (and expenses related directly to those earnings).
  • Your tax status is personal to you, you do not need to tell your employer, and they will not be informed via the tax office. Your employer can't find out if you're registered self-employed or not because that's your private information.
  • However, you will have to check the contract you signed with your current employer, which may be very restrictive. At the very least, it would be a good idea to inform your employer of what your intentions are so there's no confusion. You have signed a contract and you have a duty to honour that contract. Ideally you want an agreement written down and authorized by someone who matters. This might not be your team-lead-who-you-also-get-drunk-with-on-Friday-nights, but instead the HR-department-you-don't-really-get-on-with.
  • It's ridiculously simple to set your tax status to self-employed. You can do it online, just go here and look under "If you're self-employed and will be dealing with your own tax affairs".
  • If you register self-employed you'll have to file your own tax return, which you can also do online, and you'll also be charged £2.50 a week National Insurance.
  • If you earn less than £5,315 (as of this tax year) then you can claim an excemption from NI, see here. You will have to print off a form and mail it in by hand. Notice they don't make it as easy to get an excemption from NI as they do to sign up for tax...
  • If you earn more than £73,000 (you lucky dog), you'll also need to register for VAT. I don't know much more than that as it seemed like it was a bit unlikely. 
  • Remember that these numbers do NOT include your current salary. It's treated as a completely different thing.
  • Once you register, you will be sent a Unique Taxpayer Reference. You will need this when you open your AdMob account for serving adverts (that's your Local Tax ID), or your Google merchant account if selling apps.
  • I am not an accountant, so make sure to check this information out for yourself. This is just a record of my experiences, not financial advice.
Development
I've had plenty of Java experience and so developing with Android was fairly easy to get into. I would think it would be reasonably easy for most people with any C++/Java/C# or similar to get into. Perhaps what helped me more was the Eclipse experience. A couple of points though:
  • Layouts! Argghh! My kingdom for a decent layout system! No one understood it in Swing, Windows Forms were crap, and XAML is just as bad. And lets not start on CSS. Android layouts are just as horrible and it's gonna take a little time to learn.
  • android:windowSoftInputMode="adjustNothing" in your activity element in your Android.manifest file means "don't screw with everything when the soft keypad comes up like you usually do".
  • I spent most time creating the "Say It!" button, as I'm not a graphic designer. I think it's definitely worth spending the time to make your app look good.
  • You're probably going to need a Preferences or Settings screen, so make sure you look up the Android Preferences instead of trying to do your own.
  • Ensure you know what Intents are and use them for switching between screens. This tutorial seems to cover it pretty well.
  • I wanted to serve ads with this, and chose to go with AdMob. It seemed like the de-facto standard ad provider, although I didn't do much research to be honest. Adding the code was as simple as adding a jar file to the build path and putting an element into my layout XML. Don't talk to me about layouts, though, grr....
Deployment
This was a fairly pleasant process. You just need to sign up with AdMob, although I used my google account. You'll need your Unique Reference Number as your Local Tax Id, and everything else was pretty simple.
You'll also need to join the Android Market to publish your apps, which will cost you $25 (£15.50 in real money), and you're going to have to jump through a few hoops to get it on there:
  • Keystore. You have to sign your app which you can do straight from Eclipse. If you don't have a keystore then you're going to have to create one and add a key for your app. Then you'll get to spend some time wondering what your "organisational unit" is.
  • The store requires images in various sizes to represent your app. You will at least need a 48x48 (which will be your icon) and a 512x512 image (PNG is fine). I just used the work I'd done for the button.
  • Description. I think it's worth spending some time on the description, unlike me. Although you can change it later. I believe this should be treated in the same way you'd treat Search Engine Optimization for a web page - think of key potential search words and organise them into sentences. Some research on this is necessary I think. I was suprised I wasn't allowed to add keywords.
After Publishing
So I put my app up and what happened?
  • I've earned $0.04 in ad revenue! I'm oddly happy about that and I'm not sure why, maybe it's because it's more than zero.
  • I have had two reviews - one from a friend who downloaded the app and thinks he's hilarious (thanks mate :)), and one from someone who said it was "cool and decent", but then only gave it 3 stars. Three?! Why three?! Surely "cool and decent" is at LEAST four?!
  • I have no idea how someone came across my app (besides being told directly to download it), because I can't find it even if I type in "Say It!" as the search terms. Perhaps they got there from the link I posted on Facebook, although I don't recognise the name.
  • I didn't realise how attached I would get to it, and am constantly checking the reviews to see if anyone else has commented. Especially since this was almost a "throwaway" app just to go through the process and find my feet.
  • The Android Market gives you some great stats. It's fascinating to see that people have downloaded it from lots of different countries already, after only one day.
Lessons Learned
  • Don't get so attached to the application. Treat reviews and comments as useful information and nothing more.
  • Spend more time learning the layout system (that which is difficult you should spend longer on so you get it right).
  • Spend more time learning how to optimize the description for search terms - I'm sure there must be some advice on increasing the profile of your app out there somewhere. Which makes me think of this guy. Although I'm afraid I'm not going to fork out for his ebook just yet until I've had a good search around.
    UPDATE: It appears that you should identify your keywords very early and then use them in the description (a bit like you would in the text of a web page for SEO), and more importantly, include them in the title.
  • Creating a simple app to get my feet wet and go through the process was a really good idea.
UPDATE: I just checked and it's up to $0.10! Eeek!

Saturday, March 12, 2011

Open GLES 2.0 - Dumb Shit To Check List

Below is a series of things that you need to check when creating applications for OpenGLES 2.0. These are the things that may cause lots of pain but might not necessarily cause the program to crash, instead just giving "weird" results. This is what I found when developing for OpenGLES 2.0 on Xperia X10i with the Android NDK(r4):
  1. If you declare an attribute in the vertex shader, but don't use it, it can be optimized out. Which means that if you try to bind a variable to it, it won't be available to bind to.
    In Vertex Shader:
    attribute vec4 myattr; // no further references

    In code:
    int myattrHandle = glGetAttribLocation(shaderProgramID, "myattr");
    // myattrHandle == -1;

    // which means that later on if you try this, you're gonna generate an error
    glVertexAttribPointer(myattrHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) someArrayOfMyAttr);
    This can be frustrating if you're just checking that you're getting your values in to the shader whilst you're creating your shaders.
  2. The unwanted rainbow effect. Make sure your array sizes are spot on. For example, you declare this:
    float colors[] = new float[12];
    float vertex[] = new float[16];
    float indices[] = {1,2,3,2,3,4};
    // ...populate colors and vertex and indices....
    // ...call your glVertexAttribPointer() to add colors and vertex. Even though there aren't enough colors per vertex, THIS MAY SUCCEED WITHOUT CRASHING

    // make the call to glDrawElements()
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
    (const GLvoid*) &indices[0]);
    Now what happens is, you don't have enough colours in your color array for each vertex, so OpenGL just uses whatever it finds in memory at the place where the colours SHOULD be and uses that. Naturally this is entirely random and you usually end up with a "rainbow" effect, and it's different each time you run your app. Sometimes your app will crash anyway, but not always, presumably when another program tries to use that memory.
  3. If you are declaring your shaders like this:
    static const char* vertexShader = " \
    attribute vec4 colour; \
    attribute vec4 vertex; \";
    then you can't put comments in the shader with //. I'm not sure why, this may be something to do with C++, or the NDK, or GLSL itself; but this will invalidate your vertex shader and you'll end up with "Invalid vertex shader, cannot link program"
  4. If you specify a uniform in your vertex shader, and then try and get hold of it with
    glGetAttribLocation by accident instead of glGetUniformLocation, then it won't crash, there won't be an error produced in the log, you just won't be able to assign a variable to your shader when you render.
  5. ...to be continued...