Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java reflection to automatically import android plugins into MainActivity.java #3054

Closed

Conversation

SmileyJames
Copy link

This branch builds on my other pull request: #3040

Plugins are recursively found (other PR) then their java class paths are written to a json file. BridgeActivity then reads the json file and uses Java reflection to import and add the android plugin to the build.

The advantage of using Java reflection is that no manual editing of MainActivity.java is never required, as it currently is as described here: https://capacitor.ionicframework.com/docs/plugins/android/#export-to-capacitor. Capacitor would be able to convert a PWA to an android and ios app in a completely automated fashion.

This change is completly backwards compatible. Overriding onCreate in MainActivity.java will "opt out" of Java reflection, if you want to manually add plugins as before you can. Migration path is, keep doing what you are doing as before and no reflection will be used. Nothing changes for existing users.

It seems wise to seperate the concerns of these two PRs - if only to seperate discussion of the impact of these changes.

Use read-installed package to resolve plugins from all dependencies,
not just local ones.
Kept encountering this error when compiling:

node_modules/commander/typings/index.d.ts:26:25 - error TS2689: Cannot
extend an interface 'NodeJS.EventEmitter'. Did you mean 'implements'?

Had the add node/types specifically for version 12

tj/commander.js#787
DefinitelyTyped/DefinitelyTyped@c47a34e#r36559684
Remeber what we have seen because back refereences exist
We stopped using .flat()
No need to manually edit MainActivity.java
Java reflection means that overriding onCreate is no longer required
Choose the most recent version
Warn about ignored packages
Only call getPlugins once
Check if file exists before reading file
Inform user with a spinner in the cli
@imhoffd
Copy link
Contributor

imhoffd commented Jul 14, 2020

Closing this as well (see #3040 (comment)). Please track this feature here: #3266

Thank you!

@imhoffd imhoffd closed this Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants