【问题标题】:WebView doesn't work after generate APK [React-Native]生成 APK [React-Native] 后 WebView 不起作用
【发布时间】:2017-05-26 07:32:47
【问题描述】:

我使用 Webview 与 PayPal 集成: 代码示例:

<Modal
                    animationType={"fade"}
                    transparent={false}
                    visible={this.state.modalVisible}
                    onRequestClose={() => {
                        alert("Modal has been closed")
                    }}
                    >
                        <WebView
                            source={ require('./PayPalIntegration.html')}
                            style={{flex: 10, width: width, height: height, margin: 20, alignItems: 'center', alignSelf: 'center'}}
                            javaScriptEnabled={true}
                            automaticallyAdjustContentInsets={true}
                        />
                        <TouchableOpacity style={{marginLeft: 10, marginBottom: 10,}}onPress={() => {
                            this.setState({ modalVisible: false})
                        }}>
                            <Text>
                                X Close
                            </Text>
                        </TouchableOpacity>
                    </Modal>

当我使用 Xcode 中的 iOS 模拟器、在 AndroidStudio 的 AVD 管理器上工作时它可以工作,并且当我将react-native run-android 直接用于我的设备时也可以工作。 但在生成 APK 并安装后,我只看到 ModalWebView 不起作用。

我做了几件事来尝试解决这个问题:

  1. 根据web view not loading page after exporting to signed APKweb view not loading page after exporting to signed APK

  2. ,我检查了 proguard 的配置,并根据此处的其他帖子,它已经是 FALSE
  3. 我根据JavascriptInterface on Android dont work with APK in release mode添加了-keepattributes JavascriptInterface

我必须说我只能在ANDROID上查看,因为我只能生成APK(没有苹果的开发者账号)

【问题讨论】:

  • 帮助某人...?
  • 您好,我知道这是旧的,但我在stackoverflow.com/a/50544869/2225316 发布了答案。那里的答案与此相关,并且适用于您的用例。
  • @BoomerRogers 谢谢!这是一个旧帖子,但仍然存在于同一个旧项目中。我会尝试使用您的解决方案修复它,并会尽快更新。

标签: react-native webview react-native-android react-native-ios


【解决方案1】:

尝试在AndroidManifest.xml的application标签下添加android:usesCleartextTraffic="true"。它应该如下所示。

<application
      .........
      .........
      android:usesCleartextTraffic="true"
      .........

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    • 2021-02-08
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多