Isolate routing change listeners for API 23 and API 24 in AudioTrack - #2
Merged
Merged
Conversation
Owner
|
thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This description was translated by Google.
Summary
We have prepared a class loading isolation fix to address an issue where AudioTrackAudioOutput throws a NoClassDefFoundError due to the lack of the AudioRouting interface in Android 6.0 (SDK level 23).
Details
Gramophone crashed on Android 6.0 and higher when testing compatibility and robustness at FoedusProgramme/Gramophone#1003.
android.media.AudioRoutingis a class introduced in Android 7.0 (API 24), and it doesn't exist in the framework of Android 6.0 (API 23, SDK Level 23). When a routing change event occurs on an API 23 device, the lambda generated inside this class is executed. ART throws ajava.lang.NoClassDefFoundErrorbecause it cannot find theAudioRoutingtype when loading/validating the class members associated with this lambda.On July 24, 2026, c9501075 introduced a new compatibility layer, re-based the media3 submodule on upstream code containing the new audio architecture (NativeTrack / AudioOutputProvider).
During this re-based upstream code process, commit 73c8dcd ("Added route change listeners to API 23 as well") was made. However, when modifying
AudioTrackAudioOutput.java, theAudioRoutinginterface of API 24 and the listening logic of API 23 were written in the same inner class, causing the class loader to throw aNoClassDefFoundErrorerror on Android 6.0 devices due to the lack ofAudioRouting. Therefore, I made the following changes:In
media3 AudioTrackAudioOutput.java, a unified private interfaceOnRoutingChangedListenerwas defined, and arelease()method was declared.The original single implementation class, which mixed API 23 and API 24, was split into two independent implementation classes:
@RequiresApi(23) private static final class OnRoutingChangedListenerApi23: Only referencesandroid.media.AudioTrack.OnRoutingChangedListener, which exists in API 23, and no longer references any higher-version types.@RequiresApi(24) private static final class OnRoutingChangedListenerApi24: Referencesandroid.media.AudioRouting.OnRoutingChangedListener, which was introduced in API 24.In the
AudioTrackAudioOutputconstructor, the corresponding listener implementation class is instantiated based on theSDK_INTbranch condition:If
SDK_INT >= 24, thenOnRoutingChangedListenerApi24is instantiated.If
SDK_INT >= 23, thenOnRoutingChangedListenerApi23is instantiated.If this value is lower than API 23, no route listener is created.