Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Crashes on Launch After Adding "mic_stream" Dependency on Android TV and Chromecast with Google TV #80

Open
LiTipo opened this issue Oct 6, 2023 · 12 comments

Comments

@LiTipo
Copy link

LiTipo commented Oct 6, 2023

description of the Issue:
I added the mic_stream package (version 0.7.1) as a dependency in a basic Flutter demo app. The app crashes upon launch when tested on Android TV and Chromecast with Google TV. It's worth noting that I haven't added any code related to mic_stream in the main program (main.dart).

expected behavior:
The app should launch normally after adding the mic_stream dependency.

actual behavior:
The app crashes upon launch after adding the mic_stream dependency.

steps to reproduce:

  1. Create a new Flutter demo app.
  2. Add mic_stream (version 0.7.1) as a dependency in pubspec.yaml.
  3. Try launching the app on Android TV or Chromecast with Google TV.

my environment:

  • Flutter Version: 3.13.6
  • Dart Version: 3.1.3
  • mic_stream Version: 0.7.1
  • Target Android Version: 10 and above
  • Physical Device: Chromecast with Google TV
  • Emulator: Android TV (1080p) API 30

Sample main.dart Code from Demo App:
Below is the test code from my demo app's main.dart. Note that I haven't modified any code or added anything related to mic_stream in this demo app.

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

Build Warning Logs:
When I build the APK for release using flutter build apk --release, I receive the following warnings related to mic_stream, which I suspect might be related to the issue:

