6

There's this weird exception in Samsung phones specifically Galaxy S7 Edge, which we noticed in Fabric crash reports:

Fatal Exception: java.lang.RuntimeException: Unable to instantiate receiver com.someapp: java.lang.ClassNotFoundException: Didn't find class "com.someapp" on path: DexPathList[[zip file "/data/app/com.someapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.someapp-1/lib/arm, /system/fake-libs, /data/app/com.someapp-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
   at android.app.ActivityThread.handleReceiver(ActivityThread.java:3331)
   at android.app.ActivityThread.-wrap20(ActivityThread.java)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1734)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6688)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

Caused by java.lang.ClassNotFoundException: Didn't find class "com.someapp" on path: DexPathList[[zip file "/data/app/com.someapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.someapp-1/lib/arm, /system/fake-libs, /data/app/com.someapp-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
   at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
   at android.app.ActivityThread.handleReceiver(ActivityThread.java:3326)
   at android.app.ActivityThread.-wrap20(ActivityThread.java)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1734)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6688)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

As a feedback from users, this error happens only when app is in the background and there's not interaction with it, I think the issue lies in the way Samsung's device rom tries to minimize background tasks or put them in a special memory and our app is not ready and this happens.

The point is the exception is not pointing to any class of the app so we can trace the issue, If anyone has encountered this problem before please help!

Rez
  • 4,501
  • 1
  • 30
  • 27
  • http://stackoverflow.com/questions/33313101/dexindexoverflowexception-only-when-running-tests – IntelliJ Amiya Apr 05 '17 at 09:29
  • 1
    did you enable multidex in your app? – Manohar Apr 05 '17 at 09:30
  • Yep, Its enabled but this doesnt have anything to do with multidex, at least I think so – Rez Apr 05 '17 at 11:00
  • Hi, I had a problem with classloaders using compat libs. I've "workaround" it changing the classloader before each of my json deserialization. Maybe it is somehow related and you can fix it the same way: http://stackoverflow.com/questions/31070976/flexjson-classnotfound-exception-on-android-4-4-4 – eduyayo Apr 10 '17 at 11:20
  • try to add android:largeHeap="true" in manifest. – parik dhakan Apr 11 '17 at 04:03
  • @MohammadReza please post your `build.gradle` and `Manifest` please – IntelliJ Amiya Apr 11 '17 at 09:06
  • @eduyayo Thanks for your comment, but in no way its associated with Json deserialization, it happens in the background while app is doing nothing – Rez Apr 13 '17 at 07:56
  • @parikdhakan It's already turned on – Rez Apr 13 '17 at 07:57
  • @IntelliJAmiya Nothing special in the build.gradle, a few dependencies and multidex is turned on – Rez Apr 13 '17 at 07:57
  • enable multiDex in the gradle : multiDexEnabled true – Jéwôm' Apr 13 '17 at 09:19
  • 1. Do you use ProGuard? 2. I see lib/armeabi-v7a in crash report, but Samsung Galaxy works in 64 bit mode, so it uses arm64-v8a – AndreyICE Apr 13 '17 at 09:39
  • Is there a chance that this is a duplicate of http://stackoverflow.com/questions/9601373/unable-to-instantiate-receiver-java-lang-classnotfoundexception Check the accepted answer. – BhalchandraSW Apr 13 '17 at 14:54
  • Are you saying "com.someapp" is the actual class returned in the error? This wasn't sanitized before posting? – Pablo Baxter Apr 14 '17 at 17:11
  • @PabloBaxter Its my app's package name!, the thing is it doesnt point to any class of my app just says the package name's broadcast is not registered! – Rez Apr 15 '17 at 08:26
  • @BhalchandraSW nope! there's no unregistered broadcast receiver in my code! – Rez Apr 15 '17 at 08:27
  • Can you post the manifest? – Pablo Baxter Apr 17 '17 at 16:18
  • pls, try changing the classloader. if you see the link, I've opened an issue in google devrs site telling the classloader changes and have to be restored. They call this a feature... – eduyayo Apr 19 '17 at 07:43

2 Answers2

0

try this.. its work for me where i have the same problem on different devices

add compile 'com.android.support:multidex:1.0.1' to your dependencies.

make sure you put multiDexEnabled true in defaultConfig

then add this in your Application class

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
ZeroOne
  • 8,996
  • 4
  • 27
  • 45
0

From Marshmallow, Google has introduced a new feature/mode called Doze. According to official documents

Starting from Android 6.0 (API level 23), Android introduces two power-saving features that extend battery life for users by managing how apps behave when a device is not connected to a power source. Doze reduces battery consumption by deferring background CPU and network activity for apps when the device is unused for long periods of time. App Standby defers background network activity for apps with which the user has not recently interacted.

You can read it here in detail.

In Nougat, it has been more optimized.

I believe the problem is actually the Doze feature. I don't know if there's any way to prevent this, but you can manually do it. You can refer here and here for more detail

Waqas Ahmed Ansari
  • 1,683
  • 15
  • 30
  • I'm afraid this'd be the case, because this just happens on samsung phones, especially S7 Edge – Rez Apr 15 '17 at 08:28