11

Since past 2 months, we have started receiving native crashes in our developer console only for some Samsung devices.

Here is the crash trace

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/ha3gjv/ha3g:5.0/LRX21V/N9000QXXUEBOG3:user/release-keys'
Revision: '11'
ABI: 'arm'
pid: 10422, tid: 10478, name: AsyncTask #2  >>> com.sample.app <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1c
    r0 131413a0  r1 131413a0  r2 b1687070  r3 00262827
    r4 00000349  r5 131413a0  r6 00000000  r7 00000002
    r8 131412c0  r9 af071800  sl 87783218  fp 13141360
    ip 000031d0  sp 9530e8c0  lr 7446c91f  pc a0a83596  cpsr 000f0030

backtrace:
    #00 pc 001bc596  /data/dalvik-cache/arm/data@app@com.sample.app-2@base.apk@classes.dex
    #01 pc 0008091d  /system/framework/arm/boot.oat

And here is the list of devices where crashes have been received till date -

Galaxy S6 (zeroflte)
Galaxy S6 Edge+ (zenltevzw)
Galaxy A5(2016) (a5xelte)
Galaxy S5 Neo (s5neolte)    
Galaxy S6 Edge (zerolte)    
Galaxy S6 (zerofltetmo)
Galaxy Note3 (ha3g)
Galaxy J7 (j7elte)
Galaxy Note4 (trelte)
Galaxy S5 (k3g)
Galaxy Alpha (slte)

Any ideas on why it is happening?

Here is build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "com.test" 
        minSdkVersion 14
        targetSdkVersion 22
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile files('libs/okhttp-2.4.0.jar')
    compile files('libs/okhttp-urlconnection-2.4.0.jar')
    compile files('libs/okio-1.4.0.jar')
    compile files('libs/mediaplayersdk.jar')


    compile 'com.google.android.gms:play-services-analytics:8.4.0'
    compile 'com.google.android.gms:play-services-ads:8.4.0'
    compile 'com.android.support:appcompat-v7:23.1.0'
}
Floern
  • 33,559
  • 24
  • 104
  • 119
user669231
  • 1,371
  • 3
  • 18
  • 27

2 Answers2

7

According to Android native crash initiating from /system/framework/arm/boot.oat this error is produced on some Samsung devices when apk is zipaligned using Zopfli.

According to your build.gradle you are using buildToolsVersion "23.0.0" so I would say that your apk is zipaligned using Zopfli and this is the source of the problem that you are finding (Zopfli was added in version 21.0.0).

Note that when you generate your apk using Build -> Generate Signed APK your apk is automatically zipaligned. From the documentation:

zipalign is an archive alignment tool that provides important optimization to Android application (.apk) files

To solve it, you can avoid automatically zipalign adding on zipAlignEnabled false to the release section of your build.gradle:

release {
    //...
    zipAlignEnabled false
}

Then, you need to generate your apk again (you can check that your apk is not zipaligned running zipalign -c -v 4 yourapk.apk. It will output Verification FAILED) and then manually zipalign the apk using the zipalign instructions, avoiding the -z option.

zipalign -f -v 4 yourapk.apk yourzipalignedapk.apk

Other option is to change the buildToolsVersion to, for example 20.0.0 (the zipalign tool in this version doen't include Zopfli) but this is not recommended (From the documentation):

You should always keep your Build Tools component updated by downloading the latest version using the Android SDK Manager. By default, the Android SDK uses the most recent downloaded version of the Build Tools. If your projects depend on older versions of the Build Tools, the SDK Manager allows you to download and maintain separate versions of the tools for use with those projects.

Community
  • 1
  • 1
antonio
  • 18,044
  • 4
  • 45
  • 61
  • Thanks Antonio for the detailed answer. Will try this and confirm if this resolves the issue. However, one doubt that I have is that I too have multiple Android 5.0 & Android 5.1 devices, but couldn't reproduce the issue. So can it be the case that the issue is happening randomly and not on all devices? – user669231 Apr 15 '16 at 02:42
  • 1
    Yes, I think that the issue can happen randomly or only on some devices. This kind of problems are very annoying because they are really hard to track. Please, let me know if you make any progress – antonio Apr 19 '16 at 06:41
  • @user669231 Any news on this topic? Did it help? Would be great if you could give some insights and accept this answer if it helped. –  Oct 24 '16 at 10:42
  • @antonio wondering why zipalign manually can solve this issue? What's the difference? – Nick Jian Feb 10 '17 at 08:57
  • @antonio and what is zipalign "-z" for?? couldn't find anything about it. edit: -z: recompress using Zopfli – Nick Jian Feb 10 '17 at 08:59
  • @Nick Jian, zipalign optimizes the apk files and some Samsung devices seem to be somehow incompatible. From [this](https://code.google.com/p/android/issues/detail?id=223511) (Sep 23, 2016), *zipalign -z is no longer supported on buildtools 2.2+* – antonio Feb 10 '17 at 09:02
  • To sum up, Samsung should stop making new Android devices. – Kimi Chiu Jul 18 '18 at 03:12
0

I found the proper solution here. By using

 -keep class !android.support.v7.internal.view.menu.**,android.support.v7.**      {*;}

instead of

 -keep class android.support.v7.** {*;}
Community
  • 1
  • 1
Dinesh
  • 482
  • 9
  • 20