PS C:\Users\User\Documents\VScode\flutter\chromcast_test_app> flutter build apk --release

Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 1336 bytes (99.9% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Note: C:\Users\User\AppData\Local\Pub\Cache\hosted\pub.dev\mic_stream-0.7.1\android\src\main\java\com\code\aaron\micstream\MicStreamPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\User\AppData\Local\Pub\Cache\hosted\pub.dev\mic_stream-0.7.1\android\src\main\java\com\code\aaron\micstream\MicStreamPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Running Gradle task 'assembleRelease'...                           58.9s
√  Built build\app\outputs\flutter-apk\app-release.apk (17.4MB).

I am unable to resolve these warnings with my current level of expertise, and I believe they could be contributing to the issue.

additional Information:
I have also tried another similar package, flutter_sound (version 8.1.4), and it works fine in the same environment.

special Note:
I have some projects that are already heavily dependent on mic_stream, so making changes would require a significant amount of time. Nevertheless, I'm still hopeful and writing here with a request for the author to please address this issue. Thank you!

@anarchuser
Copy link
Owner

Thank you for your report. I will see if I can do anything to address this issue. It's going to take some time though.
Also, I cannot test it on the physical device but if an emulated Android TV works it should be fine.

Now - did an earlier version of the plugin previously work? I expect it not to but if you find the time please test it.
Also, the same app works just fine for other devices, even with 0.7.1, is that right?

Most importantly, can you provide crash logs? If you can give me something to work with before I can reproduce the issue this may speed up the process significantly.

Lastly, the warnings you mentioned are old, they exist since the beginning of the plugin. I also haven't found a way to get rid of them. They come from the Java backend, probably from one of the few packages I'm using to record audio or to send it to flutter. I deem it unlikely to be the issue, since I think the Java backend part should not get started until a stream is requested (this I need to double check though, as it sounds like a potential source of errors for devices maybe not properly implementing said Java packages)

@LiTipo
Copy link
Author

LiTipo commented Oct 6, 2023

Thank you for your report. I will see if I can do anything to address this issue. It's going to take some time though. Also, I cannot test it on the physical device but if an emulated Android TV works it should be fine.

Now - did an earlier version of the plugin previously work? I expect it not to but if you find the time please test it. Also, the same app works just fine for other devices, even with 0.7.1, is that right?

Most importantly, can you provide crash logs? If you can give me something to work with before I can reproduce the issue this may speed up the process significantly.

Lastly, the warnings you mentioned are old, they exist since the beginning of the plugin. I also haven't found a way to get rid of them. They come from the Java backend, probably from one of the few packages I'm using to record audio or to send it to flutter. I deem it unlikely to be the issue, since I think the Java backend part should not get started until a stream is requested (this I need to double check though, as it sounds like a potential source of errors for devices maybe not properly implementing said Java packages)

Thank you for your prompt response.

  1. Older Versions: I will take some time to test previous versions of the plugin and report back on whether any of them work without issues.
  2. Other Devices: Yes, the app seems to work fine on other devices with version 0.7.1 of the plugin. The issue appears to be specific to Android TV and Chromecast with Google TV.
  3. Crash Logs: I am working on capturing the crash logs and will provide them as soon as possible to help you better understand the issue.
  4. Java Backend Warnings: I understand that the warnings are unlikely to be the root cause. If I come across any further insights, I'll be sure to share them.

I understand that resolving this issue will take time, and I appreciate your efforts to look into it. Thank you.

@LiTipo
Copy link
Author

LiTipo commented Oct 6, 2023

I have tested other versions of the mic_stream plugin, specifically versions ^0.6.0, ^0.6.5, ^0.5.0, and ^0.4.0. All of these versions run fine on other devices, but they fail to work on Chromecast with Google TV.

Additionally, I've tested the app on various other physical devices including Samsung A42, Samsung A53, Samsung A31, and NOKIA X71, and it runs smoothly on all these smartphones. Interestingly, the app also works well on NVIDIA Shield TV, which is another Android TV device. However, it crashes specifically on Chromecast with Google TV.

@LiTipo
Copy link
Author

LiTipo commented Oct 6, 2023

I have tested other versions of the mic_stream plugin, specifically versions ^0.6.0, ^0.6.5, ^0.5.0, and ^0.4.0. All of these versions run fine on other devices, but they fail to work on Chromecast with Google TV.

Additionally, I've tested the app on various other physical devices including Samsung A42, Samsung A53, Samsung A31, and NOKIA X71, and it runs smoothly on all these smartphones. Interestingly, the app also works well on NVIDIA Shield TV, which is another Android TV device. However, it crashes specifically on Chromecast with Google TV.

Unfortunately, my current Chromecast with Google TV device does not support USB debug mode and cannot be rooted, making it difficult for me to obtain crash logs. Do you have any other methods for retrieving these reports?

@LiTipo
Copy link
Author

LiTipo commented Oct 6, 2023

Regarding the Java backend warnings, here are some suggestions that may help:

  1. Check Deprecated APIs: You might want to go through the deprecated APIs that the plugin is using or overriding and see if there are any newer, more secure alternatives.

  2. Recompile with -Xlint:deprecation and -Xlint:unchecked: This can provide more details about which specific APIs are deprecated or which operations are unchecked.

  3. Code Review: A thorough code review, especially in the parts where the warnings are coming from, could be beneficial. Make sure all the Java packages and classes being used are up-to-date and compatible with the target platforms.

  4. Testing Across Environments and Devices: Even if the Java backend warnings may not be the root cause, testing on different devices and environments might reveal more insights.
    by GPT-4

This is a response from GPT-4. It may help you resolve the Java issues.

@anarchuser
Copy link
Owner

Unfortunately, my current Chromecast with Google TV device does not support USB debug mode and cannot be rooted, making it difficult for me to obtain crash logs. Do you have any other methods for retrieving these reports?

No, especially not in such an early state. Best bet would be to try to reproduce it on an emulated system

@anarchuser
Copy link
Owner

I have tested other versions of the mic_stream plugin, specifically versions ^0.6.0, ^0.6.5, ^0.5.0, and ^0.4.0. All of these versions run fine on other devices, but they fail to work on Chromecast with Google TV.

Additionally, I've tested the app on various other physical devices including Samsung A42, Samsung A53, Samsung A31, and NOKIA X71, and it runs smoothly on all these smartphones. Interestingly, the app also works well on NVIDIA Shield TV, which is another Android TV device. However, it crashes specifically on Chromecast with Google TV.

Thank you, that is roughly as anticipated. The configuration and packages used never changed much. I suspect it has something to do with the native AudioRecord backend

@anarchuser
Copy link
Owner

Regarding the Java backend warnings, here are some suggestions that may help:

  1. Check Deprecated APIs: You might want to go through the deprecated APIs that the plugin is using or overriding and see if there are any newer, more secure alternatives.

  2. Recompile with -Xlint:deprecation and -Xlint:unchecked: This can provide more details about which specific APIs are deprecated or which operations are unchecked.

  3. Code Review: A thorough code review, especially in the parts where the warnings are coming from, could be beneficial. Make sure all the Java packages and classes being used are up-to-date and compatible with the target platforms.

  4. Testing Across Environments and Devices: Even if the Java backend warnings may not be the root cause, testing on different devices and environments might reveal more insights.
    by GPT-4

This is a response from GPT-4. It may help you resolve the Java issues.

haha I will see what I can do. Until now this never has been an issue and I attributed it to the fact that the backend is written in Java 8. Literally everything should be deprecated.

@LiTipo
Copy link
Author

LiTipo commented Oct 7, 2023

Unfortunately, my current Chromecast with Google TV device does not support USB debug mode and cannot be rooted, making it difficult for me to obtain crash logs. Do you have any other methods for retrieving these reports?

No, especially not in such an early state. Best bet would be to try to reproduce it on an emulated system

I've tested the app on an emulated Google TV (API 30) and various Pixel phone models using the emulator, and mic_stream functions correctly on those. However, the app still crashes specifically on the physical Chromecast with Google TV device.

I've also tried using other recording apps as well as the "Spectroid" app to test sound graphs and spectrograms, and all these other apps function correctly on the device.

This concludes my testing report for now. I apologize for the inconvenience and appreciate your time and effort in looking into this issue. Thank you!

@anarchuser
Copy link
Owner

I've had a look through the native code looking for some obvious flags. There is definitely static code getting executed; not a lot but it's a start.

Now, until I figure out a way to reproduce the issue, I can only rely on your cooperation to debug this. So if you want, clone this repo, checkout branch fix/80/android-tv-crash, and build the example app. If the change from 69f3bba is the issue, the example crash shouldn't crash on launch (though it will when you press the recording button).

@LiTipo
Copy link
Author

LiTipo commented Oct 11, 2023

Thank you for providing the branch for testing. Here are my findings after building the example app:fix/80/android-tv-crash

  • On the emulator, the app launches and functions as expected.
  • On the Nvidia Shield TV physical device, the app launches successfully but crashes, as you anticipated, when the recording button is pressed.
  • On Chromecast with Google TV, the app still crashes immediately upon launch, which is not the expected behavior of simply launching successfully.

It seems that the issue persists specifically on Chromecast with Google TV, even with the changes from the branch.fix/80/android-tv-crash

@anarchuser
Copy link
Owner

thank you for your report.
Another thing you can try is a very old version of the plugin, e.g., 0.1.2. A major rework happened around 0.2.0; before that the native backend was notably simpler. If need be, I can prepare a snapshot on the test branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants