Skip to content

Modernize legacy Leanback sample: Upgrade Gradle/SDK and migrate to Media3#225

Open
pflammertsma wants to merge 5 commits into
android:mainfrom
pflammertsma:leanback-media3-update
Open

Modernize legacy Leanback sample: Upgrade Gradle/SDK and migrate to Media3#225
pflammertsma wants to merge 5 commits into
android:mainfrom
pflammertsma:leanback-media3-update

Conversation

@pflammertsma

Copy link
Copy Markdown
Member

This PR modernizes the legacy Java-based Leanback sample app to ensure it compiles and runs correctly on modern Android developer environments and devices, preparing it to serve as a stable "before" baseline for the Compose migration.

Key Changes

  • Build Modernization: Upgraded Gradle to 8.7, AGP to 8.6.0, and JDK to 21. Updated compileSdk and targetSdk to 35.
  • Media3 Migration: Replaced the deprecated legacy ExoPlayer dependency with AndroidX Media3 (1.9.0) for video playback.
  • Bug & Compilation Fixes:
    • Fixed a compile error in SettingsFragment.java related to the findPreference API signature.
    • Enabled buildConfig and configured non-transitive R classes (android.nonTransitiveRClass=false) to resolve legacy resource compilation issues.
  • Startup Crash Fix: Disabled the background UpdateRecommendationsService on app launch. This service relied on the deprecated androidx.recommendation library which throws fatal IllegalArgumentExceptions when targeting API 31+ due to missing PendingIntent mutability flags.
  • Screenshot Script Updates: Optimized capture_screenshots.sh with increased delays to ensure stable UI loading before capturing, and regenerated all 10 screenshots at 1080p (1920x1080).

Paul Lammertsma added 4 commits July 7, 2026 11:55
- Migrate VideoPlayerGlue and PlaybackFragment from deprecated ExoPlayer 2 to AndroidX Media3.

- Add android:exported="true" to launcher activities in AndroidManifest.xml for Android 12+ compatibility.

- Add PendingIntent.FLAG_IMMUTABLE in RecommendationReceiver for Android 12+ alarm mutability compliance.

- Resolve static analysis and lint warnings (add hashCode() to Video, specify Locale.ROOT in VideoProvider, pass parent ViewGroup to inflate in IconHeaderItemPresenter, fix array declaration syntax).

TAG=agy

CONV=c90143f0-3646-4a01-89f5-44a5938a65f2
@pflammertsma
pflammertsma requested a review from chikoski as a code owner July 13, 2026 13:53

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modernizes the Leanback sample application by upgrading the target SDK to 35, updating Gradle to version 8.7, migrating from legacy ExoPlayer to AndroidX Media3, and introducing a central dependency catalog. It also adds a script to automate screenshot generation. The review feedback highlights several areas for improvement: fully disabling the deprecated recommendation service to prevent background crashes on API 31+, removing commented-out and dead code in MainFragment, using requireContext() and properly detaching PlaybackGlue in PlaybackFragment to avoid null pointer exceptions and memory leaks, and fixing a potential crash in the screenshot script when arguments are missing.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread Leanback/app/src/main/java/com/example/android/tvleanback/ui/MainFragment.java Outdated
Comment thread Leanback/screenshots/capture_screenshots.sh
@pflammertsma
pflammertsma force-pushed the leanback-media3-update branch 3 times, most recently from af9d286 to ca9a08f Compare July 14, 2026 16:41
…a3, and remove obsolete recommendations

- Upgrade Gradle to 8.7, AGP to 8.6.0, and JDK to 21, targeting SDK 35.
- Migrate video playback to AndroidX Media3 (1.9.0).
- Completely remove the obsolete and crashing recommendations functionality (androidx.recommendation library, RecommendationReceiver, and UpdateRecommendationsService).
- Fix compilation issues in SettingsFragment.java and resource resolutions.
- Use requireContext() and requireActivity() instead of getActivity() in PlaybackFragment for null-safety.
- Detach PlaybackGlue from its host in PlaybackFragment when releasing the player to prevent memory leaks.
- Improve robustness of capture_screenshots.sh with argument validation for the serial flag.
- Regenerate all screenshots at 1080p.
@pflammertsma
pflammertsma force-pushed the leanback-media3-update branch from 8faa72a to 909f873 Compare July 14, 2026 16:43
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

Successfully merging this pull request may close these issues.

2 participants