[英]React Native Relase, Debug apk crashes in physical devices
I followed the facebook documentation on how to generate signed apk exactly. 我遵循了有关如何准确生成签名apk的facebook文档。 But still I am getting error:
undefined is not an object (evaluating 'e.length'
Here is the screenshot 但是仍然出现错误:
undefined is not an object (evaluating 'e.length'
这是屏幕截图
However, the app works fine in Android Emulator with command react-native run-android
. 但是,该应用程序在Android Emulator中使用命令
react-native run-android
。 But, I got the issue which was causing the app to crash. 但是,我遇到了导致应用崩溃的问题。 It was
native-base
. 它是基于
native-base
。 Here is the following code in my App.js: 这是我的App.js中的以下代码:
import React, { Component } from 'react';
import {Text} from 'react-native';
import { Container, Header, Content, Form,Text, Item, Input, Label, Button }
from 'native-base';
export default class ReactNativeExample extends Component {
constructor(props) {
super(props);
this.state = {
username: '',
password: ''
};
this.doSignIn = this.doSignIn.bind(this);
}
doSignIn() {
let formdata = new FormData();
formdata.append("username", this.state.username)
formdata.append("password", this.state.password)
fetch('http://someweb.com/loginUser',{
method: 'post',
headers: {
'Content-Type': 'multipart/form-data',
},
body: formdata
}).then((response) => response.json())
.then((responseData) => {
console.log("Inside responsejson");
if(responseData.error != true) {
console.log('You have logged in...');
}
}).done();
}
render() {
return (
<Container>
<Header />
<Content>
<Form>
<Item floatingLabel style={{margin: 8}}>
<Label>Username</Label>
<Input ref="username" onChangeText={(username) =>
this.setState({username})}/>
</Item>
<Item floatingLabel last style={{margin: 8}}>
<Label>Password</Label>
<Input ref="username" onChangeText={(password) =>
this.setState({password})}/>
</Item>
<Button block info style={{margin: 8}} onPress={this.doSignIn}>
<Text>Login</Text>
</Button>
</Form>
</Content>
</Container>
<Text> Hello </Text>
);
}
}
I want to know what is wrong with the above native-base
code that is making the App crash? 我想知道导致应用程序崩溃的上述基于
native-base
代码有什么问题吗? Is there any way I can make native-base
code work? 有什么办法可以使基于
native-base
代码工作?
Thank You. 谢谢。
ReactNative version: 0.50.1 ReactNative版本:0.50.1
tried your code. 尝试过您的代码。 Was able to generate an apk successfully.
能够成功生成apk。 Didn't find any issue while running the apk.
运行apk时未发现任何问题。 Posting the code.
发布代码。
import React, { Component } from "react";
import { Container, Header, Content, Form, Text, Item, Input, Label,Button } from "native-base";
export default class ReactNativeExample extends Component {
constructor(props) {
super(props);
this.state = {
username: "",
password: "",
};
this.doSignIn = this.doSignIn.bind(this);
}
doSignIn() {
let formdata = new FormData();
formdata.append("username", this.state.username);
formdata.append("password", this.state.password);
fetch("https://httpbin.org/", {
method: "post",
headers: {
"Content-Type": "multipart/form-data",
},
body: formdata,
})
.then(response => console.log("response", response))
.done();
}
render() {
return (
<Container>
<Header />
<Content>
<Form>
<Item floatingLabel style={{ margin: 8 }}>
<Label>Username</Label>
<Input ref="username" onChangeText={username => this.setState({ username })} />
</Item>
<Item floatingLabel last style={{ margin: 8 }}>
<Label>Password</Label>
<Input ref="username" onChangeText={password => this.setState({ password })} />
</Item>
<Button block info style={{ margin: 8 }} onPress={this.doSignIn}>
<Text>Login</Text>
</Button>
</Form>
</Content>
</Container>
);}
}
When using NativeBase components use <Text/>
from 'native-base' 使用NativeBase组件时,请使用'native-base'中的
<Text/>
That's because there is import duplicates of Text
component 那是因为
Text
组件有导入重复项
import { Text } from 'react-native';
import { Container, Header, Content, Form,Text, Item, Input, Label, Button }
from 'native-base';
You can import both Text components via as
like this 您可以通过导入这两个文本组件
as
这样的
import { Text as NativeText } from 'react-native';
And then use NativeText
. 然后使用
NativeText
。 Otherwise, do not duplicate your imports. 否则,请勿重复导入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.