Using pydroid

This is a simple log of my experience with pydroid.  Not necessarily successful yet…still a work in progress.  Jump to the end to see where I am stuck.

Pydroid is a build tool for python apps on Android, using the Qt GUI framework.

I started with a more or less clean computer that is not a development machine (few programming tools already installed).

As noted in the pydroid documents, it only works with Linux.  I am using Ubuntu 13.10.

About Pydroid

Pydroid is a set of scripts, in the Python language.  It automates a build process that alternatively is tedious typing into the command line.  Python is a scripting language often used to automate such administrative or building work.  Alternatively, the build process could be automated using shell scripts.  Since you are a Python programmer, it makes sense to use Python for your build scripts, since you probably are weak at writing shell scripts.

Pydroid also seems to create a project for Qt Creator.  And the Pydroid command seem to find their way into Qt Creator?

The pydroid README file says it is a framework, but that word means something else to me.  Pydroid seems to be another SDK: a kit of tools (Python scripts) and template code, for developing an app.  As an SDK, it depends on other tools.

Dependencies

These are pydroid dependencies:

  • setuptools
  • pip
  • adb
  • Necessitas NDK

Necessitas had its own dependencies, these are Linux (Debian) packages :

  • build-essential (a basic suite of program development tools)
  • openjdk-6-jdk (a java development kit)
  • ant ( a build automation tool similar to make)

The Necessitas NDK includes the Android SDK and the Android NDK.  Thus you don’t need to install those.  However, the Android SDK that is part of Necessitas SDK as installed is somewhat dated.  The Android SDK package includes a tool for updating itself, the Android SDK Manager (a package installation manager.)

Install Dependencies

Install setuptools

The install script for pydroid needs setuptools. Download and install it with this command:

>wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | sudo python

Install pip

pip is another Python installation tool (why are there so many?)

I used the Ubuntu package manager (it probably understands dependencies better and might upgrade other packages that pip depends on.)

>sudo apt-get install python-pip

Install Necessitas NDK

Necessitas lets Qt be installed on Android.  Necessitas is a component of the Qt project.

Full instructions for installing NDK.

Install Necessitas dependencies

For each of [build-essential, openjdk-6-jdk, ant]:

sudo apt-get install build-essential

Invoke Necessitas installer

Browse to the download site, part of the KDE project.  Choose the download link.  That downloads an installer app.  Make it executable and execute it.

chmod +x necessitas-x.y-online-sdk-installer-linux
./necessitas-x.y-online-sdk-installer-linux

An installer ‘wizard’ app will appear (having a GUI.)  Step through the wizard’s panels.

When it is done, Qt Creator (an IDE) will start.  Close it, we will use pydroid from the command line.

Install adb

adb is the Android Debug Bridge.  It is a command line app that communicates from your host machine to a target Android machine.

sudo apt-get install android-tools-adb

Download pydroid

Navigate your browser to pydroid repository.  Click on the “Download ZIP” button (on the right side of the page.)

Unarchive the file.

Install pydroid

Change directory to the unarchived pydroid directory.  Pydroid is a Python application.  You must install it:

sudo python setup.py install

Start Using Pydroid

To use pydroid, you configure it, create a project, and deploy (build and deploy) the project.

One more prerequisite is that you have an Android device (AVD or real) to deploy to.

Edit the configuration file

As noted in the pydroid documentation, you need to edit a configuration file before you begin using pydroid.

Edit the configuration file:  ~/.pydroid/deploy.conf.

It might be owned by root, since you installed pydroid as root.  Change its owner to yourself. (Or edit it as root, you probably only need to edit it once.)

cd ~
sudo chown <loginName> .pydroid
cd .pydroid
sudo chown <loginName> deploy.conf

Change the dummy variables:

  • /PATH/TO/ADB (the path to the ‘adb’ program, typically ‘/usr/bin/adb’
  • /PATH/TO/NECESSITAS (the path where you installed Necessitas, e.g. ‘/home/<loginName>/Necessitas’
  • ARM-VERSION e.g. ‘v7a’

Create a pydroid project

Enter:

pydroid create app name:APP_NAME domain:COM.EXAMPLE

This creates a project directory called “APP_NAME”.  (You should make sure the current directory is a suitable home for that directory, and you probably will want to substitute for “APP_NAME.”)

The documentation says the project is now ‘already deployable.’  That doesn’t mean it is ready to distribute.  It means it is ready to run the “deploy” command.  The deploy command builds the app and uploads it to a device (virtual or real.)

Testing pydroid configuration

Invoke the “status” command of the pydroid app:

>pydroid status

It should display a list of configuration values.  Instead, you get this message:

This functionality is available from the root directory of a pydroid project only.

Apparently the “check” command does not check an installation, it checks a project, which is contrary to what the README says:

You can always check your system or your project with the following command

Note that ‘check’ checks a project, while ‘status’ checks the pydroid system (the configuration values it will use to build.)  Neither command will execute except when the current working directory is a pydroid project directory.  Change directory to the project you just created:

>cd APP_NAME

Now the status command should work and show you configuration values.

Build and deploy your app

Invoke the pydroid deploy command:

>pydroid deploy complete

In my session, I had never created an AVD using AVD Manager.  So I got:

BUILD SUCCESSFUL
Total time: 40 seconds
** deploying APK
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
– waiting for device –

So I killed the running pydroid app with a couple of Ctl-C keys.

Using Android tools, to manage AVD’s

As noted above, the Necessitas SDK include the Android SDK, which includes the ‘android’ tool for managing:

  • the Android SDK as an installable package (‘Android SDK Manager’ for package management)
  • Android virtual devices (‘Android AVD Manager’, a VMM for managing virtual machines.)

Invoking the Android tool

The ‘android’ tool is a command line tool with two command line options (for the purposes above.)

  • avd
  • sdk

To use the tool, for example:

>cd ~/necessitas/android-sdk/tools
>./android sdk

Invoking the tool brings up a GUI tool.

Updating the Android SDK

Start the ‘Android SDK Manager’:

>./android sdk

The GUI is an expandable tree of package that can be installed, and their current state of installation.

Check the checkboxes of the packages you want to install or update, and then choose the “Install Packages” button.

In my session, it showed that the ‘Android SDK Tools’ and others could be updated.  I did not choose to update them.

In my session, it showed that only Android API 8 and 10 were installed.  At the time, those API’s represent a fraction of the installed Android base (a majority of Android devices in use in the real world are the ‘Jelly Bean’ API, i.e. version 4.x.x i.e. API 14 through 17.  So I chose to install API 16.

The goal is an AVD that pydroid will be able to talk to.  I reasoned that the the older API’s were probably broken (and my initial attempts to create an AVD resulted in an AVD that wouldn’t boot.)

Note that after installing a set of packages, the Android SDK Manager usually suggests a few more packages to install.  I.E. installing is iterative.

Creating an AVD

See my other post “Understanding Android Emulators.”

Unfortunately, that describes starting the AVDM from inside the Eclipse IDE.  You can also start it from a command line: (It is part of the Android SDK, which is bundled inside Necessitas, which you installed.)

>./android avd

AVDM is a GUI app.   Use it to create an AVD.  (For example, I used “Nexus S”, “API Level 10”, “ARM(armeabi)”, “500” MiB for the SDcard, and “Use Host GPU.”)

(I think it is important to have a large SDcard configured.  I think your app is installed there, and the components can be quite large, and the error if it runs out of space might be obscured.  Don’t chance it.)

After creating an AVD, choose the “Start” button to start the AVD.  A window will appear showing the emulated window of your Android device.  It may take many minutes for it to boot.  It typically shows a blinking “Android” while it boots.

I confirmed that I had created and started a device with:

>adb devices

Which listed the named device I had just created.

Trying to deploy again

With your AVD running, change directory to your project directory and invoke the pydroid deploy command:

>pydroid deploy complete

It takes awhile, then finally it says something like:

BUILD SUCCESSFUL
Total time: 43 seconds
** deploying APK
Failure
785 KB/s (16573668 bytes in 20.601s)
pkg: /data/local/tmp/APP_NAME-debug.apk
Success
Starting: Intent { cmp=COM.EXAMPLE.APP_NAME/org.kde.necessitas.origo.QtActivity }

Then pydroid returns to the command line.

While or after that is happening, on your AVD’s screen, it shows “Installing”.  After the install completes on the AVD you will see

This application requires Ministro service.  Would you like to install it?

Choose the “OK” button.

Then the AVD should access the network and download a Qt library (that is what Ministro is, a package manager for an Android device that understands how to download in install dependencies.  Note that this strategy is unusual for Android devices, and strange to users?)

Debugging your app fails to find the Ministro service

On my first attempts, on the AVD I got:

Can’t find Ministro service.  The application can’t start.

On the AVD, I tried the browser app and found that the AVD could connect to the internet.

A little web searching indicates these possibilities (possibly outdated advice):

  • Ministro cannot be downloaded to an AVD because there is no ‘market’ for it?
  • Qt works better on a real device (eliminating the emulation layer)
  • Qt5.1.1 might behave better (and I’m not sure what version of Qt pydroid is using?)
  • you can install Ministro.apk and MinistroManager.apk in the AVD manually using adb (instead of going through Google Play i.e. a market)
  • you can install Qt in the AVD manually?

Figuring this out (whether Ministro SHOULD download itself, and why it doesn’t on an AVD) is not a high priority.  Assume it WILL work on a real device, and for the virtual device, download it manually:

Downloading Ministro to your AVD

On your development machine, download Ministro.apk from here.

Start you AVD using the AVD Manager.

Upload from your development machine to your AVD:

>adb install ~/Downloads/Ministro II v9.5.apk

That should print something like:

2067 KB/s (542653 bytes in 0.256s)
pkg: /data/local/tmp/Ministro II v9.5.apk
Success

I don’t know how the Ministro service is visible to an Android user.   Apparently not as an app.

Testing your app after installing Ministro service

Now in your AVD, click on the icon for your app “APP_NAME.”  Now it says:

APP_NAME needs extra libraries to run.  Do you want to download them?

(This is the Ministro service talking to you.  Ministro is a broker.  Your app asks Ministro for libraries.  Ministro negotiates with the user and acquires the libraries, then returns the libraries to your app.)

Click on the “OK” button.

You see a sequence of various progress indicators: “Extracting …” and “Downloading …”.  It takes several minutes to download many Qt libraries.

Apparently this step works on an AVD (whereas downloading the Ministro.apk does not on an AVD?)  I suppose the Qt libraries are in a “repository” and not in a “market.”

After the Qt libraries are downloaded you will see:

Hello world example.

Edit the following files….

This is your pydroid app talking to you.  Thats all it does: print out a message.  Hit the Escape key to exit it.

Start your app again, by clicking on its icon.  You will briefly see a “Necessitas” logo, then the message above.  That is, on second runs of your app, Qt libraries are already installed on your Android device and the app starts quickly.

From here

I use the PyQt binding instead of the PySide binding.  I hope to blog about swapping bindings in Pydroid.

Debugging: your app fails to ask for Ministro service

On my first attempts, on the AVD I got: “Unfortunately, APP_NAME has stopped.”

I just explored, and found I had:

  • made a typo in the build.config
  • had specified ‘v7a’ in the build.config  but configured an AVD with the x86eabi

I tried to uninstall the app on the AVD

Using an AVD

Tips:

  • use the mouse (instead of a finger)
  • use the Escape key as ‘back’ i.e. the one physical button on many mobile devices.
  • use “Page Up” to unlock the device (when the lock icon is visible.)

To uninstall an app:

  • from the main menu (a grid of icons), choose “Settings”: a menu will
  • choose the Device>Apps menu item: a list of installed apps will appear
  • click on the app you want to uninstall: a dialog will appear
  • choose the “Uninstall” button
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s