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

plugin_not_installed on android #34

Open
KreLou opened this issue Apr 7, 2019 · 9 comments
Open

plugin_not_installed on android #34

KreLou opened this issue Apr 7, 2019 · 9 comments

Comments

@KreLou
Copy link

KreLou commented Apr 7, 2019

I want to use the WebServer in an Ionic4 app on android and IOS, build with angular.

I installed the plugin via
ionic cordova plugin add https://github.com/bykof/cordova-plugin-webserver
npm install --save @ionic-native/web-server

I importet WebService in app.module.ts in providers
import { WebServer } from '@ionic-native/web-server/ngx';

I want to create a service, with the following code:

`constructor(private myServer: WebServer, private networkFinder: NetworkFinderService, private platform: Platform) {

this.IP = networkFinder.clientInformation.IP;
this.platform.ready().then(() => {
  this.myServer.onRequest().subscribe(request => {
    const response = {
      status: 200,
      body: 'Working',
      headers: {
        'Content-Type': 'text/html'
      }
    };
    console.log('Request: ', request);
    this.myServer.sendResponse(request.requestId, response);
  });

  this.myServer.start(PORT)
  .then(() =>  {
    console.log('Start Webserver on ', this.IP, ':', PORT);
  }).catch((error) => {
    console.error(error);
  });
});

}`

But i also tried this in app.component.ts in the constructor.

Then i build the android apk and run on the device via cordova.

Put i alwas get the error: plugin_not_installed.

Does anybody knows the solution?

Thanks for help

@DaveMans
Copy link

Hey did you found any solution for this problem? I'm in the same situation, thanks!

Best regards from Guatemala.

@DaveMans
Copy link

DaveMans commented May 1, 2019

Thank for the response, that was exactly what I did, I just created a new project and I was able to load the plugin properly.

@Maurocruzter
Copy link

Hi @DaveMans .

How did you solve the issue? I have the same problem

@Ovilia
Copy link

Ovilia commented Aug 21, 2019

Same problem here. Any update?

@DaveMans
Copy link

Hi @Maurocruzter and @Ovilia , I didn't check this until today, sorry :)

Well, basically what I did was that I created a complete new project, and then I installed the plugin from github repository, then I moved my code from the original project to the new one, is not an "elegant" solution but it worked for me, hope that helps!!

Regards!

:)

@Ovilia
Copy link

Ovilia commented Aug 23, 2019

@DaveMans May I ask when did you do that? Maybe it's caused in a recent commit?

I tried it with an empty project but the same error occurs.
Here's what I did:

ionic start ionicserver
cd ionicserver
ionic cordova plugin add cordova-plugin-webserver
ionic cordova platform add ios
npm install @ionic-native/web-server
ionic cordova build ios

The code is:

import {Component} from '@angular/core';
import {Platform} from '@ionic/angular';
import {WebServer, Response} from '@ionic-native/web-server/ngx';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {

  constructor(protected platform: Platform, protected webServer: WebServer) {
    this.platform.ready().then(() => {
      this.webServer.onRequest().subscribe(data => {
      console.log(data);
      const res: Response = {
        status: 200,
        body: '',
        headers: {
          'Content-Type': 'text/html'
        }
      };

      this.webServer.sendResponse(data.requestId, res)
        .catch((error: any) => console.error(error));
    });

    this.webServer.start(80)
      .then(() => console.log('server started'))
      .catch((error: any) => console.error(error));
    });
  }

}

Error message:

WARN: Native: tried calling WebServer.onRequest, but the WebServer plugin is not installed.
WARN: Install the WebServer plugin: 'ionic cordova plugin add cordova-plugin-webserver'
ERROR: plugin_not_installed

@boedy
Copy link
Collaborator

boedy commented Aug 23, 2019

@Ovilia Although I have never used ionic myself, I believe ionic cordova plugin add cordova-plugin-webserver tries to install it from NPM. This plugin is not yet published to NPM. There is currently a package on NPM that is using the same name as this repo, but is actually something different (see #37). Try installing it through GitHub directly.

@Ovilia
Copy link

Ovilia commented Aug 23, 2019

@boedy It worked for me! Thanks for saving my day! 😆

For others having the same problem here, try remove the one installed with npm and

ionic cordova plugin add https://github.com/bykof/cordova-plugin-webserver.git

@willyguevara
Copy link

@Ovilia Although I have never used ionic myself, I believe ionic cordova plugin add cordova-plugin-webserver tries to install it from NPM. This plugin is not yet published to NPM. There is currently a package on NPM that is using the same name as this repo, but is actually something different (see #37). Try installing it through GitHub directly.

Thank you very much!!

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

No branches or pull requests

6 participants