sudo apt-get install build-essential
# curl -sL | sudo -E bash -
# sudo apt install nodejs
sudo apt-get install python-pip
sudo pip install nodeenv
nodeenv --node=0.10.33 $LIB
. $LIB/bin/activate
npm install -g ionic
# npm install -g bower


npm update -g ionic cordova
. $LIB/bin/activate
npm install -g ionic
cd <project>
ionic lib update

It is important to install native gradle or use gradle shipped with android studio (see PATH below)

  • ANDROID_HOME=/opt/android-sdk
  • PATH=/opt/android-sdk/platform-tools:/opt/android-studio/gradle/gradle-3.2/bin/


nodeenv lib
. lib/bin/activate
npm install -g ionic cordova
ionic start test1 blank
cd test1
ionic cordova plugin 
cd ..
git clone
# create pacakge.json in ImageDetectionCordovaPlugin
cd test1
cordova plugin add ../ImageDetectionCordovaPlugin
ionic cordova platform add android
ionic cordova build android
ionic cordova run android --device

example2 with cordova-plugin-camera-preview.git → GianoDroidIonic

ionic start MyCameraApp blank --id org.csgalileo.mycameraapp
git clone --depth=1
cd MyCameraApp
ionic cordova platform add android

ionic cordova plugin add ../cordova-plugin-camera-preview
npm install @ionic-native/camera-preview --save

ionic cordova plugin add cordova.plugins.diagnostic
npm install @ionic-native/diagnostic --save

ionic cordova build android
ionic cordova run android --device

Add opencv support

In <project root> add: CMakeLists.txt

cmake_minimum_required(VERSION 3.4.1)
find_library(log-lib log)

set(OpenCV_DIR "android-opencv/opencv/src/sdk/native/jni")
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")

and add to build-extras.gradle (this file is copied with hook <hook src=“scripts/” type=“after_platform_add” />)

android {
  externalNativeBuild {
    cmake {
      path "../../CMakeLists.txt"
  packagingOptions {
    // edit also abiFilters and clean project before make apk
    //exclude 'lib/armeabi-v7a/'
    exclude 'lib/mips/'
    exclude 'lib/mips64/'
    exclude 'lib/armeabi/'
    exclude 'lib/x86/'
    exclude 'lib/x86_64/'


dependencies {
  compile project(':android-opencv:opencv')

ext.postBuildExtras = {
  logger.quiet('adding java sources')
  android {
    sourceSets { += '../../src/android/java'
      main.res.srcDirs += '../../src/android/res'

from build.gradle of android-opencv comment classpath from dependancies

dependencies {
        //classpath ''

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

with <hook src=“scripts/” type=“after_platform_add” /> apply patch to change settings.gradle in

include ":"
include ":CordovaLib"
include ":android-opencv:opencv"
project(":android-opencv:opencv").projectDir = new File("../../android-opencv/opencv")

with <hook src=“scripts/” type=“before_compile” /> patch res/xml/config.xml to export plugin interface, for example

	<feature name="TestPlugin">
		<param name="android-package" value="org.csgalileo.giano.TestPlugin"></param>
		<param name="onload" value="true"></param>

define typescript interface

import { Injectable } from '@angular/core';
declare var cordova:any;
export class TestPlugin {
    public testCall() {
                function(data) { console.log("test-plugin getDate="+data); },
                function(error) { console.log("test-plugin:"+error); },

After project creation via cli (see up) import project (Eclipse, ADT, gradle) from folder <project-root>/platforms/android (choose to update gradle).

Now it is possible to develop JAVA code in Android Studio but HTML/TS has to be changed in <project-root>/src and synced with 'ionic build'

  • tips/ionic.txt
  • Last modified: 2017/08/07 13:54
  • by scipio