22. March 2014

Kivy – buildozer android debug failed with libstdc++.so.6: cannot open shared object file

Kivy is awesome library for developing GUI applications in Python.

It’s possible to build same application for desktop, Android or iOS. It’s something like Cordova/PhoneGap for JavaScript.

I was following Kivy crash course 2: Building an android apk tutorial recorded by Alexander Taylor.

I was trying to build application on Linux Debian for Android:

buildozer android debug

Build failed with quite strange message:

[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] Found 1 AIDL files.
     [aidl] Compiling 1 AIDL files.
     [aidl] /home/georgik/.buildozer/android/platform/android-sdk-21/platform-tools/aidl: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

BUILD FAILED

assets/private.mp3: /home/georgik/idea/kivytest/.buildozer/android/app/sitecustomize.pyo
Traceback (most recent call last):
  File "build.py", line 431, in 
    make_package(args)
  File "build.py", line 346, in make_package
    subprocess.check_call([ANT, arg])
  File "/usr/lib/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ant', 'debug']' returned non-zero exit status 1

The reason of this problem is not so obvious.

My operating system is 64bit, but Android build system requires 32 bit version of stdc++ library.

Fix is very easy. Just install lib32stdc++6 package :-)

apt-get install lib32stdc++6

If build is still failing, because of other missing libraries, then you can use online Debian package search to find missing dependencies: https://www.debian.org/distrib/packages

Other missing 32bit libraries are often libz, libncurses5:

apt-get install lib32z1 lib32ncurses5

29. June 2013

True/False gotcha Python vs Ruby vs PowerShell vs NodeJS vs PHP

Evaluation of conditions is very important part programming. True is ture, false is false…

Or not? It might surprise you, but not all languages evaluate numbers, empty strings or empty arrays in the same way.

Let’s examine several technologies. Python, Ruby, PowerShell, NodeJS and PHP.

Here is small code written in Python:

def test(value):
    if value:
        print "True"
    else:
        print "False"

test(0)
test(1)
test("")
test([])
test({})

Here is similar code written in Ruby:

def test(value)
    if value
        print "True"
    else
        print "False"
    end
end

test(0)
test(1)
test("")
test([])
test({})

Let’s compare it to PowerShell:

Function Test($value) {
    if ($value) {
        Write-Host "True"
    } else {
        Write-Host "False"
    }
}

Test(0)
Test(1)
Test("")
Test(@())
Test(@{})

Same logic in JavaScript for NodeJS:

function test(value) {
    if (value) {
        console.log("True");
    } else {
        console.log("False");
    }
}

test(0);
test(1);
test("");
test([]);
test({});

Code in PHP:

<?php 
function test($value) {
    if ($value) {
        echo "True";
    } else {
        echo "False";
    }
}

test(0);
test(1);
test("");
test(array());
test(array());
?>

Results are little bit surprising:

 

Python Ruby PowerShell NodeJS PHP
0 False True False  False False
1 True True True True True
“” False True False False False
[] False True True  True False
{} False True True  True False

26. May 2013

How to activate Python virtual environment in PowerShell

It’s quite easy to set up virtual a environment with isolated packages for Python in PowerShell. There are several methods

Method 1. Pipenv

This is the youngest and most convenient method. Pipenv automatically manages the environment and can create virtualenv based on the working directory. Files with virtualenv are stored in a separate directory and the user does not need to worry about them.

Install pipenv package:

python3 -m pip install pipenv

Enter the directory where you’d like to work and type:

pipenv shell

Pipenv will bootstrap and activate the environment. It will launch subshell. If you’d like to leave the environment simply close the shell by command:

exit

Method 2. Using embedded venv

Python 3 contains package venv. It’s often confused with virtualenv which is a standalone package to manage virtual environments. The advantage of the command is that you do not need to install additional packages. Just create a virtual environment in the directory like pyenv:

python3 -m pyenv 

Activate the environment:

.\pyenv\Scripts\activate.ps1

To deactivate the environment simply call:

deactivate

Method 3. Good old virtualenv

Creating a virtual environment with virtualenv is an old method. You need to create a directory that will contain the virtual environment and then activate it. virtualenv is not part of the default Python package, it’s necessary to install it:

python3 -m pip install virtualenv

Now it’s possible to create a new virtualenv in a directory like pyenv by the following command:

virtualenv pyenv

The last step is to activate this environment in PowerShell :

.\pyenv\Scripts\activate.ps1

You should see the name of your virtual environment in the command line. The virtual environment is active.

To deactivate the environment simply call:

deactivate

11. May 2013

Edge – invoke PowerShell from NodeJS

Project Edge allows seamless integration of NodeJS and PowrShell.

Just install packages:

npm install edge
npm install edge-ps

Create NodeJS application which contains PowerShell code:

var edge = require('edge');

var hello = edge.func('ps', function () {/*
"PowerShell welcomes $inputFromJS on $(Get-Date)"
*/});

hello('Node.js', function (error, result) {
 if (error) throw error;
 console.log(result[0]);
});

Start application and you’ll get output

PowerShell welcomes Node.js on 05/11/2013 07:14:38

Project Edge also allows integration of NodeJS with other technologies (e.g. Python)

8. May 2013

Vim mode in Cloud9 IDE

Cloud9 IDE is cloud base IDE for NodeJS, Python, Ruby or PHP projects.

The cool thing about this IDE is that code editor has support for Vim mode (it also supports Emacs) :)

vim-cloud9

Go to View, Keyboard Mode and select Vim.

Voila you can use many Vim features, like indentation by >> or many others.

Here is offical video from Cloud9 Youtube channel: