Search code examples
ionic-frameworkcordova-plugin-proguard

Ionic third party libraries


After some research I found some information about how to add a third party android libraries in Ionic framework. Apparently we can add and use .aar files in Ionic projects. My question is that if I include an .aar file, will project still be a cross platform? Can iOS devices run it?


Solution

  • As per my understanding you want to use library which is basically written in Native Android/iOS.

    Note: we can not use native code directly into ionic app.

    So next question is how to call native code or library in Hybrid app?

    To call native code from Javascript we need Cordova plugin which will communicate from Hybrid app -> Native Code & Native Code -> Hybrid app.

    lets us build our app in a web view, and call native code from JavaScript

    Cordova provides lots of default plugins like below:

    "cordova-android": "~6.3.0",
    "cordova-ios": "^4.5.4",
    "cordova-plugin-advanced-http": "^1.9.0",
    "cordova-plugin-device": "^1.1.7",
    "cordova-plugin-file": "^6.0.1",
    "cordova-plugin-inappbrowser": "^1.7.2",
    "cordova-plugin-ionic-webview": "^1.1.16",
    "cordova-plugin-native-spinner": "^1.1.3",
    "cordova-plugin-network-information": "^1.3.4",
    "cordova-plugin-proguard": "^1.0.0",
    "cordova-plugin-splashscreen": "^4.1.0",
    "cordova-plugin-whitelist": "^1.3.3",
    "cordova-sqlite-storage": "^2.2.0", 
    

    So these plugin mainly used for utilise native app framework like

    for SQLite DB storage we used cordova-sqlite-storage plugin

    for Splash screen we used cordova-plugin-splashscreen plugin and so on ...

    so next question is What is a Cordova plugin?

    Building Cordova plugins means we are writing some JavaScript to call down to some Native (Obj-c/Swift, Java, etc.) code we also write, and returning the result to our JavaScript.

    To sum it up: we build a Cordova plugin when we want to do something natively that doesn’t yet have a Web API analog, like accessing HealthKit data on iOS or using the Fingerprint scanner on Android.

    Ref : Max Lynch (Medium Blog)

    So if you want to use your .aar file you need to build custom plugin.

    This .aar file will be used for Android, for iOS you need to search related framework.

    Hope this will helps to understand all the In & Out in hybrid app.

    Useful links :

    Ionic Native

    How to write custom plugin?

    How to use cordova custom plugin?