nomis/slf4j-android

crash in android 2.2: String.isEmpty() and Locale.ROOT not found

Closed this issue · 2 comments

k3b commented

slf4j uses methods that are not implemented in android 2.2

  • method java.lang.String.isEmpty()
    • referenced from method eu.lp0.slf4j.android.LoggerFactory.getConfig
    • referenced from method eu.lp0.slf4j.android.LoggingConfig.
    • could be easily replaced by ((string == null) || (string.length() == 0))
  • Static field java.util.Locale.ROOT
    • referenced 2 times from LoggingConfig.LoggingConfig()
    • could be easily replaced by Locale.US

runtime:

  • android 2.2 on emulator
  • lib 'org.slf4j', name: 'slf4j-api', version:'1.7.7'
  • lib 'eu.lp0.slf4j:slf4j-android:1.7.6-0'

here is the debug output.

I/dalvikvm﹕ Could not find method java.lang.String.isEmpty, referenced from method eu.lp0.slf4j.android.LoggerFactory.getConfig
W/dalvikvm﹕ VFY: unable to resolve virtual method 524: Ljava/lang/String;.isEmpty ()Z
D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0010
D/dalvikvm﹕ VFY: dead code 0x0013-0044 in Leu/lp0/slf4j/android/LoggerFactory;.getConfig (Ljava/lang/String;)Leu/lp0/slf4j/android/LoggerConfig;
I/dalvikvm﹕ Could not find method java.lang.String.isEmpty, referenced from method eu.lp0.slf4j.android.LoggingConfig.
W/dalvikvm﹕ VFY: unable to resolve virtual method 524: Ljava/lang/String;.isEmpty ()Z
D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x006e
D/dalvikvm﹕ DexOpt: couldn't find static field
W/dalvikvm﹕ VFY: unable to resolve static field 195 (ROOT) in Ljava/util/Locale;
D/dalvikvm﹕ VFY: replacing opcode 0x62 at 0x00ce
I/dalvikvm﹕ Could not find method java.lang.String.isEmpty, referenced from method eu.lp0.slf4j.android.LoggingConfig.
W/dalvikvm﹕ VFY: unable to resolve virtual method 524: Ljava/lang/String;.isEmpty ()Z
D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x00e1
D/dalvikvm﹕ DexOpt: couldn't find static field
W/dalvikvm﹕ VFY: unable to resolve static field 195 (ROOT) in Ljava/util/Locale;
D/dalvikvm﹕ VFY: replacing opcode 0x62 at 0x0120
I/dalvikvm﹕ Could not find method java.lang.String.isEmpty, referenced from method eu.lp0.slf4j.android.LoggingConfig.
W/dalvikvm﹕ VFY: unable to resolve virtual method 524: Ljava/lang/String;.isEmpty ()Z
D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0133

W/dalvikvm﹕ Exception Ljava/lang/NoSuchMethodError; thrown during Lde/k3b/android/cellinfo/demo/CellInfoDemoActivity;.
W/dalvikvm﹕ Class init failed in newInstance call (Lde/k3b/android/cellinfo/demo/CellInfoDemoActivity;)
E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.ExceptionInInitializerError
            ...
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NoSuchMethodError: java.lang.String.isEmpty
            at eu.lp0.slf4j.android.LoggerFactory.getConfig(LoggerFactory.java:143)
            at eu.lp0.slf4j.android.LoggerFactory.getLogger(LoggerFactory.java:64)
            at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)
            at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:288)
            at de.k3b.android.cellinfo.demo.CellInfoDemoActivity.(CellInfoDemoActivity.java:34)
...

Are there any issues with the class files being in Java 1.6 format or is this information lost during conversion to dex format?

eu.lp0.slf4j:slf4j-android:1.7.7-1 is now available from Maven Central

k3b commented

Confirm codefix: eu.lp0.slf4j:slf4j-android:1.7.7-1 works as expected on my android-2.2 device. Thanks for fixing