tips:ionic

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tips:ionic [2017/07/31 16:26] – [Android] scipiotips:ionic [2017/08/07 13:54] (current) scipio
Line 2: Line 2:
  
 ===== Prerequisites ===== ===== Prerequisites =====
- 
  
 ==== nodejs (latest) ==== ==== nodejs (latest) ====
Line 19: Line 18:
 </code> </code>
  
-===== Project ===== +===== Create library =====
-==== Create library ====+
  
 <code bash> <code bash>
Line 37: Line 35:
 npm update -g ionic cordova npm update -g ionic cordova
 </code> </code>
-==== Create project ==== 
  
-  * https://devdactic.com/login-ionic-2/ +===== Update libs =====
-  * https://ionicacademy.com/ionic-3-lazy-loading/ +
-  * https://www.joshmorony.com/an-introduction-to-observables-for-ionic-2/ +
- +
-Activate library +
-<code bash> +
-. $LIB/bin/activate +
-</code> +
- +
-<code bash> +
-NAME=PeperStart +
-ionic start $NAME blank +
-cd $NAME +
-ionic browser add crosswalk #(this command enable also android platform) +
-</code> +
- +
-==== Update libs ====+
  
 <code bash> <code bash>
Line 65: Line 46:
 </code> </code>
  
-==== Android ====+===== Android =====
  
 It is important to install native gradle or use gradle shipped with android studio (see PATH below) It is important to install native gradle or use gradle shipped with android studio (see PATH below)
Line 108: Line 89:
 </code> </code>
  
-example3 with custom plugin +==== Add java sources and native C++ support ====
-<code> +
-ionic start GianoDroidHybrid blank --id org.csgalileo.gianodroidhybrid +
-cd GianoDroidHybrid +
-rm -fR .git +
-ionic cordova platform add android +
-ionic cordova plugin add ../cordova-plugin-giano +
- +
-</code> +
- +
-=== Add Native C++ support ===+
  
 Add opencv support http://wiki.csgalileo.org/projects:giano:android#simpler_mode Add opencv support http://wiki.csgalileo.org/projects:giano:android#simpler_mode
  
-In android root project (<project root>/platforms/android) add:+In <project root> add:
 CMakeLists.txt CMakeLists.txt
 <file> <file>
Line 134: Line 105:
 </file> </file>
  
-and add to existing buid.gradle (android section and dependencies section+and add to //build-extras.gradle// (this file is copied with hook <hook src="scripts/gradle.sh" type="after_platform_add" />)
 <file> <file>
 android { android {
 +  externalNativeBuild {
 +    cmake {
 +      path "../../CMakeLists.txt"
 +    }
 +  }
 +  packagingOptions {
 +    // edit also abiFilters and clean project before make apk
 +    //exclude 'lib/armeabi-v7a/libopencv_java3.so'
 +    exclude 'lib/mips/libopencv_java3.so'
 +    exclude 'lib/mips64/libopencv_java3.so'
 +    exclude 'lib/armeabi/libopencv_java3.so'
 +    exclude 'lib/x86/libopencv_java3.so'
 +    exclude 'lib/x86_64/libopencv_java3.so'
 +  }
  
-   // ...  
- 
-   externalNativeBuild { 
-        cmake { 
-            path "CMakeLists.txt" 
-        } 
-    } 
-    packagingOptions { 
-        // edit also abiFilters and clean project before make apk 
-        //exclude 'lib/armeabi-v7a/libopencv_java3.so' 
-        exclude 'lib/mips/libopencv_java3.so' 
-        exclude 'lib/mips64/libopencv_java3.so' 
-        exclude 'lib/armeabi/libopencv_java3.so' 
-        exclude 'lib/x86/libopencv_java3.so' 
-        exclude 'lib/x86_64/libopencv_java3.so' 
-    } 
 } }
  
 dependencies { dependencies {
-    // ... +  compile project(':android-opencv:opencv') 
-    compile project(':android-opencv:opencv')+
 + 
 +ext.postBuildExtras = { 
 +  logger.quiet('adding java sources'
 +  android { 
 +    sourceSets { 
 +      main.java.srcDirs += '../../src/android/java' 
 +      main.res.srcDirs += '../../src/android/res' 
 +    } 
 +  }
 } }
 </file> </file>
Line 171: Line 149:
     }     }
 </file> </file>
-==== Android Studio ==== 
  
-After project creation via cli (see up) import project (Eclipse, ADT, gradle) from folder <project-root>/platforms/android (choose to update gradle).+with <hook src="scripts/gradle.sh" type="after_platform_add" /> apply patch to change settings.gradle in 
 +<file> 
 +include ":" 
 +include ":CordovaLib" 
 +include ":android-opencv:opencv" 
 +project(":android-opencv:opencv").projectDir = new File("../../android-opencv/opencv") 
 +</file>
  
-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' +with <hook src="scripts/config.xml.py" type="before_compile" /> patch **res/xml/config.xml** to export plugin interface, for example 
-==== Eclipse ====+<file xml res/xml/config.xml> 
 + <feature name="TestPlugin"> 
 + <param name="android-package" value="org.csgalileo.giano.TestPlugin"></param> 
 + <param name="onload" value="true"></param> 
 + </feature> 
 +</file>
  
-$P is $NAME/platforms/android path+define typescript interface 
 +<file typescript src/app/test.module.ts> 
 +import { Injectable } from '@angular/core';
  
-  * Import -> "Existing Android Code ..." -> $NAME/platforms/android and deselect all subprojects +declare var cordova:any;
-  * Project -> Build Path -> Configure Build Path +
-    * Source -> Link source -> $P/Cordovalib/src with name src-cordovalib +
-    * Libraries -> Add external JAR -> $P/Cordovalib/xwalk_core_library/xwalk_core_library_java_app_part.jar +
-    * Libraries -> Add external JAR -> $P/Cordovalib/xwalk_core_library/xwalk_core_library_java_library_part.jar+
  
-==== Native lib integration ====+@Injectable() 
 +export class TestPlugin { 
 +    public testCall() { 
 +        cordova.exec( 
 +                function(data) { console.log("test-plugin getDate="+data); }, 
 +                function(error) { console.log("test-plugin:"+error); }, 
 +                "TestPlugin", 
 +                "getDate", 
 +                []); 
 +    } 
 +
 +</file>
  
-Create zip file named **gpio.jar** and put into platforms/android/libs +===== Android Studio =====
-<code> +
-lib +
-└── armeabi +
-    └── libgpio.so +
-</code>+
  
-build.gradle search inside libs for *jar (see dependancy section) +After project creation via cli (see upimport project (Eclipse, ADT, gradle) from folder <project-root>/platforms/android (choose to update gradle).
-===== Tips =====+
  
-==== Video fullscreen autoplay ====+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'
  
-<code html> 
-<video ng-controller="startVideo" controls="" style="width:100%; height:auto" autoplay="false"> 
-   <source src=""></source> 
-</video> 
-</code> 
  
-<code javascript> 
-.controller('startVideo', function($scope) { 
-  angular.element('video').attr('src','http://...'); 
-}); 
-</code> 
  • tips/ionic.1501511215.txt.gz
  • Last modified: 2017/07/31 16:26
  • by scipio