Search code examples
javaandroidtypescriptnativescriptnativescript-plugin

How to link a local JAR dependency in a NativeScript Plugin


I'm building a NativeScript plugin and wrapping some functionality from a JAVA library. In most cases, I've seen users define a dependency with compile 'org.namespace:library:x.y.z' in src/platforms/android/include.gradle but in my case the library is not available in any JAVA repos and is a standalone .jar file.

I've tried some suggestions users have done with actual Android apps, but of course NativeScript is a little different and so far these methods aren't working.

Steps I've tried:

1) platforms/android/include.gradle

repositories {
  flatDir {
    dirs 'libs'
  }
}

dependencies {
  compile name: 'SimpleNetworking'
}

2) platforms/android/include.gradle

dependencies {
  compile files('libs/SimpleNetworking.jar')
}

Both attempts have ended up failing when testing this on a NativeScript app requiring this plugin as a dependency:

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration 
':app:debugCompileClasspath'.
 > Could not find :SimpleNetworking:.
   Required by:
     project :app

The specific plugin I'm working to resolve can be found here.


Update

After reading this Android Studio Doc about build dependencies and changing the include.gradle file to look like:

dependencies {
  implementation files('libs/SimpleNetworking.jar')
}

It seems to have found the file! What appears to be broken now is something else:

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':app:debugCompileClasspath'.
> Failed to transform file 'SimpleNetworking.jar' to match attributes {artifactType=processed-jar} using transform IdentityTransform
> Transform output file /Users/USERNAME/git/ons-testapp/platforms/android/app/libs/SimpleNetworking.jar does not exist.

I'm not sure if this is a related error or something new.


Solution

  • You will just have to place your JAR / AAR files inside platforms/android, your plugin will automatically pick it up during compilation.