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

Unable to inject Capacitor, Plugins won't work #1572

Closed
mrodal opened this issue May 24, 2019 · 9 comments · Fixed by #1574

Comments

@mrodal
Copy link

@mrodal mrodal commented May 24, 2019

Description of the problem:
Hey, I just got started with capacitor, and Im getting this error on the Android studio console when running the app:
E/Capacitor: Unable to inject Capacitor, Plugins won't work

Is it normal?

Affected platform

  • Android
  • iOS
  • electron
  • web

OS of the development machine

  • Windows
  • macOS
  • linux

Other information:

Capacitor version:
4.12

node version:
10.15

npm version:
6.9

CocoaPods version:

Steps to reproduce:

Link to sample project:

@jcesarmobile

This comment has been minimized.

Copy link
Member

@jcesarmobile jcesarmobile commented May 24, 2019

Can you provide a little more information? like what steps did you follow

A sample app would be helpful

@mrodal

This comment has been minimized.

Copy link
Author

@mrodal mrodal commented May 24, 2019

Of course, its a vue app, so the type in ionic config is custom.
I created the app with vue-cli
I installed ionic as described here https://github.com/ionic-team/ionic/tree/master/vue
Executed ionic init
Then ionic capacitor add android
Added "ionic:serve": "vue-cli-service serve", to the package.json scripts
Executed ionic capacitor run android --livereload
Then ran the app on an emulator on android studio

Heres the app:
https://github.com/mrodal/reported-issues/tree/unable-inject-capacitor

@mrodal

This comment has been minimized.

Copy link
Author

@mrodal mrodal commented May 24, 2019

Ok, I looked for the code raising the error, and its on JSInjector.java:
image

This is called first with the site's html, where the script is injected succesfully, and then again a couple of times with content like this:
{"websocket":true,"origins":["*:*"],"cookie_needed":false,"entropy":1469886054}

So it is actually working, but it is trying to also inject the scripts where it shouldnt

@jcesarmobile

This comment has been minimized.

Copy link
Member

@jcesarmobile jcesarmobile commented May 24, 2019

Yeah, Capacitor injects itself into html files searching for the head tag, but it's trying to inject itself into json files too showing that error message. Will fix it.

@mrodal

This comment has been minimized.

Copy link
Author

@mrodal mrodal commented May 24, 2019

If you think its a good solution, I can make a PR checking for the content type on WebViewLocalServer.java:

image

@jcesarmobile

This comment has been minimized.

Copy link
Member

@jcesarmobile jcesarmobile commented May 24, 2019

Thanks, but I've already sent it.

@theunreal

This comment has been minimized.

Copy link

@theunreal theunreal commented May 28, 2019

I am facing this issue, what is the workaround?

@jcesarmobile

This comment has been minimized.

Copy link
Member

@jcesarmobile jcesarmobile commented May 28, 2019

Should be a harmless message as it happens when it tries to inject itself to json or other type of files. Unless you plugins don't work, in that case create a new issue and provide more information.

@theunreal

This comment has been minimized.

Copy link

@theunreal theunreal commented May 29, 2019

Thanks @jcesarmobile , I opened a new issue.

#1595

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.