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

support ionic #1

Closed
mrpower55 opened this issue Oct 29, 2017 · 26 comments
Closed

support ionic #1

mrpower55 opened this issue Oct 29, 2017 · 26 comments

Comments

@mrpower55
Copy link

hi there, i want to add this plugin on my ionic project

but i can't know what is the class of it to set it on providers,

also i can't know what is the function i need to use on ionic

so please help me

thanks

@SujitSingh
Copy link

SujitSingh commented Jan 16, 2018

By default, you can import "IRoot" class from "cordova-plugin-iroot\www\iroot".
But in Ionic, this will generate error, "require", "cordova" and "exec" not defined in web version.

Thus, I have conditionaly added this file in index.html (which is only if device is mobile type).
Know more about that logic here.

I have customized my IRoot.js file to be as below -

window.isRooted = function (successCallback, failureCallback) {
    cordova.exec(successCallback, failureCallback, "IRoot", "isRooted", []);
};
window.isRootedRedBeer = function (successCallback, failureCallback) {
    cordova.exec(successCallback, failureCallback, "IRoot", "isRootedRedBeer", []);
};

Now to call isRooted function while avoiding compilation errors in web version, I have created another JS file named rooted-check.js with required caller functions -

module.exports = {
    isRootedDevice: function(successCallback, errorCallback){
        window.isRooted(successCallback, errorCallback)
    },
    isRootedRedBeerDevice: function(successCallback, errorCallback){
        window.isRootedRedBeer(successCallback, errorCallback)
    },
}

Now, to call required functions -

import * as rootedCheck from '../../assets/js/rooted-check';

rootedCheck.isRootedDevice(
  (booleanVal) => {
    // success callback function
    if(booleanVal){
      // this is a rooted device
    }
  },
  (err) => {       
    // error callback function
    // error while checking rooted status
  }
)

This works in web as well as in mobile app. I haven't tested yet in web-browser of a mobile device.

There may be better way(s) of doing this, which we will be happy to know about.

@WuglyakBolgoink
Copy link
Owner

Thank you @sujit77 ,

I check it

@WuglyakBolgoink
Copy link
Owner

@sujit77 I fixed in ionic. I need some tests with normal apps.

lastChanges@progress

@SujitSingh
Copy link

@WuglyakBolgoink, have you found better way of importing this plugin into Angular(2 and above) projects? I can test it out too if you can instruct me for that.

You can test it in Android studio using android emulator.
Devices in Android emulator are rooted. So you don't have to search for a rooted Android device.

However, I haven't tested it in iOS device cause it is hard to find jail broken iPhone.

@WuglyakBolgoink
Copy link
Owner

WuglyakBolgoink commented Mar 1, 2018

FYI @sujit77

  1. you should add IRoot-Plugin via
ionic cordova plugin add cordova-plugin-iroot --save
  1. declare mock-variable
declare var IRoot: IRoot;

with IRoot Type (*.d.ts File you can import too):

import { IRoot } from '../../plugins/cordova-plugin-iroot/iroot';

src/app/app.component.ts

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { TabsPage } from '../pages/tabs/tabs';
import { IRoot } from '../../plugins/cordova-plugin-iroot/iroot';

declare var IRoot: IRoot;

@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage: any = TabsPage;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform
      .ready()
      .then(() => {
        // Okay, so the platform is ready and our plugins are available.
        // Here you can do any higher level native things you might need.
        statusBar.styleDefault();
        splashScreen.hide();

        console.log('platform', platform);

        if (platform.is('cordova')) {
          console.log('is cordova');

          try {
            console.log(' IRoot', IRoot);

            IRoot.isRooted((booleanVal) => {
              console.log('IRoot.isRooted success: ', booleanVal);
            }, (err) => {
              console.log('IRoot.isRooted error:', err);
            });
          }
          catch (e) {
            console.log('Error:', e);
          }
        } else {
          console.log('is not cordova');
        }
      });
  }
}

and build app

image

IRoot is in global scope and you should not import this file.


Test-1:

  • ionic v3.19.1
  • cordova v6.5.0
  • cordova-plugin-iroot v0.6.1

Test-2:

  • angularJS v1.6.9
  • cordova v6.5.0
  • cordova-plugin-iroot v0.6.1

