React-navigation 在调试模式下工作正常,但在发布模式下不行

2024-01-01

几周以来我遇到了一个问题,我在我的react-native应用程序中使用react-navigation,当我在调试模式下在我的设备上测试时,我在屏幕之间正确导航,但是当我构建签名的apk时,导航不再工作。 我尝试了一切,但没有任何效果。

我正在使用react-native 0.61.2,react-navigation 4.0.10

这是我的 app/build.gradle 文件

project.ext.react = [
    entryFile: "index.js",
    enableHermes: false,  // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = true

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = true

/**
 * The preferred build flavor of JavaScriptCore.
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US.  Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'

/**
 * Whether to enable the Hermes VM.
 *
 * This should be set on project.ext.react and mirrored here.  If it is not set
 * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
 * and the benefits of using Hermes will therefore be sharply reduced.
 */
def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.lumennui"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk true  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://facebook.github.io/react-native/docs/signed-apk-android.
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }

        }
    }
}

dependencies {
    implementation project(':react-native-splash-screen')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-video')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

这是我的 android/gradle.build 文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.4.2")

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

这是我的根导航文件:

import React from 'react';
import { createAppContainer, createSwitchNavigator } from "react-navigation";
import Chat from "../screens/Chat";
import Welcome from "../screens/Welcome";

const rootNav = createSwitchNavigator({
        welcome: {screen: Welcome},
        chat: {screen: Chat},
    },
    {
        initialRouteName: 'welcome'
    }
);
const RootNavigation = createAppContainer(rootNav);

export default RootNavigation;

我的 app.js 文件:

import React from 'react';
import RootNavigation from "./navigations/RootNavigation"
import SnackbarProvider from "./components/SnackBar";

export default class App extends React.Component {

	render(){
		return (
            <SnackbarProvider>
                <RootNavigation/>
            </SnackbarProvider>
		);
	}
}

欢迎.js 文件:

import React from 'react'
import Header from "../components/Header"
import axios from 'axios'
import '../constants/serverAdress'
import {withSnackbar} from "../components/SnackBar"
import {
    Button,
    ImageBackground,
    Tile,
    Overlay,
    TextInput,
    Title,
    Subtitle,
    Text,
    Card,
    Caption,
    Image,
    View
} from "@shoutem/ui"
import luminy from '../assets/images/luminy.jpg'
import luminy2 from '../assets/images/luminy2.jpg'
import {KeyboardAvoidingView, ScrollView} from "react-native";
import { Provider, Portal, Modal} from "react-native-paper";
import moi from '../assets/images/moi.jpg'
import SplashScreen from 'react-native-splash-screen'

class Welcome extends React.Component {

    constructor(props) {
        super(props)
        this.state = {
            pseudo: '',
            visible: false
        }
        this.onSubmit = this.onSubmit.bind(this)
    }

    _showModal = () => this.setState({ visible: true });
    _hideModal = () => this.setState({ visible: false });

    function

    componentDidMount() {
        SplashScreen.hide()
    }

    onSubmit(e){
        e.preventDefault()
        const { snackbar, navigation } = this.props
        axios.post(`${SERVER_ADRESS}/register`, { pseudo: this.state.pseudo })
        .then(res => {
            if(res.data.status !== undefined){
                snackbar.showMessage(res.data.message)
            } else {
                navigation.navigate('chat', {
                    id : res.data._id,
                    pseudo: this.state.pseudo
                })
            }
        })
        .catch(error => {
            console.log(error)
        })
    }
    render() {
        return (
            <KeyboardAvoidingView
                behavior="padding"
                style={{flex: 1}}
            >
                <Header title="Welcome" help helpAction={this._showModal}/>
                <ImageBackground
                    styleName="large"
                    source={luminy2}
                >
                    <Tile>
                        <Overlay styleName="image-overlay">
                            <Title styleName="sm-gutter-horizontal">Bienvenue sur LumEnnui</Title>
                            <Subtitle>Saisis ou crée ton pseudo et commence à  .....</Subtitle>
                        </Overlay>
                    </Tile>
                </ImageBackground>
                <ImageBackground
                    styleName="large"
                    source={luminy}
                >
                    <TextInput
                        placeholder={'Pseudo'}
                        onChangeText={(text) => this.setState({pseudo: text})}
                    />
                    <Button
                        styleName="secondary"
                        style={{ marginTop: 20}}
                        onPress={this.onSubmit}
                    >
                        <Text>ACCEDER</Text>
                    </Button>
                </ImageBackground>
                {/*Modal section*/}
                <Provider>
                    <Portal>
                        <Modal visible={this.state.visible} onDismiss={this._hideModal}>
                            <Card style={{ width: 200, height: 400}}>
                                <Image
                                    styleName="medium-avatar"
                                    source={moi}
                                />
                                <View styleName="content">
                                    <ScrollView>
                                        <Subtitle>
                                           lorum ipsum
                                        </Subtitle>
                                        {/*<Subtitle style={{ color: 'red'}}>
                                            lorum ipsum
                                        </Subtitle>*/}
                                        <Caption>Créé par Mama DEMBELE aka Pakendux</Caption>
                                    </ScrollView>
                                </View>
                            </Card>
                        </Modal>
                    </Portal>
                </Provider>
            </KeyboardAvoidingView>
        );
    }
}
export default withSnackbar(Welcome)

预先非常感谢您的帮助


似乎他们在 0.60.2 捆绑中破坏了与 JS Core 相关的东西 - 我现在遇到了客户端的 puchdb 和后端的 couchdb 的类似问题。

32 位运行良好,直到我将 "metro-react-native-babel-preset": "0.56.3" 更新到最新版本 - 即使在 32 位版本中它也停止工作。 原因是在 RN 中,他们在调试 (Chrome V8) 和发布 (JSC) 中使用不同的 JS 引擎 - 在我看来这是一个相当值得怀疑的决定。对于 98% 的代码来说它是有效的,但在边缘情况下我们会遇到一些奇怪的问题...... 我要尝试一下RN V8 https://github.com/Kudo/react-native-v8

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

React-navigation 在调试模式下工作正常,但在发布模式下不行 的相关文章

  • Android 上的 MIDI:Java 和/或 AIR 库

    一段时间以来 我一直在考虑在 iPad 上 重新 构建一个应用程序 其中我将使用 Objective C 和DSMI http dsmi tobw net 将 MIDI 信号发送到主机 这还不错 我的意思是 除了实际编写应用程序之外 现在我
  • 当 minifyEnabled 为 true 时 Android 应用程序崩溃

    我正在使用多模块应用程序 并且该应用程序崩溃时minifyEnabled true in the installed模块的build gradle 以下是从游戏控制台检索到的反混淆堆栈跟踪 FATAL EXCEPTION Controlle
  • AsyncStorage 未解析或拒绝

    我正在尝试从异步存储中获取项目 componentDidMount console log componentDidMount AsyncStorage getItem STORAGE KEY then storage gt console
  • 将文本字段限制为仅包含数字的最佳方法?

    I m using the following Javascript to restrict a text field on my website to only accept numerical input and no other le
  • 如何使用 NextJS 使用自托管字体face?

    使用 NextJS 的字体 我已经阅读了有关如何在 NextJS 中使用自托管字体的不同主题 我得到了什么 wait compiling 当我这样做时 font face font family montserrat src url myp
  • Android模拟器中的网络访问

    我试图通过我的 Android 应用程序访问互联网 但我既成功又失败 我在构建应用程序时启动模拟器 并且应用程序安装得很好 我可以使用浏览器访问互联网 但是 当我尝试这个小代码片段时 InetAddress inet try inet In
  • 如何为 React 组件参数创建文字类型?

    我创建了 SelectProps 界面 export interface SelectProps value string options string onChange value any gt void 我创建了反应组件
  • onTaskRemoved() 在华为和小米设备中没有被调用

    我一直在使用onTaskRemoved 服务中的方法 用于检测应用程序何时通过滑动从设备最近列表中删除 我执行一些日志记录和发生这种情况时需要执行的一些其他操作 它工作完美 然后我在运行Android 6 0的华为设备上检查了这个方法 该方
  • Unity c# 四元数:将 y 轴与 z 轴交换

    我需要旋转一个对象以相对于现实世界进行精确旋转 因此调用Input gyro attitude返回表示设备位置的四元数 另一方面 这迫使我根据这个四元数作为默认旋转来计算每个旋转 将某些对象设置为朝上的简单方法如下 Vector3 up I
  • 此版本的 CLI 仅与 Angular 版本 5.0.0 或更高版本兼容错误

    我已经有 Angular 项目在 4 版本中运行 在安装新项目时 不幸的是我安装了 6 版本的 Angular cli 在以 4 版本运行的旧项目中运行 ngserve 命令时 这会引发错误 您的全局 Angular CLI 版本大于本地版
  • 如何将样式应用于我拥有的所有 TextView? [复制]

    这个问题在这里已经有答案了 可能的重复 设计所有 TextView 或自定义视图 的样式 而不向每个 TextView 添加样式属性 https stackoverflow com questions 6801890 styling all
  • 离子初始加载时间

    我正在使用 Ionic 构建一个简单的应用程序 但我的应用程序在冷启动时的初始加载时间方面存在性能问题 这是我所做的 collection repeat 代替带有 track by 的 ng repeat 原生滚动 overflow scr
  • 禁用 Android 菜单组

    我尝试使用以下代码禁用菜单组 但它不起作用 菜单项仍然启用 你能告诉我出了什么问题吗 资源 菜单 menu xml menu menu
  • fs-extra:源和目标不能相同。 (科尔多瓦)

    我在使用 cordova 构建时遇到错误 Error Source and destination must not be the same 构建系统 Ionic ionic cli 4 10 1 ionic framework ionic
  • 如果 jquery 验证激活,如何在单选按钮中放置红色边框[重复]

    这个问题在这里已经有答案了 我的问题是 如果 jquery 验证像示例图片中那样激活 我无法使单选按钮具有红色边框 任何人都可以帮我解决这个问题吗 http i38 photobucket com albums e149 eloginko
  • ECDH使用Android KeyStore生成私钥

    我正在尝试使用 Android KeyStore Provider 生成的私有文件在 Android 中实现 ECDH public byte ecdh PublicKey otherPubKey throws Exception try
  • 丢失应用程序的密钥库文件(但已启用 Google Play 应用程序签名)

    我已经失去了原来的keystore用于签署我的应用程序的文件 我的应用启用了 Google Play 应用签名 如果我联系 Google 支持人员 是否可以重置密钥 以便我可以继续上传到此包 我希望我可以做到这一点 因为应用程序签名已启用
  • VS Code 扩展 - 获取完整路径

    我正在为 VS Code 编写一个插件 我需要知道调用扩展的文件的路径 无论是从编辑器上下文菜单或资源管理器上下文菜单调用还是用户只需键入扩展命令 function activate context get full path of the
  • LifeCycleAware Fragment 中的片段生命周期事件

    我有一个生命周期感知片段和一个LifecycleObserver class public class MyFragment extends Fragment Override public void onCreate Nullable B
  • Android GetPTLAFormat 上的 Phonegap 错误

    我们正在开发一个使用 jQuery 移动和电话间隙的应用程序 一切似乎都工作正常 但是当在连接的 Android 手机上运行应用程序时 我们在 Eclipse logcat 中看到大量类似这样的错误 0 GetPTLAFormat inva

随机推荐

  • JQuery CORS 和重定向

    使用 JQuery 1 8 2 我正在从一个 AppServer 向应用程序发出 CORS 请求 Front 到另一个应用程序服务器 Back 服务器 当我进行以下 Ajax 调用时Front 来自的 302 响应 安全检查 Back很荣幸
  • 从 .tar.gz 将模块安装到 Anaconda

    当我想将模块安装到 Anaconda 时 我运行conda install 然而 现在我有一个 tar gz文件并想要安装它 怎么做 有多种方法可以实现此目的 我在这里描述一种方法 即使您的默认方法也应该相对简单python变量不是 ana
  • 更新应用商店错误 - 找不到启动故事板

    我的应用程序已在应用程序商店中发布 6 个月 我现在尝试发布更新 但在验证应用程序时遇到错误 找不到启动故事板 确保为 Info plist 中的键 UILaunchStoryboardName 指定不带文件扩展名的启动故事板文件名 我所做
  • 如何优化 TradingView Pine 脚本中的参数? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我想优化 TradingView Pine 回测中的指标参数 这对于其他工具来说是可能的 但是当我在
  • 使用 ggplot 在 R 中绘制多个大型时间序列时出现问题

    我有一个包含 16 个独立时间序列的大型数据集 我想将它们绘制在 3x7 网格中 顶行是每个以 IN 结尾的时间序列 底行是每个以 OUT 结尾的时间序列 在中间行中 我将重复对应于每个 IN OUT 对的以 RN 结尾的两个时间序列中的每
  • PDOStatement 包含什么以及 fetch/fetchAll 有什么用?

    我无法理解 1 PDOStatement 对象内部有什么以及 2 为什么我需要 fetch 或 fetchAll 方法 我的数据库 一个名为 动物 的简单表 有 3 列 id 名称 物种 My code try pdo new PDO ds
  • Clang 格式换行符

    我正在寻找一个clang format设置以防止工具删除换行符 例如 我有我的ColumnLimit设置为 120 这是我重新格式化一些示例代码时发生的情况 Before include
  • 根据另一个数组的内容对 C 数组进行排序

    我正在尝试对数组进行排序A其元素是索引 索引引用另一个数组B其值将决定顺序A 所以 我想排序A这样B A i 在增加 例如 A 0 1 4 5 7 B 5 3 8 2 2 7 1 6 3 9 Sorted A将会 A 7 4 1 0 5 这
  • 如何修复Python缩进

    我有一些 Python 代码的缩进不一致 大量制表符和空格的混合使情况变得更糟 甚至空格缩进也没有保留 该代码按预期工作 但难以维护 我怎样才能修复缩进 比如HTML 整洁 https en wikipedia org wiki HTML
  • 如何在echarts中添加渐变颜色?

    I made a echart line graph https stackblitz com edit angular aqghec file src 2Fapp 2Fapp component ts Now I want to add
  • 自定义 UItableView 在 ios8 上无法正确显示

    我做了一个定制UITableViewCell当我显示它时 我得到了这个结果 我在 iPhone 5 上运行 xcode 6 和 iOS 8 beta 1 https i stack imgur com 9Oswn png https i s
  • 只读时无法使用文本框获取文本?

    我有一个文本框
  • CSS Line-Through 未被删除

    我有一些代码可以在 TR 上为已删除的行添加一条直通线 但这意味着我的 操作 列 只有 按钮会受到影响 这是因为按钮之间存在单独的空间 这些空间最终也会被贯穿 在浏览了 W3Schools 后 我很困惑为什么这个例子不起作用 table t
  • 如何设置 tkinter textvariable 在单独的线程上运行?

    尝试使用 main 函数变量更新在线程上运行的 tkinter textvariable 我实现了一个基于线程的解决方案 因此 tkinter 主循环后面的代码可以运行 https stackoverflow com a 1835036 1
  • 如何使用功能状态生成随机数?

    我正在努力弄清楚如何将 State 的函数表示与 Scala 的 Random 类合并以生成随机整数 我正在从书上学习Scala 中的函数式编程 所以大部分代码都是从那里获取的 以下是 State 类的样子 直接来自书中 case clas
  • 使用 NSIS 安装程序向注册表项授予权限的有效方法是什么?

    我正在尝试使用访问控制插件 http nsis sourceforge net AccessControl plug in在 NSIS 中设置注册表项的权限 它不起作用 安装程序运行后 所有用户组没有完全控制权 我在下面创建了一个示例 这里
  • Eclipse:有没有办法在组织导入中强制导入来解决歧义?

    我在 android 项目上使用 Eclipse 我更新到 Lion 问题开始出现 尝试了几个小时 没有结果 问题是这样的 我有几十个文件com stuff morestuff在我的项目中 我想 ctrl shift O 我的项目 这样每个
  • VS2010单元测试“待处理”且测试无法完成

    我正在使用 VS2010 Windows 7 每次我尝试运行单元测试时 它都会保持 待处理 状态并且测试无法完成 我试着遵循这个msdn说明 http msdn microsoft com en us library ms182532 28
  • Netflix 如何在不刷新页面且无需 JavaScript 的情况下提交评分?

    我正在尝试为我的网站做一些类似 Netflix 的 5 星级评级系统的事情 我注意到 Netflix 即使禁用了 JavaScript 仍然会在不刷新页面的情况下提交评级 这是显而易见的 因为当您手动重新加载页面时 您可以看到新的评级 但是
  • React-navigation 在调试模式下工作正常,但在发布模式下不行

    几周以来我遇到了一个问题 我在我的react native应用程序中使用react navigation 当我在调试模式下在我的设备上测试时 我在屏幕之间正确导航 但是当我构建签名的apk时 导航不再工作 我尝试了一切 但没有任何效果 我正