使用log4j记录器时出现NoClassDefFoundError

时间:2017-04-29 08:24:57

标签: java android logging log4j

我正在使用log4j将日志存储在我的Android设备中的文件中。

以下是我的依赖项:

compile 'de.mindpipe.android:android-logging-log4j:1.0.3'
compile 'log4j:log4j:1.2.17'

以下是我的getLogger方法:

public static Logger getLogger(Class clazz, String logType) {
    String logsFolderName;
    logsFolderName = Environment.getExternalStorageDirectory().toString() + File.separator + PlayerProperties.logsFolder + File.separator;

    String logFilePrefix = PlayerProperties.androidId ;
    String logFileName = logFilePrefix + "_" + getCurrentDateString() + ".log";

    if (!(new File(logsFolderName).exists())) {
        new File(logsFolderName).mkdirs();
    }

    String absoluteFileName = new File(logsFolderName, logFileName).getAbsolutePath();
    logConfigurator.setFileName(absoluteFileName);
    logConfigurator.setRootLevel(Level.INFO);
    logConfigurator.setLevel("org.apache", Level.INFO);
    logConfigurator.setUseFileAppender(true);
    logConfigurator.setFilePattern("%d %-5p [%c{2}]-[%L] %m%n");
    logConfigurator.setMaxFileSize(1024 * 1024 * 3); // each log file max size - 3 MB
    logConfigurator.setImmediateFlush(true);
    logConfigurator.configure();
    Logger log = Logger.getLogger(clazz);
    return log;
}

用法:

public static Logger LOGGER = ALogger.getLogger(StorageTools.class);

虽然这在迄今为止使用的所有Android设备中都能很好地工作,但是一个特定的Android设备(版本4.4.2)会引发以下异常:

04-29 08:10:02.982 3880-3880/com.blynq.app.multipaneplayer E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.blynq.app.multipaneplayer, PID: 3880
    java.lang.NoClassDefFoundError: org.apache.log4j.Logger
        at de.mindpipe.android.logging.log4j.LogConfigurator.setLevel(LogConfigurator.java:118)
        at com.blynq.app.tools.ALogger.getLogger(ALogger.java:49)
        at com.blynq.app.tools.ALogger.getLogger(ALogger.java:28)
        at com.blynq.app.tools.StorageTools.<clinit>(StorageTools.java:37)
        at com.blynq.app.multipaneplayer.MainPlayer.setPlayerDefaultConfiguration(MainPlayer.java:162)
        at com.blynq.app.multipaneplayer.MainPlayer.initiatePlayer(MainPlayer.java:99)
        at com.blynq.app.multipaneplayer.MainPlayer.onResume(MainPlayer.java:91)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1206)
        at android.app.Activity.performResume(Activity.java:5473)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2778)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2817)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
        at android.app.ActivityThread.access$800(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
        at dalvik.system.NativeStart.main(Native Method)

有人可以帮我理解这个问题吗?

0 个答案:

没有答案