Test-3: (todo)

  • angular v4.x
  • cordova v6.5.0
  • cordova-plugin-iroot v0.6.1

Test-4: (todo)

  • angular v5.x
  • cordova v6.5.0
  • cordova-plugin-iroot v0.6.1

@WuglyakBolgoink
Copy link
Owner

Hi @mrpower55 & @sujit77 please check if all work with 0.6.1 version

@SujitSingh
Copy link

I am not able to make it work. Will you be able to help me in detecting steps which I have missed?

I have installed latest package using -

ionic cordova plugin add cordova-plugin-iroot@latest

Trying to import IRoot using following -

import { IRoot } from 'cordova-plugin-iroot/iroot'; // Error - Cannot find module "cordova-plugin-iroot/iroot

import { IRoot } from 'cordova-plugin-iroot'; // Error - Cannot find module "cordova-plugin-iroot

The one which works is -

import { IRoot } from 'cordova-plugin-iroot/www/iroot; 

But above one generates error while running -

Runtime Error
Cannot find module "cordova/exec"

This is exactly same what I got earlier with version 0.4.0.

@WuglyakBolgoink
Copy link
Owner

WuglyakBolgoink commented Mar 1, 2018

@sujit77

do not import IRoot as cordova plugin.

IRoot Plugin is available as IRoot-variable. Noting to do hier.

You can import iroot.d.ts for Interface, as I wrote above in p.2

@SujitSingh
Copy link

SujitSingh commented Mar 4, 2018

@WuglyakBolgoink , new changes works perfectly with pitfalls.

Installed using - cordova plugin add cordova-plugin-iroot@latest

import { IRoot } from 'cordova-plugin-iroot/iroot';
declare var IRoot: IRoot;

I started getting following errors while building package files for specific mobile platforms -

(node:4520) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CordovaError: Failed to fetch platform cordova-android@7.0.0
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
Error: cmd: Command failed with exit code 1 Error output:
npm ERR! path C:\Users\SujitKumarSingh\ProjectApp\node_modules\cordova-plugin-iroot
npm ERR! code EISGIT
npm ERR! git C:\Users\SujitKumarSingh\ProjectApp\node_modules\cordova-plugin-iroot: Appears to be a git repo or submodule.
npm ERR! git     C:\Users\SujitKumarSingh\ProjectApp\node_modules\cordova-plugin-iroot
npm ERR! git Refusing to remove it. Update manually,
npm ERR! git or move it out of the way first.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\SujitKumarSingh\AppData\Roaming\npm-cache\_logs\2018-03-04T11_02_10_503Z-debug.log
(node:4520) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

---------------------

(node:372) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CordovaError: Failed to fetch platform cordova-android@7.0.0
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
Error: cmd: Command failed with exit code 1 Error output:
npm ERR! path C:\Users\SujitKumarSingh\ProjectApp\node_modules\cordova-plugin-iroot
npm ERR! code EISGIT
npm ERR! git C:\Users\SujitKumarSingh\ProjectApp\node_modules\cordova-plugin-iroot: Appears to be a git repo or submodule.
npm ERR! git     C:\Users\SujitKumarSingh\ProjectApp\node_modules\cordova-plugin-iroot
npm ERR! git Refusing to remove it. Update manually,
npm ERR! git or move it out of the way first.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\SujitKumarSingh\AppData\Roaming\npm-cache\_logs\2018-03-04T11_04_14_350Z-debug.log
(node:372) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

-------------------------

(node:15856) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CordovaError: Failed to fetch platform cordova-android@7.0.0
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
Error: cmd: Command failed with exit code 1 Error output:
npm ERR! path C:\Users\SujitKumarSingh\ProjectApp\node_modules\cordova-plugin-iroot
npm ERR! code EISGIT
npm ERR! git C:\Users\SujitKumarSingh\ProjectApp\node_modules\cordova-plugin-iroot: Appears to be a git repo or submodule.
npm ERR! git     C:\Users\SujitKumarSingh\ProjectApp\node_modules\cordova-plugin-iroot
npm ERR! git Refusing to remove it. Update manually,
npm ERR! git or move it out of the way first.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\SujitKumarSingh\AppData\Roaming\npm-cache\_logs\2018-03-04T11_03_48_224Z-debug.log
(node:15856) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

