Páginas

sábado, 25 de enero de 2014

Signing your app to publish on Google Play (with Google Maps)

Hi everyone !

Today, I want to show you how to sign your application before to publish on Google Play, in another words, we have to write internally that you are the developer of that app.

STEP 1: CREATE A PRIVATE KEY

When we was debugging the application, we generated a debug keystore. Now we have to create a new one. To do this, go to "bin" directory on your JDK (Java Development Kit) folder. We need a tool called "keytool" that it is in this directory and write the following:
keytool -genkey -v keystore <path_for_the_new_key> -alias alias_name -keyalg  algorithm_key -keysize key_size -validity validity_days
For example:
keytool -genkey -v keystore C:/Users/danigonlinea/new_key.keystore -alias danigonlinea -keyalg RSA -keysize 2048 -validity 15750

NOTE: If you have not installed it, you can do it in this link: JDK.

STEP 2: OBTAIN SHA1 AND MD5 FROM THE KEY TO GET GOOGLE MAPS API KEY

First thing we have to do is to sign the maps on the application, we need to obtain the api key. To this way, our future users can use the maps in the application. If you have not maps on your application, you can jump this step and keep reading after this step.

keytool -list -keystore <path_new_key_created> -keypass password_key -v
For example
keytool -list -keystore C:/Users/danigonlinea/new_key.keystore -keypass perico_palote -v

STEP 3: PUT THE SHA1 ON GOOGLE DEVELOPER CONSOLE

Access to this website, link: Google Developer Console. You have to activate Google Maps and obtain a new Android Key for your application using SHA1. For more information, get in Obtain Google Maps API Key.

STEP 4: Export your Android application.

In ADT Bundle Eclipse, Go to File -> Export -> Export Android Application. Complete the wizard. Select the keystore that we had created in the first step and remember the alias name and password.

NOTE: if you get fail on the process, try to clean the project on Project -> Clean...
NOTE 2: remember to use a correct package for your source code on your project. It have to be unique on entire Google Play!

Finally, you have your app ready to publish on Google Play.

Using UI Automator Viewer and uiautomator for UI Testing on Android

Hi everyone !

Today I want to talk about UI Testing on Android. The project I am developing, I am using two tools very usefull for this job: UI Automator Viewer and uiautomator (from Android SDK). I want to show you how to start with on Windows ( if you are using GNU/Linux like Ubuntu, maybe some steps are different but it is the same deeply).

STEP 1: CHECK YOUR UI COMPONENTS.
Firstable, we need to check our visual component with UI Automator Viewer to take a look how our component is referenced. You can find it in "tools" directory on your Android SDK.
    Figure 1: UI Automator Viewer in action
You have to write (in a paper apart, for example) the name of the UI components that you can use to test. Take details from XML fields like "resource-id" or "content-desc" (Figure 1). In the image, you don't see anything in that fields but you can write what you want on your XML layouts from your application. Later we can see how to reference it in the test.

STEP 2: CREATE THE PROJECT AND ADD DEPENDENCIES.

Now, you have to make a new Java Project on your Android IDE (I use ADT Bundle Eclipse but I think the idea is the same). You need to add 3 files on your project:
  • uiautomator.jar and android.jar: Go to proyect properties -> Java Build Path -> Add External jar. You can find them on "platform/< Android version you are compiling your project>" directory in your Android SDK.
  • JUnit (library): Go to proyect properties -> Java Build Path -> Add Library -> JUnit (3 - I don't know if it is compatible with 4 version yet)

STEP 3: WRITE THE TEST CODE.
So now, you have to write your test cases that you want to test. Here you have a general view about the source.
 
public class TestCasesName  extends UiAutomatorTestCase
{

	protected void setUp() throws Exception {
		super.setUp();
                // for precondition statements
	}
 
	protected void tearDown() throws Exception {
		super.tearDown();
                // for postconditions statements
	}
	
	public void testnumberone () throws UiObjectNotFoundException
	{
		 // write your test case 1 here
	}
	
	public void testnumbertwo () throws UiObjectNotFoundException
	{
		 // write your test case 2 here
	}
	
	// and all of the test that you want to write.
}

STEP 4: CHECK YOUR ANDROID IDENTIFIER
Identify your android version in android list. For this, you have to go to "tools" directory on Android SDK and write in the terminal:
android list
Figure 2: android list
STEP 5:  GENERATE THE BUILD CONFIGURATION FILES.

You can check that in my list, I have android-18 for number 1, and android-19 for number 2. You have to choose Android version you are compiling. Now, write the next in the same directory:
android create uitest-project -n <name_test_project> -t <identifier_android_version> -p <path_test_project_folder> 
For example:
android create uitest-project -n HelloTesting -t 1 -p c:\Users\danigonlinea\Documents\Android\Workspace\HelloTesting

STEP 6: COMPILE YOUR PROJECT WITH ANT

Next you have to do is create (or updated if it had been created automatically) a file name build.xml. To do this, go to your test project folder and write:
ant build

NOTE: if you have not installed Apache Ant in your system, you have to. Here a link to do it: Install Ant Windows 7.


STEP 7: PUT THE .JAR FILE ONTO THE DEVICE

Now, you have generated a .jar file on your "bin" directory on your test project. Check it out. The next step that we have to do is to move that file into your emulator/smartphone.
adb push <path_to_output_jar> /data/local/tmp/

NOTE: In my case, it was useless because actually I am using the fantastic "emulator" for Android testing, Genymotion. I had a problem: I was not be able to have permission to write in this folder. Genymotion runs on VirtualBox so what I did was to create a folder and share it, so whatever I put on this folder, it could be accessible on Genymotion.


VirtualBox: Shared Folders
STEP 8: RUN IT!

We have the .jar inside the emulator so, let's run it !!. For this propose, you have to go "platform-tools" directory in the Android SDK and write:

adb shell uiautomator runtest <path_to_jar_file> -c <package_plus_name_test_name_to_run>

For example:

adb shell uiautomator runtest /mnt/shared/SharedFilesGenymotion/ikeComercialTesting.jar -c android.testing.testnumberone

That's all!. In fact, the .jar will execute on your emulator and you can see all the steps that you describe on your test code automatically, like a video. Finally, you can check the result of the test on the terminal.

Happy Testing !



Gow, Unix functions for CMD (Command Prompt) on Windows

Lastly, I am developing on Windows (it does not look like "wow this is horrible"; it is fine) since I had problems with graphic card on Ubuntu( shit!! I can not be able to turn up/down the bright !! ) and I have to say that the most tool I have missed is the terminal (yes, CMD really is.... no comments). So, I discovered a library on Github by Brent Matzelle called Gow that it is very usefull. I recovered some Unix commands thanks to that library and I can still use CMD. Take a look !! https://github.com/bmatzelle/gow