Android native module works in inspector, not in deployed app


#1

I’ve created a native module and following the documentation steps and everything outputs that there was a successful build.

I have tested my code against the hardware (this is a bluetooth integration) and get responses just fine when using the inspector.

When I build/upload/deploy the module into my actual app I am not getting any specific errors, but the communication between the Java and JS code via Forge seems to stop after certain BT-related calls are made. The issue seems to be around related to an attempt to begin scanning for Bluetooth devices. The manifests for both inspector and app APKs include the appropriate BT permissions.

I have looked at the Manifests of the 2 APKs that are being generated the only differences seem to be:

android:testOnly=“true” - on inspector only
2 new permissions (fine location and vibrate) - on my app only
names and authorities are different

Another variable in play is that we are using a 3rd party jar. As mentioned before, things are working properly in the inspector app, and I have verified that I can access classes from the jar in both inspector and my app. I can’t seem to find the difference in configuration/deployment that is making it so that the inspector app can do the BT communication, but my app cannot.

Any suggestions on where to look?


#2

Native module support first saw light as a feature only available to customers with a consulting contract so the sdk docs were never all that great to start with.

Since then there’s also been a slow and ongoing incremental shift to gradle since the docs were written which has left them somewhat out of date.

So, first thing to know is that the module architecture has two parts:

  1. ForgeInspector - this is just a jig that hosts ForgeModule during development. Everything in this part is discarded when your module is used in deployment. Any changes made to it will be lost and not make it to your app.
  2. ForgeModule - The module implementation. This is what’s deployed. It contains the module code, any external resources and any build steps required to configure the app for the module. You can perform the following operations with it:
    • Add and modify .java source files
    • Change build configuration via the android build_steps.json file.
    • Add external dependencies via the build_steps.json file.
    • Add resources to ForgeModule/res.

A few thoughts:

  • Make sure you are making changes to build settings via build_steps.json rather than in the IDE. (e.g. permissions, dependencies etc.)
  • We are no longer able to support .jar external dependencies. With Google’s shift to Gradle everything has moved over to .aar depencies. The supported options are:
    1. Your dependency needs to be in one of the official repos and added to your module via the android_add_gradle_dependency build step.
    2. Include the source for your dependency directly in your module.

For the full list of supported build steps:

https://trigger.io/docs/current/api/native_modules/native_build_steps.html