But, finally it worked(I just hibernated system).
But, above error message still appear if I reinstall packages after removing node_modules and plugins folders.

@SujitSingh
Copy link

@WuglyakBolgoink we just need to remove the .git folder which gets created while installing this package. After that everything works perfectly.

Look at solutions [1], [2] with similar issues.

@WuglyakBolgoink
Copy link
Owner

@sujit77 ok. I will check this.

@CHENPINGFIONA
Copy link

Hi @WuglyakBolgoink,

While I am using the plugin. I am facing the issue of
Cannot find module "cordova-plugin-iroot/iroot".
How can I resolve this?

Thank you

@WuglyakBolgoink
Copy link
Owner

@CHENPINGFIONA
you should declare mock-variable. if u need JSDoc, then import interface from cordova-plugin-iroot/iroot

see my comment above.

if this do not help you, then how can I reproduce your case?

@CHENPINGFIONA
Copy link

@WuglyakBolgoink
I do exactly what your comment shown above. and declared mock-variable. However it still encounter this issue. I just create simple app with the plugin install and added in the codes provided above.

@WuglyakBolgoink
Copy link
Owner

@CHENPINGFIONA can you create a demo repo with your test project to reproduce this error?

@CHENPINGFIONA
Copy link

@WuglyakBolgoink
I found out is my typescript version issue. it was 2.3.4, after update to 2.6.2. problem solved.
Really appreciate for your kindly assistance

@rosstimothy
Copy link

The steps above to compile no longer work

❯ ionic info                                                                                                                               

Ionic:

   ionic (Ionic CLI)  : 4.0.2 (/usr/local/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.1

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : ios 4.5.5
[10:11:33]  typescript: src/app/app.component.ts, line: 8
            Cannot find module '../../plugins/cordova-plugin-iroot/iroot'.

       L8:  import { IRoot } from '../../plugins/cordova-plugin-iroot/iroot'

[10:11:33]  ionic-app-script task: "build"
[10:11:33]  Error: Failed to transpile program
Error: Failed to transpile program
    at new BuildError (~/node_modules/@ionic/app-scripts/dist/util/errors.js:16:28)
    at ~/node_modules/@ionic/app-scripts/dist/transpile.js:159:20
    at new Promise (<anonymous>)
    at transpileWorker (~/node_modules/@ionic/app-scripts/dist/transpile.js:107:12)
    at Object.transpile ~/node_modules/@ionic/app-scripts/dist/transpile.js:64:12)
    at ~/node_modules/@ionic/app-scripts/dist/build.js:109:82
[ERROR] An error occurred while running subprocess ionic-app-scripts.

@ng22792
Copy link

ng22792 commented Feb 26, 2019

FYI @sujit77

  1. you should add IRoot-Plugin via
ionic cordova plugin add cordova-plugin-iroot --save
  1. declare mock-variable
declare var IRoot: IRoot;

with IRoot Type (*.d.ts File you can import too):

import { IRoot } from '../../plugins/cordova-plugin-iroot/iroot';

src/app/app.component.ts

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { TabsPage } from '../pages/tabs/tabs';
import { IRoot } from '../../plugins/cordova-plugin-iroot/iroot';

declare var IRoot: IRoot;

@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage: any = TabsPage;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform
      .ready()
      .then(() => {
        // Okay, so the platform is ready and our plugins are available.
        // Here you can do any higher level native things you might need.
        statusBar.styleDefault();
        splashScreen.hide();

        console.log('platform', platform);

        if (platform.is('cordova')) {
          console.log('is cordova');

          try {
            console.log(' IRoot', IRoot);

            IRoot.isRooted((booleanVal) => {
              console.log('IRoot.isRooted success: ', booleanVal);
            }, (err) => {
              console.log('IRoot.isRooted error:', err);
            });
          }
          catch (e) {
            console.log('Error:', e);
          }
        } else {
          console.log('is not cordova');
        }
      });
  }
}

and build app

image

IRoot is in global scope and you should not import this file.

