-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
Support SDK 31 + Gradle 7 + Android 12 #836
Comments
Thanks for the report and reproduction project. I've relabeled it as a bug. Although I haven't installed the Android 12 beta yet, I have updated the code in the |
Yes, with Those two lint errors are still there though, but it does not seem like they affect anything (if the |
This lint really confuses me.
As for this:
Well, This S/O post seems to be related, but my Gradle file looks like it has the right dependency: https://stackoverflow.com/questions/62282686/cant-use-mediabrowserservicecompat |
I've fiddled around with the code a bit, changing this and that, but also couldn't figure out how to "satisfy" those lint errors. It may as well be some bug in the Gradle, since this I guess it can be ignored then. Or maybe suppressed? But suppressed where exactly? In the |
What the S/O post made me think of is that there might be multiple versions of the same class in the build system due to the way dependencies are all built and merged, so it could be getting confused because of this. |
Yes, I also had that thought. But So, basically I have no idea how to fix it and why it happens. :) |
Right, so what I was guessing is that there might be multiple versions of the |
I've removed all dependencies, but still get those lint errors. git clone https://github.com/z80maniac/audio_service_sdk31_gradle7_nodeps.git
cd audio_service_sdk31_gradle7_nodeps/audio_service/example/
flutter build apk |
On the other hand, an empty Flutter project with just an empty git clone https://github.com/z80maniac/mediabrowserservicecompat_test.git |
Yep, complete mystery, but the situation is reminiscent of the same issues that can happen with class loaders at runtime, so here we could have two different versions of the https://developer.android.com/studio/write/lint.html#config Maybe an IDE would have some tool to update the appropriate files (although I don't use an IDE). |
Turns out this error happens in diff --git a/audio_service/example/android/app/src/main/AndroidManifest.xml b/audio_service/example/android/app/src/main/AndroidManifest.xml
index 974cd99..7913e65 100644
--- a/audio_service/example/android/app/src/main/AndroidManifest.xml
+++ b/audio_service/example/android/app/src/main/AndroidManifest.xml
@@ -31,13 +31,23 @@
</intent-filter>
</activity>
- <service android:name="com.ryanheise.audioservice.AudioService" android:exported="true">
+ <service
+ android:name="com.ryanheise.audioservice.AudioService"
+ android:exported="true"
+ xmlns:tools="http://schemas.android.com/tools"
+ tools:ignore="Instantiatable"
+ >
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
- <receiver android:name="com.ryanheise.audioservice.MediaButtonReceiver" android:exported="true">
+ <receiver
+ android:name="com.ryanheise.audioservice.MediaButtonReceiver"
+ android:exported="true"
+ xmlns:tools="http://schemas.android.com/tools"
+ tools:ignore="Instantiatable"
+ >
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter> Since these errors can't be suppressed in the library itself, maybe it makes sense to mention this case in the docs? |
The build process should merge the plugin's So yes, probably the README and example should be updated. |
I decompiled the
This will be a breaking change then. And it's probably an overkill for just silencing a linter. |
I have this error with audio_service 0.18.1, how I can fix it?
|
Hi @prilepskiy , the current work to fix it is on the |
Any plans to merge |
Unfortunately there is still an unresolved problem so I can't merge it yet. I currently have Gradle flagging warnings as errors (as a quality control measure) and while that's what I want, the current solution to this issue generates warnings when compiling a release build. For now, you can use the branch directly, but I'm also open to feedback on this if you were able to solve this issue yourself. |
Yeah, I'm using it via
I'll try to see what can be done to resolve these warnings. Thanks for explanation ! |
Hey, I created a fork and fixed locally lint errors. Please take a look on #871 |
Hi @squallsama , thanks. I'll take a look at it. Although I just realised I have some stashed changes that I haven't committed/pushed yet, in the gradle and manifest files which I think do some of the same things in this PR. Let me compare and see if there are any significant differences. |
Also, it would be great if you provide command line which I can use to check if lint errors still exists or not. For now I used |
I've just pushed my local (previously uncommitted) changes. I don't see any difference with your PR aside from version 7.0.3 instead of 7.0.2 in gradle, except mainly that your PR doesn't update the example to target Android 12 (maybe that's why it's working for you??) In any case, can you try my latest commit to see if you are able to reproduce the issue? |
Sure. And also I'll try to update example to target android 12. |
@ryanheise It's working, tested on real device with android 12 (Galaxy S21+), #887 builds fine but notification does not appear Audio_service_android12.mp4. |
Thanks for testing, @BecoStopclub . Did you apply the same changes to your manifest as in the example? Does the example work for you? If that's the case, you should be able to copy what it does, otherwise let me know if the example is also failing for you. |
@ryanheise I didn't try the example or change the manifest, I just overwritten to use I can test more later today :) |
@ryanheise Sorry for the delay. |
Thanks for testing that. Regarding the issue with the notification not showing in your own app, the only difference I can see is that you have |
Hi @ryanheise, I ran a full test on the two available solutions: (branch: 1 -
|
configs | audio_service's example | My Own app |
---|---|---|
service.exported=true && receiver.exported=true | OK | OK |
service.exported=true && receiver.exported=false | OK | OK |
service.exported=false && receiver.exported=true | OK | OK |
service.exported=false && receiver.exported=false | OK | OK |
2 - PR #887
Compiles, the notification appears when you press PLAY for the first time, but if you press STOP and PLAY again, it doesn't appear anymore.
configs | audio_service's example | My Own app |
---|---|---|
service.exported=true && receiver.exported=true | FAIL | FAIL |
service.exported=true && receiver.exported=false | FAIL | FAIL |
service.exported=false && receiver.exported=true | FAIL | FAIL |
service.exported=false && receiver.exported=false | FAIL | FAIL |
Both audio_services's example
and My own app
running with:
- compileSdkVersion 31
- targetSdkVersion 31
@BecoStopclub I'm curious why it failed before and worked now given the same |
@ryanheise My comment about not working was related to PR #887 (was tagged above). Sorry for the misunderstanding, English is not my first language. |
Ah, sorry it was my misunderstanding since you did mention that earlier. It's good to know |
We had to update a project to sdkVersion 31 and this popped up for us too. This branch fixes and we're able to run our project again! |
@ryanheise Doesn't work for me. Got the same Instantiatable lint errors when tried to build in release mode. If I moved the service & receiver elements to the package's AndroidManifest.xml then it will build fine. Those will be merged with the main AndroidManifest during the build process. You can take a look at the changes here: mehayhe@5827ff9 |
Can confirm that it does not work (unless you add Regarding |
Just to clarify: the main problem (and the reason I submitted this issue in the first place) was actually fixed long ago (the application crash). Now just this weird linter error remains. AFAIK it can be safely ignored - I've built my own music player app with that Maybe that branch should be released since it actually fixes the initial problem? And that linter error is a completely separate problem for which a fix can be released separately. |
That's certainly interesting. Although hard coding this in the package is also problematic since it hard codes certain components and can cause issues with manifest merging when an app tries to define custom components. |
Out of curiosity, why did you add |
I've tested with real device Android 12 using this branch |
I should still address the issue mentioned in my previous comment. Maybe you can try setting |
I tried the
or
|
That's surprising, but sure enough the documentation also says it is so: https://developer.android.com/studio/write/tool-attributes#error_handling_attributes In that case, I think I'll go with that approach for the official example and README just because it will cause less friction. |
Hmm, I don't remember... Maybe I was testing against the main branch where the |
On second thought, adding it on each component causes less friction since most developers will copy and paste the service and receiver component declarations whole. |
I've just committed some changes to the This updates the README and the example with the lint ignore. Since it has been working for me recently even without the lint ignore, I can't test this, but if anyone who had the lint errors can just test this release candidate, let me know and I'll push out a release. |
After merging
|
Thanks for testing! I might update the path_provider dependency given the compile note, and I notice the latest path_provider targets Android 12. |
Thanks all for contributing with both testing and research regarding the lint issue. I've now published the fix in release 0.18.3. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with audio_service. |
Is your feature request related to a problem? Please describe.
The
audio_service
library cannot be used when an application is targeting SDK 31 and uses Gradle 7 and runs on Android 12.When you use this setup then the application just crashes upon start.
This was actually reported earlier here: #796
I'm basically reporting the same thing while trying to provide more info and follow the issue template.
This GitHub issue is about a crash, but I'm writing it as a feature request because when you use the SDK and Gradle versions from "the example" (in this repo) everything works as expected. So it's a feature request to support the new versions of SDK and Gradle because I think the support for these new versions is relevant in terms of future-proofing and may help to catch some hidden bugs in the current code.
The crash only happens when all these conditions are met:
For example, the app runs correctly when SDK = 30 or when Gradle version is lower than 7 or when it runs on Android 11 or lower.
Steps to reproduce:
It's a fork of your repo with needed modifications:
git diff
Go to
audio_service/example
.Connect a device or emulator that runs Android 12 with SDK 31 (I used the emulator from Android Studio: Pixel 4 + Android S x86_64 with Play Services).
Run
flutter build apk
.It will give two lint errors (which are ignored):
lint errors
These lint errors were also reported here: #822
I'm not sure if they are relevant to the subject (they also appear when targeting SDK 30 with Gradle 7).
Also, these errors don't happen on debug build. Maybe because of lint settings.
Anyway, these two lint errors may not be relevant at all, but I just decided to include them just in case.
flutter run
. It will just crash immediately upon launch. It will also crash on release version.Now here's a tricky part. Flutter may not give you the actual error right away. Sometimes it just crashes with a cryptic error messages:
Lost connection to device.
Error connecting to the service protocol: failed to connect to http://127.0.0.1:43925/3ebPWbNkhco=/
Error initializing DevFS: DevFSException(Service disconnected, _createDevFS: (112) Service has disappeared, null)
But sometimes it will give you the actual error (or at least I believe that it's the actual error that causes the crash). It takes me usually around 10-15 times of invoking
flutter run
to get some meaningful output. Maybe there's a reliable way to show this error without a trial-and-error, but I don't know it.Here is the full output with the actual error:
I believe that the source of the crash is this:
Describe the solution you'd like
The application should not crash.
Describe alternatives you've considered
The only workaround is to not use this specific combination: SDK 31 + Gradle 7 + Android 12.
Additional context
flutter doctor
The text was updated successfully, but these errors were encountered: