natjs / nat

A powerful kit for adding native functionalities to your weex app.
http://natjs.com
282 stars 25 forks source link

Unhandled promise rejectionTypeError: device.info is not a function #26

Closed weenta closed 6 years ago

weenta commented 6 years ago

Using module nat-device-info in android, when i get info of the device,in android studio,it has errors like this: Unhandled promise rejectionTypeError: device.info is not a function. (In 'device.info', 'device.info' is undefined)__ERROR

is there anything wrong in my code ? /index.vue

<template>
  <div class="wrapper">
    <image :src="logo" class="logo" @click='getInfo'/>
    <text class="greeting">demo3</text>
    <text class="greeting">{{text}}</text>
  </div>
</template>
<script>
 import Nat from 'natjs'
 export default {
    name: 'App',
   data () {
      return {
        logo: 'https://gw.alicdn.com/tfs/TB1yopEdgoQMeJjy1XaXXcSsFXa-640-302.png',
        text:'hello'
      }
    },
    methods:{
      getInfo(){
        Nat.device.info((err, ret) => {
          if(err){
            this.text = 'error'
          }else {
            this.text = ret
          }
        })
      }
    }
  }
</script>

/plugins.json

{
  "ios": [],
  "web": [],
  "android": [
    {
      "type": "maven",
      "groupId": "com.instapp.nat",
      "name": "weex-plugin-device-info",
      "version": "1.0.0-alpha"
    }
  ]
}

environment: ubuntu 16.04 node 8.9.3 npm 5.6 weexpack 1.1.1 natjs 0.1.5

acathur commented 6 years ago

Did you install the module correctly? Please check the .weex_plugin.json file in your Android project (/platforms/android/.weex_plugin.json).

btw, you should use weex run android to launch the app after adding new weex plugin.

weenta commented 6 years ago

actually, i did use weex run android and the modules seems installed correctly(except the last module): /platforms/android/.weex_plugin.json

[
  {
    "type": "maven",
    "groupId": "com.instapp.nat",
    "name": "weex-plugin-camera",
    "version": "1.0.0-alpha",
    "dependency": "com.instapp.nat:weex-plugin-camera:1.0.0-alpha"
  },
  {
    "type": "maven",
    "groupId": "com.instapp.nat",
    "name": "weex-plugin-communication",
    "version": "1.0.0-alpha",
    "dependency": "com.instapp.nat:weex-plugin-communication:1.0.0-alpha"
  },
  {
    "type": "maven",
    "groupId": "com.instapp.nat",
    "name": "weex-plugin-device-info",
    "version": "1.0.0-alpha",
    "dependency": "com.instapp.nat:weex-plugin-device-info:1.0.0-alpha"
  },
  {
    "type": "maven",
    "groupId": "com.instapp.nat",
    "name": "weex-plugin-device-vibration",
    "version": "1.0.0-alpha.1",
    "dependency": "com.instapp.nat:weex-plugin-device-vibration:1.0.0-alpha.1"
  },
  {
    "type": "maven",
    "groupId": "com.instapp.nat",
    "name": "weex-plugin-sensor-compass",
    "version": "1.0.0-alpha",
    "dependency": "com.instapp.nat:weex-plugin-sensor-compass:1.0.0-alpha"
  },
  {
    "type": "maven",
    "groupId": "com.instapp.nat",
    "name": "weex-plugin-device-screen",
    "version": "1.0.0-alpha.1"
  }
]

it worked; but in an interesting way: when installed a new module, the former one would worked correctly, it seems like the last one module's dependency always couldn't be installed currectly, don't know why this happens

acathur commented 6 years ago

I found the problem, the key dependency is always missing in the last JSON object of the plugins array. You can add it manually and then the project will be worked fine.

Obviously, it's a problem cause by weexpack, @erha19 bug report ;)

erha19 commented 6 years ago

@Acathur @weenta see it, I will check it out soon.

erha19 commented 6 years ago

@weenta @Acathur now you can upgrade your weexpack to v1.1.5 to avoid this issue. try weex update weexpack@latest, then add your plugins again.