3

I need to create an Ionic app that uses a native Android SDK in order to perform the functionality I want. The SDK is an AAR and allows me to develop an Android app that handles things like web services, bluetooth, etc. The problem is that I need to develop the app cross platform using Ionic and that means ultimately creating a Cordova plugin. I've looked around the net for information on Cordova plugins but I'm not quite sure how to develop a plugin larger than an echo because thats all anyone ever seems to show.

So my question is, where do I begin? Do I develop the Android app first and then copy the java code into my Cordova plugin or do I develop the Cordova plugin at the same time as creating the java code based on the Android SDK I've been provided with?

If I build the Cordova plugin without the Android application first I won't be able to test, so maybe I should build the Android app first and then port it into a Cordova plugin?

Thanks

Ben McM
  • 31
  • 3

2 Answers2

3

where do I begin?

Use an existing (real) Cordova plugin as reference.

Depending how your SDK is packaged, depends how you'll need to install it from your plugin.

If your SDK is a JAR file, you'll need to place it in your plugin folder and add an entry to your plugin.xml to deploy it. For example cordova-plugin-cipherlab-rs30 does this.

Or if your SDK is available via Maven, you can use <framework> tags to satisfy the dependency via Gradle: e.g. cordova-plugin-facebook.

Do I develop the Android app first and then copy the java code into my Cordova plugin

I wouldn't recommend this if you're ultimately developing a Cordova plugin, otherwise you will create more work than necessary.

If I build the Cordova plugin without the Android application first I won't be able to test

This is not true:

  • create your plugin locally e.g. /path/to/my/plugin
  • then create a Cordova test app project which you'll use to test it, e.g. cordova create myplugintest
  • add your plugin to your test project: cd myplugintest && cordova plugin add /path/to/my/plugin
  • add the Android platform: cordova platform add android
  • Open the native Android project in Android Studio: /path/to/myplugintest/platforms/android
  • Set breakpoints and debug your plugin by running your test app in Android studio.
  • Any code changes you make to your plugin Java in Android Studio will need to be copied back to your plugin source in /path/to/my/plugin/
DaveAlden
  • 30,083
  • 11
  • 93
  • 155
  • Thanks for the in depth response! You cleared a lot of things up. I feel like I'm out of my depth here and your explanation helped. Maybe I'll have more questions later, but this is a very good start. Cheers! – Ben McM Jun 08 '17 at 12:25
  • I just noticed you said your SDK is an AAR (not JAR), so check out [this answer](https://stackoverflow.com/a/30757738/777265) – DaveAlden Jun 08 '17 at 12:36
  • Haha yes, using the links you provided I also found that you can create a custom gradle file and hold the AAR files in a directory within the plugin. The answer you found provides a lot of detail on how to do it. Thanks again for your help. Really appreciate it! – Ben McM Jun 08 '17 at 13:17
0

Check out this reference for plugging into an AAR file: https://github.com/bitstadium/HockeySDK-Cordova

xke
  • 1,073
  • 12
  • 13