getsentry / sentry-dart

Sentry SDK for Dart and Flutter
https://sentry.io/for/flutter/
MIT License
745 stars 231 forks source link

Not possible to read external files directory. #831

Closed kasipavankumar closed 2 years ago

kasipavankumar commented 2 years ago

Platform:

IDE:

split-debug-info and obfuscate (Flutter Android or iOS) or CanvasKit (Flutter Web):

Platform installed with:

Output of the command `flutter doctor -v` below: ``` [???] Flutter (Channel stable, 2.10.3, on Microsoft Windows [Version 10.0.19044.1645], locale en-IN) ??? Flutter version 2.10.3 at K:\Data\Flutter\flutter ??? Upstream repository https://github.com/flutter/flutter.git ??? Framework revision 7e9793dee1 (6 weeks ago), 2022-03-02 11:23:12 -0600 ??? Engine revision bd539267b4 ??? Dart version 2.16.1 ??? DevTools version 2.9.2 [???] Android toolchain - develop for Android devices (Android SDK version 31.0.0) ??? Android SDK at K:\Data\Android\SDK ??? Platform android-31, build-tools 31.0.0 ??? Java binary at: K:\Program Files\Android\Android Studio\jre\bin\java ??? Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822) ??? All Android licenses accepted. [???] Chrome - develop for the web ??? Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe [X] Visual Studio - develop for Windows X Visual Studio not installed; this is necessary for Windows development. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [???] Android Studio (version 2021.1) ??? Android Studio at K:\Program Files\Android\Android Studio ??? Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter ??? Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart ??? Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822) [???] VS Code (version 1.66.2) ??? VS Code at C:\Users\\AppData\Local\Programs\Microsoft VS Code ??? Flutter extension version 3.38.1 [???] Connected device (4 available) ??? TA 1053 (mobile) ??? D1AGAD1751906384 ??? android-arm64 ??? Android 9 (API 28) ??? Windows (desktop) ??? windows ??? windows-x64 ??? Microsoft Windows [Version 10.0.19044.1645] ??? Chrome (web) ??? chrome ??? web-javascript ??? Google Chrome 100.0.4896.88 ??? Edge (web) ??? edge ??? web-javascript ??? Microsoft Edge 100.0.1185.39 [???] HTTP Host Availability ??? All required HTTP hosts are available ! Doctor found issues in 1 category. ```

The version of the SDK (See pubspec.lock): 6.4.0


I have initialized Sentry using the runZonedGuarded approach and there are 3 messages (included in Actual Result section) logged to the console. Initialization roughly looks like as shown below:

Steps to reproduce

void main() {
  runZonedGuarded(
    () async {
      WidgetsFlutterBinding.ensureInitialized();

      await ConfigReader.initialize();
      await KeyValueStorageBase.init();

      // Lock app orientations to just potrait.
      SystemChrome.setPreferredOrientations([
        DeviceOrientation.portraitUp,
        DeviceOrientation.portraitDown,
      ]);

      // Reads the environment variable for APP_ENV.
      final appEnv = AppConfig.AppEnv;

      // Initialize app with Sentry only when running in "production" or "stage".
      if ([AppEnv.production.name, AppEnv.stage.name].contains(appEnv)) {
        debugPrint('App running in $appEnv .. initializing Sentry.');
        debugPrint('Got Sentry DSN: ${AppConfig.SentryDSN}');

        await SentryFlutter.init(
          (options) => options
            ..dsn = AppConfig.SentryDSN
            ..environment = appEnv
            ..tracesSampleRate = 1.0,
          appRunner: () => runApp(
            const App(),
          ),
        );
      } else {
        debugPrint('App running in development mode.');
        runApp(const App());
      }
    },
    (error, trace) async {
      await Sentry.captureException(error, stackTrace: trace);
    },
  );
}

With the aforementioned rough initialization and running the app in debug mode using flutter run, the issue can be reproduced.

Solutions tried

Here are few things I have tried to verify that this issue occurs on any device:

  1. The device I usually run this app, is configured to use the SD card as the internal storage. My first thought was regarding this, so I changed devices but still getting the same error.
  2. Last month, I had used Sentry (v6.3.0) with another app, which had no issues whatsoever. So, I downgraded to v6.3.0 but still the same issue.
  3. After searching for similar issues (surprisingly the results were scarce and not related to Dart), few people suggested to add the "external storage" permissions in AndroidManifest.xml, still the same issue.
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  4. This is related to point 3, that the "external storage" permissions are required to be obtained during runtime, which was done using the permission_handler package but to no avail.

Actual result

Sentry does not catch any exceptions. Instead, it throws the following logs:

# The following 2 logs show up during the initial booting of the application.
D/Sentry  ( 6892): SU isn't found on this Device.

W/pool-3-thread-1( 6892): type=1400 audit(0.0:2417): avc: denied { read } for name="version" dev="p:s0:c216,c256,c512,c768 tcontext=u:object_r:proc_version:s0 tclass=file permissive=0

# This is logged whenever Sentry encounters an exception.
I/Sentry  ( 6892): Not possible to read external files directory

Expected result

marandaneto commented 2 years ago

Not possible to read external files directory is just an info logging, not a bug, since the device does not have an external drive.

If yo are using the custom runZonedGuarded approach, you cannot use the appRunner callback to init your App, just go with runApp(const App()); after the Sentry SDK is init.