只需构建一个全新的0.61应用程序,其中包含组件和从当前App.js
复制的0.59
。新的0.61应用程序可以正常启动。但是,当应用程序调用{{1}}时,它将引发错误:
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)]
在RN 0.59中,模块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
}
}
....
需要在react-native-device-info
中进行链接,而自动链接在RN 0.61中提供。我想知道错误是否与自动链接有关。这是0.59中的settings.gradle
:
settings.gradle
此处为0.61:
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'