Skip to content

fix(android): prevent crash in getHasGms() when play-services-base is missing#42

Merged
l2hyunwoo merged 2 commits intomainfrom
fix/prevent-has-gms-crash
Dec 1, 2025
Merged

fix(android): prevent crash in getHasGms() when play-services-base is missing#42
l2hyunwoo merged 2 commits intomainfrom
fix/prevent-has-gms-crash

Conversation

@l2hyunwoo
Copy link
Owner

Issue

close #40

Summary

Fixes getHasGms() to gracefully return false instead of crashing when play-services-base dependency is not included in the app.

Problem

When an Android app does not include the play-services-base dependency, calling getHasGms() would crash with a JNI exception. This occurred because:

  1. GoogleApiAvailability.getInstance() throws NoClassDefFoundError when the class cannot be loaded
  2. NoClassDefFoundError extends Error, not Exception
  3. The existing catch (e: Exception) block did not catch Error types
  Throwable
  ├── Exception  ← catch (e: Exception) catches this
  └── Error
      └── LinkageError
          └── NoClassDefFoundError  ← This was NOT caught

Solution

Changed error handling from catch (e: Exception) to catch (e: Throwable) to catch all error types including NoClassDefFoundError.

  // Before
  catch (e: Exception) {
      Log.w(NAME, "GMS not available or GMS library not found", e)
      false
  }

  // After
  catch (e: Throwable) {
      Log.d(NAME, "GMS not available or GMS library not found", e)
      false
  }

Also changed log level from Log.w (warning) to Log.d (debug) since missing GMS is an expected scenario for apps distributed on non-GMS stores.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a crash in getHasGms() when the play-services-base dependency is not included in an Android app. The fix changes the exception handling to catch Throwable instead of just Exception, which allows the method to gracefully handle NoClassDefFoundError and return false instead of crashing.

Key Changes:

  • Modified exception handling from catch (e: Exception) to catch (e: Throwable) to catch NoClassDefFoundError
  • Changed log level from Log.w (warning) to Log.d (debug) as missing GMS is an expected scenario
  • Enhanced documentation with detailed comments explaining the rationale

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…hrowable

Address PR review feedback: catching Throwable is too broad and can mask
serious JVM errors like OutOfMemoryError or StackOverflowError.

Now catches Exception and NoClassDefFoundError separately for more
explicit error handling.
@l2hyunwoo l2hyunwoo merged commit 43f43b2 into main Dec 1, 2025
5 checks passed
@l2hyunwoo l2hyunwoo deleted the fix/prevent-has-gms-crash branch December 1, 2025 23:54
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.

getHasGms() throws JNI exception when play-services-base is not included

2 participants