Test-1:

  • ionic v3.19.1
  • cordova v6.5.0
  • cordova-plugin-iroot v0.6.1

Test-2:

  • angularJS v1.6.9
  • cordova v6.5.0
  • cordova-plugin-iroot v0.6.1

Test-3: (todo)

  • angular v4.x
  • cordova v6.5.0
  • cordova-plugin-iroot v0.6.1

Test-4: (todo)

  • angular v5.x
  • cordova v6.5.0
  • cordova-plugin-iroot v0.6.1

So basically everything worked fine when I removed "import { IRoot } from '../../plugins/cordova-plugin-iroot/iroot';" line from the app.component.ts and changed the line "declare var IRoot: IRoot;" to "declare var IRoot;".

Try this and everything works (for people who are trying to directly copy paste the code and getting errors)

Thanks @WuglyakBolgoink for the perfect code !

@AditioPutra
Copy link

Hi @WuglyakBolgoink
I got this error
Cannot find module '../../plugins/cordova-plugin-iroot/iroot'.ts(2307)
How to fix this?

@WuglyakBolgoink
Copy link
Owner

@AditioPutra but can you find this file manually?

@AditioPutra
Copy link

@AditioPutra but can you find this file manually?

no i can't find it

@WuglyakBolgoink
Copy link
Owner

@AditioPutra reinstall plugin and check folder:
image

@AditioPutra
Copy link

Screen Shot 2019-03-29 at 16 34 30

@WuglyakBolgoink
Copy link
Owner

@AditioPutra
image

@mwvarela
Copy link

mwvarela commented Jun 27, 2019

@WuglyakBolgoink I tried doing types import in version 0.8.0 but did not work
import { IRoot } from '../../../plugins/cordova-plugin-iroot/types';
File 'd:/app-portal/plugins/cordova-plugin-iroot/types/index.d.ts' is not a module.ts(2306)

on version 0.6.1 import { IRoot } from '../../../plugins/cordova-plugin-iroot/iroot'; works

@PraveenFrancis
Copy link

FYI @sujit77

  1. you should add IRoot-Plugin via
ionic cordova plugin add cordova-plugin-iroot --save
  1. declare mock-variable
declare var IRoot: IRoot;

with IRoot Type (*.d.ts File you can import too):

import { IRoot } from '../../plugins/cordova-plugin-iroot/iroot';

src/app/app.component.ts

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { TabsPage } from '../pages/tabs/tabs';
import { IRoot } from '../../plugins/cordova-plugin-iroot/iroot';

declare var IRoot: IRoot;

@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage: any = TabsPage;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform
      .ready()
      .then(() => {
        // Okay, so the platform is ready and our plugins are available.
        // Here you can do any higher level native things you might need.
        statusBar.styleDefault();
        splashScreen.hide();

        console.log('platform', platform);

        if (platform.is('cordova')) {
          console.log('is cordova');

          try {
            console.log(' IRoot', IRoot);

            IRoot.isRooted((booleanVal) => {
              console.log('IRoot.isRooted success: ', booleanVal);
            }, (err) => {
              console.log('IRoot.isRooted error:', err);
            });
          }
          catch (e) {
            console.log('Error:', e);
          }
        } else {
          console.log('is not cordova');
        }
      });
  }
}

and build app
image
IRoot is in global scope and you should not import this file.
Test-1:

  • ionic v3.19.1
  • cordova v6.5.0
  • cordova-plugin-iroot v0.6.1

Test-2:

  • angularJS v1.6.9
  • cordova v6.5.0
  • cordova-plugin-iroot v0.6.1

Test-3: (todo)

  • angular v4.x
  • cordova v6.5.0
  • cordova-plugin-iroot v0.6.1

Test-4: (todo)

  • angular v5.x
  • cordova v6.5.0
  • cordova-plugin-iroot v0.6.1

So basically everything worked fine when I removed "import { IRoot } from '../../plugins/cordova-plugin-iroot/iroot';" line from the app.component.ts and changed the line "declare var IRoot: IRoot;" to "declare var IRoot;".

Try this and everything works (for people who are trying to directly copy paste the code and getting errors)

Thanks @WuglyakBolgoink for the perfect code !

This is working. Thanks, bro

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

9 participants