Модуль информации React Native об ошибке устройства 0,61 - PullRequest
0 голосов
/ 03 октября 2019

Просто создайте приложение 0.61 с полностью новой сборкой с компонентами и App.js, скопированной из текущей 0.59. Новое приложение 0.61 запускается без ошибок. Однако, когда приложение вызывает DeviceInfo.getUniqueID(), оно выдает ошибку:

10-03 11:17:47.484 16421 16574 I ReactNativeJS: 'error signing up: ', { [TypeError: _reactNativeDeviceInfo.default.getUniqueID is not a function. (In '_reactNativeDeviceInfo.default.getUniqueID()', '_reactNativeDeviceInfo.default.getUniqueID' is undefined)]

Вот код, связанный с компонентом:

import DeviceInfo from 'react-native-device-info';

export default class Signup extends React.Component {

      ......

      signUp = async () => {
        const { username, corp_name, cell, cell_country_code } = this.state;
        //console.log("In signup");
        try {
          // here place your signup logic
          console.log('user in Signup!: ', username);
          let url = `${GLOBAL.BASE_URL}/api/users/signup`;
          console.log("Signup post URL : ", url);
          let obj = JSON.stringify({
            _device_id: DeviceInfo.getUniqueID(),  //<<<<<===this line causes the error
            cell: cell,
            cell_country_code: cell_country_code,
            name: username,
            corp_name: corp_name,
          });
          console.log("obj : ", obj);
          let res = await fetch(url, {
            method: "POST",
            headers: {
              'Accept': 'application/json, text/plain, */*',
              'Content-Type': 'application/json',   
            },
              body: obj,
            });


            return;
          } else {
            //do nothing and show the signup page again
          };

        } catch (err) {
          console.log('error signing up: ', err);  //<<<<=== error is caught here 
        }
      }
     ....

В RN 0,59 модуль react-native-device-info требуетсвязь в settings.gradle и автоссылка предусмотрены в RN 0.61. Мне интересно, если ошибка связана с автолинком. Вот settings.gradle в 0,59:

rootProject.name = 'emps_fe'
include ':@react-native-community_async-storage'
project(':@react-native-community_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/async-storage/android')
include ':react-native-video'
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer')
include ':react-native-keychain'
project(':react-native-keychain').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-keychain/android')
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-gesture-handler'
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
include ':react-native-linear-gradient'
project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android')
include ':react-native-device-info'  //<<<<=== here is the link
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')

include ':app'

Вот оно в 0,61:

rootProject.name = 'emps_fe6'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app' 
...