amplitude / Amplitude-Android

Native Android SDK for Amplitude
MIT License
164 stars 90 forks source link

StrictMode policy violation on initialize #190

Open jush opened 5 years ago

jush commented 5 years ago

We've StrictMode enabled in our app and we see the following policy violation:

StrictMode policy violation; ~duration=301 ms: android.os.strictmode.DiskReadViolation
        at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1504)
        at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:251)
        at java.io.File.exists(File.java:815)
        at android.app.ContextImpl.ensurePrivateDirExists(ContextImpl.java:605)
        at android.app.ContextImpl.ensurePrivateDirExists(ContextImpl.java:596)
        at android.app.ContextImpl.getDatabasesDir(ContextImpl.java:835)
        at android.app.ContextImpl.getDatabasePath(ContextImpl.java:814)
        at android.content.ContextWrapper.getDatabasePath(ContextWrapper.java:327)
        at com.amplitude.api.DatabaseHelper.<init>(DatabaseHelper.java:80)
        at com.amplitude.api.DatabaseHelper.getDatabaseHelper(DatabaseHelper.java:64)
        at com.amplitude.api.AmplitudeClient.initialize(AmplitudeClient.java:228)
        at com.amplitude.api.AmplitudeClient.initialize(AmplitudeClient.java:202)
        at <our_own_package>.<init>(AmplitudeClient.kt:22)

As seen in https://github.com/amplitude/Amplitude-Android/blob/master/src/com/amplitude/api/AmplitudeClient.java#L252 the database is opened in the thread calling the initialize.

Is there any chance that DB initialization could be moved inside the runOnLogThread to avoid accessing disk?

prashanOS commented 2 years ago

This seems to still be an issue in 2.36.1.

haoliu-amp commented 2 years ago

Hello, all. We just released our new generation Android SDK. You can try to use this one instead. It doesn't have any 3rd party dependencies. @prashanOS