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

オープン
#5,488 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
34/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
android, javascript, kotlin, react-native

調査の方向性

まず、リンク先の expo-nativescript モノレポから expo-permissions Android プラグインのビルドを再現し、android/build.gradle と生成された settings.gradle に重点を置きます。package.json に含まれる提案された includedProjects フィールドと、settings.gradle の組み立て方を確認します。node_modules にある Java または Kotlin ベースの source plugin が、必要なプロジェクトエイリアスとともに正常にビルドできれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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 :)

主要言語
JavaScript
スター
1.1k
フォーク
204
平均マージ
1日 9時間
マージ済み PR(30日)
8

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NativeScript/nativescript-cli のほかの issue

NativeScript/nativescript-cli の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。