Tuesday, 13 January 2015

Ant - Running a task in a infinite loop

Ant is a task runner which by specifying different targets, it can run it and show the possible results.
Here is a trick to make it run a task in a infinite loop.

1. Download the antelope jar
1.1 Go to the home page of Antelope and download the antelope tasks jar. At the time of written this post the last version is 3.5.1
http://antelope.tigris.org/servlets/ProjectDocumentList?folderID=0&expandFolder=0&folderID=11184

1.2 Copy the jar file into the Ant library. For Mac OS X Yosemite it has the follow path:


/opt/local/share/java/apache-ant/lib

2. Config the Apache Ant build.xml
2.1 Open the build.xml of Apache ant and add the follow sentence on header, in the same line of project sentence:

xmlns:antelope="antlib:ise.antelope.tasks"

2.2 From the task you want to repeat, enclose it with the follow sentences:

<antelope:repeat count="-1">
    <!-- Tasks go here -->
</antelope:repeat> 

Note that optionally you could save the jar file download in the step 1 to another directory. In that case you should execute the ant command with -lib option. For instance:

ant mySuperCoolTask -lib PATH_TO_ANTELOP_LIBRARY

In case you want to just loop a finite number of times, just replace -1 of the step 2.2 with the number of loops you want to run.

The repeat command also has several options. Check the official manual for more information:

Source

Thursday, 8 January 2015

Running Monkey Talk on Android Project with Ant

In this post I explained the steps to do to integer the Monkey Talk with the Android project. Now it is time to explain the steps to make it run with Ant.

1. Download the AspectJ library
1.1 Go to the AspectJ download web page and download the latest stable jar. At the time of written the version is 1.8.4.


1.2 Unzip the Jar and put it on a folder. In Unix based system you just have to type the follow command:

jar xf aspectj-1.8.4.jar

Remember the folder where it is.

2. Generate Apache Ant files.
Create the Build.xml file and ant.properties file with android tool, if you have not done it yet. You can find more reference here:

3. Get the custom_rules.xml
3.1 Download the Monkey Talk package from here if you have not done it:
3.2 Unzip the file.
3.3 Copy the custom_rules.xml file in the samples/android folder to the same folder where Build.xml file were generated before.

4. Invoke Ant
From the console or terminal, type the follow:

ant clean debug -Daspectj.dir=PATH_TO_ASPECTJ_FOLDER

Where PATH_TO_ASPECTJ_FOLDER is the path to the aspectJ folder downloaded on the first step.

Source:


Wednesday, 7 January 2015

Running Monkey Talk on Android

The feature tests are the tests used to replace the human interaction with the machine. They simulates user click and swipes on the screen and then, get the results. This is very useful because it could detects errors that cannot be detected by simple unit tests.

In this sense, there is a tool called Monkey Talk. It is provided by Cloud monkey which by running a set of scripts called Monkey Scripts, which is based on JavaScript, simulates all the possible actions that a user can perform. It works both with simulated and physical devices and the same script works for Android and iOS. Another cool feature is with its IDE, the user can record the action so, there is no need to coding to create a test.

Since Monkey Talk has its own IDE which does most of the work, the first step to use it is download and install the Monkey Talk IDE, which is based on eclipse.
https://www.cloudmonkeymobile.com/download/monkeytalk-community

Once it is downloaded and installed, we should modify a bit the project to connect the IDE with the app.

1. Download the AspectJ Development Tools plugin for eclipse.
1.1 Find the right download link depending on your eclipse version from the follow page:


For different version of eclipse, they have different download links. If you are using the version 4.4(Luna), this is the link:


1.2 Once we get the right link, copy it and go to eclipse, click on Help -> Install New Software.
1.3 Paste the link and click on Enter.
1.4 Select all the packages and click on Next, accept the contract and finish.

2. Convert the Android Project to AspectJ project
Now the unique thing you should do is right click on your project, select Configure -> Convert to AspectJ project.

If you don't see this option check if AspectJ has been installed correctly. If you still don't see it, try to restart eclipse.

If you have libraries that are used by your main project, you don't have to convert them. By converting the main project to AspectJ project will be enough.

3. Includes the Monkey talk Agent library
3.1 Copy the library
From the folder downloaded from Monkey talk, there is a folder called agent. Inside that folder there is another folder called android. It contains the jar file called monkey-agent and the actual version of it.  Copy that library to the lib folder in the Main Android project.

