How To Modify Native Code (Android) In An Existing Cordova Plugin

Hey guys I had a hell of time figuring out what the best way to modify the native Android code for an exiting Cordova plugin was. Here’s a quick write up below.

  1. Fork the cordova plugin you want to modify.
  2. Clone it locally to your computer.
  3. Navigate to https://github.com/apache/cordova-android and download the repo.
  4. Extract downloaded cordova-android .zip previously downloaded.
  5. Locate framework folder and pull into new directory.
  6. Rename framework folder to project name of your choosing.
  7. Open newly renamed framework folder in Android Studio.
  8. In Android Studio create a new package with the name that matches the package name of the Android plugin files.
  9. Copy all .java files from locally cloned cordova plugin to newly created android studio package (Ctrl+c, Ctrl+v with package highlighted in Android Studio works best).
  10. You now have code completion for Android / java / plugin working
  11. Now in order to push updates to forked cloned repo, you have the following options
    11a. Setup an auto file replace from Android Studio project package name folder -> android folder in cloned repo
    11b. Manually copy files in Andriod Studio project you changed & paste them into android folder in cloned repo (mark as replace all).

The last bit step 11 could use some work, but overall I hope this helps someone!

3 Likes

Wow it was for sure kind of a work to find that! thx for documenting it :+1:

1 Like

Always happy to help! Thanks for reaching out to try and help me earlier :slight_smile:

1 Like