单击登录按钮后,React 本机发布签名的 apk 文件崩溃

Posted

技术标签:

【中文标题】单击登录按钮后,React 本机发布签名的 apk 文件崩溃【英文标题】:React native release signed apk file crashes after click on login button 【发布时间】:2019-02-27 09:12:32 【问题描述】:

我已使用以下链接创建了我的应用的 APK 文件。

https://facebook.github.io/react-native/docs/signed-apk-android#docsNav

它安装成功,一旦我点击登录按钮,它就会显示“不幸的是,应用程序已关闭错误”。我尝试创建其他项目的 APK,它工作正常。但是,在这个项目中,它崩溃了。

创建项目后,我将项目名称更改为 string.xml 文件。这有什么问题吗?甚至尝试保留以前的名称,但我的问题没有得到解决。 我的 package.json 文件是


  "name": "awsUpload",
  "version": "0.0.1",
  "private": true,
  "scripts": 
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  ,
  "dependencies": 
    "aws-sdk": "^2.395.0",
    "link": "^0.1.5",
    "react": "16.6.3",
    "react-native": "^0.58.3",
    "react-native-aws3": "0.0.8",
    "react-native-device-info": "^0.26.2",
    "react-native-file-upload": "^1.0.4",
    "react-native-image-picker": "^0.28.0",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-router-flux": "^4.0.6",
    "uniqid": "^5.0.3"
  ,
  "devDependencies": 
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "24.0.0",
    "jest": "24.0.0",
    "metro-react-native-babel-preset": "0.51.1",
    "react-test-renderer": "16.6.3"
  ,
  "jest": 
    "preset": "react-native"
  

我的包裹有问题吗?

我的按钮文件代码是

import React, Component from 'react';
import PropTypes from 'prop-types';
import Dimensions from 'Dimensions';
import 
  StyleSheet,
  TouchableOpacity,
  Text,
  Animated,
  Easing,
  Image,
  Alert,
  View,
 from 'react-native';
import Actions, ActionConst from 'react-native-router-flux';

import spinner from '../images/loading.gif';

const DEVICE_WIDTH = Dimensions.get('window').width;
const DEVICE_HEIGHT = Dimensions.get('window').height;
const MARGIN = 40;

export default class ButtonSubmit extends Component 
  constructor() 
    super();

    this.state = 
      isLoading: false,
    ;

    this.buttonAnimated = new Animated.Value(0);
    this.growAnimated = new Animated.Value(0);
    this._onPress = this._onPress.bind(this);
  

  _onPress() 
    if (this.state.isLoading) return;

    this.setState(isLoading: true);
    Animated.timing(this.buttonAnimated, 
      toValue: 1,
      duration: 200,
      easing: Easing.linear,
    ).start();

    setTimeout(() => 
      this._onGrow();
    , 2000);

    setTimeout(() => 
      Actions.secondScreen();
      this.setState(isLoading: false);
      this.buttonAnimated.setValue(0);
      this.growAnimated.setValue(0);
    , 2300);
  

  _onGrow() 
    Animated.timing(this.growAnimated, 
      toValue: 1,
      duration: 200,
      easing: Easing.linear,
    ).start();
  

  render() 
    const changeWidth = this.buttonAnimated.interpolate(
      inputRange: [0, 1],
      outputRange: [DEVICE_WIDTH - MARGIN, MARGIN],
    );
    const changeScale = this.growAnimated.interpolate(
      inputRange: [0, 1],
      outputRange: [1, MARGIN],
    );

    return (
      <View style=styles.container>
        <Animated.View style=width: changeWidth>
          <TouchableOpacity
            style=styles.button
            onPress=this._onPress
            activeOpacity=1>
            this.state.isLoading ? (
              <Image source=spinner style=styles.image />
            ) : (
              <Text style=styles.text>LOGIN</Text>
            )
          </TouchableOpacity>
          <Animated.View
            style=[styles.circle, transform: [scale: changeScale]]
          />
        </Animated.View>
      </View>
    );
  


const styles = StyleSheet.create(
  container: 
    flex: 1,
    top: -95,
    alignItems: 'center',
    justifyContent: 'flex-start',
    marginTop: 100,
  ,
  button: 
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor : '#48a4ff',
    height: MARGIN,
    borderRadius: 20,
    zIndex: 100,
  ,
  circle: 
    height: MARGIN,
    width: MARGIN,
    marginTop: -MARGIN,
    borderWidth: 1,
    borderColor: 'blue',
    borderRadius: 100,
    alignSelf: 'center',
    zIndex: 99,
    backgroundColor: '#48a4ff',
  ,
  text: 
    color: 'white',
  ,
  image: 
    width: 24,
    height: 24,
  ,
);

【问题讨论】:

应用在调试模式下运行正常吗? 是的。一旦我使用 react-native run-android 命令安装了应用程序,它就很好了,我用 run-android log-android 检查了日志。没有错误。但在 apk 文件中我有 . 【参考方案1】:

问题不在于我的代码,我使用一组代码来访问设备位置,因此在更高版本的 Android 设备中失败出于安全原因强>。

我通过参考下面的链接解决了这个问题,

How do I request permission for Android Device Location in React Native at run-time?

【讨论】:

以上是关于单击登录按钮后,React 本机发布签名的 apk 文件崩溃的主要内容,如果未能解决你的问题,请参考以下文章

在本机反应中处理设备后退按钮

React Native v0.59.2 android签名apk卡在启动画面

单击后如何在 React Native 中禁用按钮

反应本机抽屉导航在按钮单击时不起作用

React本机IOS,当TextInput获得焦点时,按钮按下不注册

在本机反应中生成多个APK?