【问题标题】:React-Native: Crashes on android when using openCamera using react-native-image-crop-picker and Camera in generalReact-Native:通常使用 react-native-image-crop-picker 和 Camera 使用 openCamera 时在 android 上崩溃
【发布时间】:2019-05-19 08:08:30
【问题描述】:

一段时间以来,我在我的一加 6 上打开相机时遇到了 react-native-image-picker 和 react-native-image-crop-picker 的问题。 使用打开相机时,打开相机的后台应用程序(我的应用程序)崩溃。它进入白屏并重新启动应用程序。 此外,react-native log-android 中没有日志。 我确实设法使用 android studio 和 logcat 发现,一旦相机打开,应用程序就会立即崩溃并留下一个死进程。 问题是我找不到任何实际的崩溃日志。 虽然事先我得到了很多“访问拒绝找到属性“vendor.debug.egl.swapinterval””,但经过一些研究后似乎并不相关。

这个问题目前只发生在我的一加 6T 上。这些问题不会出现在模拟器或 IOS 上。即使不是在我尝试过的 xiamoi 设备上。

我已经尝试了所有方法,从在图像裁剪选择器(代码一)中压缩图像,到尝试压缩图像并在 react-native-image-picker 中使用 noData 标志(代码二)。 另外,100% 有权限,甚至可以在 App permmision => {my app} 的 android 系统权限中看到 此外,我尝试清理我的一加 6t 相机的缓存,卸载并重新安装我的应用程序,并将开发者选项重置为默认值。

我基本上已经在 github 中为这两个库解决了所有问题,但没有任何效果。

ImagePicker.openCamera({
                width: 800,
                height: 600,
                compressImageMaxWidth: 640,
                compressImageMaxHeight: 480,
                compressImageQuality: 0.8
            }).then(image => {
                console.log(image);
            }).catch(e => console.log(e));
ImagePicker.launchCamera({noData: true, maxWidth: 800, maxHeight: 600, quality: 0.8}, (response) => {
  console.log('Response = ', response);

  if (response.didCancel) {
    console.log('User cancelled image picker');
  } else if (response.error) {
    console.log('ImagePicker Error: ', response.error);
  } else if (response.customButton) {
    console.log('User tapped custom button: ', response.customButton);
  } else {
    console.log(response)
  }
});

添加我的清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="------">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-feature android:name="android.hardware.camera" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.front" android:required="false" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:largeHeap="true"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="true"
      android:supportsRtl="true"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize"
        android:launchMode="singleTop"
      >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
        <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
            </intent-filter>
        </service>
        <provider
                android:name="android.support.v4.content.FileProvider"
                android:authorities="${applicationId}.provider" android:exported="false"
                android:grantUriPermissions="true"> <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths" /> </provider>
    </application>

</manifest>

预期的结果是收回承诺。并且应用程序在打开相机时不会崩溃。

很想得到一些意见。我有这个问题超过 2 周了。

【问题讨论】:

标签: react-native react-native-android react-native-image-picker


【解决方案1】:

我通过将 OxygenOS 从 9.0.4 更新到 9.0.5 使其工作。

我遇到了完全相同的问题,同时尝试了 react-native-image-picker 和 react-native-image-crop-picker。它在 Android 和 iOS 模拟器上运行良好,但在设备(一加 6)上却不行。但是当它在同事的同一部手机上运行时,事情就开始了!

确保您尝试发布版本。就我而言,我必须从 https://github.com/Yalantis/uCrop 为 native-image-crop-picker 添加一些 ProGuard 规则

【讨论】:

  • 我实际上使用的是 OxygenOS 9.0.13。我会尝试检查发布版本。希望这能解决这个问题。
  • 好的,所以它可能不是确切的版本问题,但 OxygenOS 9.0.14 刚刚修复了它。
  • 好的,我很高兴它有帮助。我对 Android 的了解不够,无法确切知道问题出在哪里。
【解决方案2】:

复制一下

<provider 
    android:name="android.support.v4.content.FileProvider" 
    android:authorities="${applicationId}.provider" android:exported="false" 
    android:grantUriPermissions="true"> <meta-data 
    android:name="android.support.FILE_PROVIDER_PATHS" 
    android:resource="@xml/provider_paths" /> </provider>

进入你的主项目 android manifest。

【讨论】:

  • 我试过了,但没有帮助,我会发布我的最帅的,也许我做错了什么。
猜你喜欢
  • 2020-03-13
  • 2021-09-28
  • 2022-11-08
  • 2021-12-02
  • 1970-01-01
  • 1970-01-01
  • 2020-07-17
  • 1970-01-01
  • 2021-05-11
相关资源
最近更新 更多