3.2 Now from the eclipse, refresh the project and find the monkey agent library under lib folder. Right click on it and select AsjectJ Tools -> Add to Aspectpath

4. Update the permissions
The bad thing about Monkey talk is it add new permissions. It requires two permissions: Internet and Get task. To do it, add this two lines to your Android Manifest file:


    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.GET_TASKS" />

5. Export libraries
5.1 Right click on the main project and select "Properties"
5.2 On the pop-up windows, select "Java Build path"
5.3 On the right side, select the tab "Order and export"
5.4 Check the "AspectJ Runtime Library"
5.5 Beside this, try to also check the "monkeytalk-agent.jar". If by exporting the Monkey talk agent jar you see "Dextification error", you should uncheck it.

With this you should be able to compile and run your project, which include the Monkey talk agent in it. To test it, just open the Monkey talk IDE and click on the Android button at the top. If you have set Monkey talk correctly in your project, you will be able to see the record and play button near tot he Android button as follow image.


Here is a short video



Source:
Cloud Monkeys - Installing the MonkeyTalk Android Agent

Wednesday, 17 December 2014

Bring an App to front using command line

An easy and simple solution to bring the App to front screen:

adb shell 'am start -n your.package.name/.YourActivityName'

Source
Incise.org - Android development on the command line

Tuesday, 16 December 2014

Configure Jenkins for Android - HockeyApp automatic upload

One of the benefits with Jenkins is with some extra plugins, it could automatise actions such as upload the app to test. This happens with the HockeyApp plugin, which allow the user to upload the compiled file to HockeyApp.

The steps to do it are:
1. Install HockeyApp plugin for Jenkins
1.1 On the main page of Jenkins, click on "Manage Jenkins" -> "Manage Plugins"
1.2 Click on the tab "Available"
1.3 Check the checkbox of "HockeyApp Plugin"
1.4 Click on "Download now and install after restart"
1.5 On the new screen, check "Restart Jenkins when installation is complete and no jobs are running"

2. Create a new app in HockeyApp
2.1 Log in or register yourself in HockeyApp
2.2 On the dashboard, click on "New App". You could fill the data manually or upload an old version of your app.
The new app will have an App ID. Remember where is because Jenkins need it.
2.3 On the top right, click on "Account settings"
2.4 On the bottom left, click on "API Tokens"
2.5 On the "Create API Token" block, select the new app, the right (I have chosen Full access) and enter a name.
A new API Token will be generated at the bottom. Copy it.

3. Config Jenkins
3.1 On Jenkins, go to the configuration page of your app
3.2 On the block "Post-build Actions", click on "Add post-build action" and select "Upload to HockeyApp".
3.3 A new configuration screen will appear. Fill the API Token with the token copied on the step 2.5.
3.4 On the field "Upload Method", select "Upload Version" and paste the App ID created on the step 2.2.
Other options could be set, but with App Token and App ID, Jenkins can upload the app to HockeyApp correctly.

Monday, 15 December 2014

Configure Jenkins for Android - Lint

Lint is a great tool created by Google to analyse the code for Android. It comes with the SDK of Android and it is useful to have good quality code.

Jenkins integrates Lint plugin which could be used to show result of Lint. To run Lint on Jenkins follow the steps:

1. Install Lint plugin on Jenkins
1.1 On the main page of Jenkins, go to Manage Jenkins -> MAnage Plugins
1.2 Go to "Available" tab
1.3 Look for a plugin called "Android Lint Plugin". Check it and click on "Download now and install after restart"
1.4 On the new screen, check "Restart Jenkins when installation is complete and no jobs are running"

2. Configure Jenkins to run Lint
2.1 Go to the configuration of the job on Jenkins
2.2 On the Build block, click on "Add build step" and select execute shell
2.3 Paste the follow command on the dialog

# Run lint
$ANDROID_HOME/tools/lint --xml lint-results.xml .

Make sure that the variable $ANDROID_HOME is defined.

This command will run Lint in the workspace directory and put the result on a xml file called lint-result.xml

3. Configure Jenkins to show Lint result
3.1 In the same page of configuration of the job, look for the block called "Post-build Actions"
3.2 Click on "Add post-build action" and select "Publish Android Lint result"
3.3 Fill the filed called "Lint files" with

lint-results.xml