Skip to content

ANRs when calling Purchases#configure #2818

Description

@RenanLukas

Describe the bug
We're experiencing ANRs in our app. After debugging with StrictMode enabled, we discovered that Purchases.configure() is performing disk I/O operations on the main thread.

  1. Environment

    1. Platform: Android
    2. SDK version: 9.12.2
    3. OS version: minSdk: 28, targetSdk: 35, compileSdk: 35
    4. Android Studio version: Android Studio Otter | 2025.2.1
    5. How widespread is the issue. Percentage of devices affected: Unknown - detected through StrictMode in debug builds, likely affects all devices when Purchases.configure() is called on the main thread
  2. Debug logs that reproduce the issue

StrictMode policy violation; ~duration=170 ms: android.os.strictmode.DiskReadViolation
	at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1683)
	at libcore.io.BlockGuardOs.access(BlockGuardOs.java:74)
	at libcore.io.ForwardingOs.access(ForwardingOs.java:128)
	at android.app.ActivityThread$AndroidOs.access(ActivityThread.java:8582)
	at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:332)
	at java.io.File.exists(File.java:829)
	at android.app.ContextImpl.ensurePrivateDirExists(ContextImpl.java:819)
	at android.app.ContextImpl.ensurePrivateCacheDirExists(ContextImpl.java:815)
	at android.app.ContextImpl.getCacheDir(ContextImpl.java:926)
	at android.content.ContextWrapper.getCacheDir(ContextWrapper.java:328)
	at com.revenuecat.purchases.paywalls.FontLoader.<init>(FontLoader.kt:30)
	at com.revenuecat.purchases.PurchasesFactory.createPurchases(PurchasesFactory.kt:325)
	at com.revenuecat.purchases.PurchasesFactory.createPurchases$default(PurchasesFactory.kt:68)
	at com.revenuecat.purchases.Purchases$Companion.configure(Purchases.kt:1105)
...
  1. Steps to reproduce, with a description of expected vs. actual behavior
  • Enable StrictMode with disk read detection in the Application class
  • Call Purchases.configure() on the main thread
  • Observe StrictMode violation and potential ANR

Expected behavior:
Purchases.configure() should not perform disk I/O operations on the main thread.

Actual behavior:
Purchases.configure() performs disk I/O operations on the main thread and can cause ANRs.

  1. Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.)

Additional context
This issue appears to be related to #1629, which also reports ANRs when calling Purchases.configure() on the main thread.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions