Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is 'android.security.MessageDigest''?

Tags:

One of several thousand customers reported an error in one of my apps. The error is:

java.lang.NoClassDefFoundError - android.security.MessageDigest 

I don't use that class/method in my apps. The Google Mapkey must be ok because there are thousands running the same app with the same version happily. Here's the stacktrace:

java.lang.NoClassDefFoundError: android.security.MessageDigest at com.google.android.maps.KeyHelper.getSignatureFingerprint(KeyHelper.java:60) at com.google.android.maps.MapActivity.createMap(MapActivity.java:552) at com.google.android.maps.MapActivity.onCreate(MapActivity.java:422) at xx.yyy.zzzz.MyMapActivity.onCreate(MyMapActivity.java:41) at xx.yyy.zzzz.TheMap.onCreate(TheMap.java:89) at android.app.Activity.performCreate(Activity.java:4465) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) at android.app.ActivityThread.access$600(ActivityThread.java:123) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) 

What is this?

Thanks in advance.

like image 787
Harald Wilhelm Avatar asked Jul 10 '12 06:07

Harald Wilhelm


People also ask

Is a message digest algorithm?

Message Digest Algorithm 5 (MD5) is a cryptographic hash algorithm that can be used to create a 128-bit string value from an arbitrary length string. Although there has been insecurities identified with MD5, it is still widely used. MD5 is most commonly used to verify the integrity of files.


1 Answers

I spent some time looking into this problem, and I'm documenting what I've found here in the hopes that it saves other people some trouble.

The error is the result of a device manufacturer or ROM creator using an older maps library with a new version of Android. Typically, this is isolated to obscure tablets, but it could theoretically appear in other situations. It's possible to recreate this problem in an emulator using following these steps:

  1. Create and load an emulator for an older API (10 or less) which includes the Google APIs
  2. Extract the maps jar from the emulator: adb pull /system/framework/com.google.android.maps.jar <destination_folder> You can close the emulator once you've done this.
  3. Create and load an emulator for a new API (11 or above) which includes the Google APIs
  4. Remount /system in the emulator so you can write to it: adb remount
  5. Put the extracted maps jar into the new emulator: adb push <destination_folder>/com.google.android.maps.jar /system/framework
  6. Reboot the emulator. This is supposed to be doable by adb reboot but that just hung the emulator. Instead, you'll need to kill a particular process which has the same effect. In Eclipse/DDMS it will be called system_process and you can kill it there. Alternatively, you can run this command:adb shell ps | grep system_server | awk '{print $2}' | xargs adb shell kill
  7. After reboot you can use the emulator as you normally would. Running any app with an embedded Google map will fail.

This process isn't permanent. Restarting the emulator reverts it to its normal working state.

It's possible to detect this problem by getting the KeyHelper.getSignatureFingerprint() method in the maps library via reflection and invoking it - passing a PackageManager and your package name as arguments. Alternatively, you can trap the error in onCreate() and load a new activity instead.

like image 78
blazeroni Avatar answered Jan 03 '23 12:01

blazeroni