Can't create Android plugins based on compiling source from node_modules

Offen
#5,488 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
34/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
android, javascript, kotlin, react-native

Rechercherichtung

Beginne damit, den Build des expo-permissions-Android-Plugins aus dem verlinkten expo-nativescript-Monorepo zu reproduzieren, mit Fokus auf android/build.gradle und die generierte settings.gradle. Prüfe das vorgeschlagene Feld includedProjects in package.json und, wie settings.gradle zusammengesetzt wird. Als erledigt gilt dies, wenn ein Java- oder Kotlin-basierter Source-Plugin aus node_modules zusammen mit seinen erforderlichen Projekt-Aliassen erfolgreich gebaut wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Is your feature request related to a problem? Please describe.

I'm trying to re-implement React Native native modules as NativeScript plugins.

React Native native modules typically consist of some JS/TS source in a src folder and some native code, i.e. Obj-C/Swift code in an ios folder, and Java/Kotlin code in an android folder. expo-permissions is one example of a React Native native module that I'm trying to port.

The key difference from the NativeScript ecosystem is that React Native native modules very often don't rely on ready-packaged native code (e.g. .jar files) downloaded from a package repository - instead, a React Native native module (which, to be clear, is an npm package such as expo-permissions) may distribute the native source files (e.g. .java files) with the intention that the React Native app then compiles them itself. In other words, the .jar file (or iOS equivalent - clang module?) would be built locally.

This presents a few problems which I may not be able to express coherently in a single attempt... For iOS, at least, I have a fully working example (see my expo-permissions-nativescript-plugin project) - the build process was relatively pain-free. But for Android, I've spent weeks failing to get anything working.

Android is problematic principally for two reasons.

  1. some include statements need to be written into the settings.gradle file to proceed (yet there is no API to edit it - so far I've hacked it together using hooks);
  2. at least with this particular Kotlin-based project, I've not had any luck compiling it. The best I managed was to produce a jar corresponding to the package, but when I extracted it, no symbols relating to the source code were found. I am not sure whether this is a problem of Kotlin, or perhaps the need for a gradle directory to be provided before anything will start to work (as @triniwiz mentioned - he would have more knowledge on this).

Describe the solution you'd like

Whether the project is made from .java or .kotlin files, NativeScript should be able to build plugins from source found in `node_modules.

When those projects bear a build.gradle file (such as this one in expo-permissions) that refers to any projects such as :unimodules-core, NativeScript must provide some solution for populating the app's settings.gradle file with the corresponding project alias:

include :unimodules-permissions-interface;
project(':unimodules-permissions-interface').projectDir = new File(rootProject.projectDir, '../../node_modules/unimodules-permissions-interface/android')

include :expo-permissions;
project(':expo-permissions').projectDir = new File(rootProject.projectDir, '../../node_modules/@nativescript-community/expo-permissions/platforms/android')

To be clear, settings.gradle is the only place where these include statements can go - I have tried placing them in build.gradle and include.gradle and whatever else, but those other options don't work.

This would probably best be done by the plugin defining, somewhere in its package.json, a field for any includedProjects, implicitly relative to the location of rootProject.projectDir, e.g.:

"includedProjects": {
    ":unimodules-permissions-interface": "../../node_modules/unimodules-permissions-interface/android",
    ":expo-permissions": "../../node_modules/@nativescript-community/expo-permissions/platforms/android"
},

Additional context

The difficulties should become much clearer if you have a go at trying to install the npm module expo-permissions and try yourself to make an Android plugin from it (as far as I can tell, it's impossible at the moment, even with hacks). You could use my expo-nativescript monorepo to experiment.

The end goal - being able to seamlessly consume React Native (and Flutter, I guess) native modules in NativeScript projects :)

Vorherrschende Sprache
JavaScript
Sterne
1.1k
Forks
204
Ø Merge
1 T. 9 Std.
Gemergte PRs (30 T.)
8

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus NativeScript/nativescript-cli

Alle Issues in NativeScript/nativescript-cli

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.