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
2 of 7 tasks
mrodal opened this issue May 24, 2019 · 9 comments · Fixed by #1574
Closed
2 of 7 tasks

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

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

Comments

@mrodal
Copy link

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
Copy link
Member

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

A sample app would be helpful

@mrodal
Copy link
Author

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
Copy link
Author

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
Copy link
Member

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
Copy link
Author

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
Copy link
Member

Thanks, but I've already sent it.

@theunreal
Copy link

I am facing this issue, what is the workaround?

@jcesarmobile
Copy link
Member

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
Copy link

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants