Closed HosseinArabbeigi closed 4 years ago
@HosseinArabbeigi did you ever find a resolution to this? I've also been seeing crashes from an Android app I released to some test users but I can't reproduce it locally. My crash log is:
Caused by java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at org.slf4j.LoggerFactory.class$(LoggerFactory.java:214)
at org.slf4j.LoggerFactory.findPossibleStaticLoggerBinderPathSet(LoggerFactory.java:214)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:125)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
at org.zeroturnaround.zip.ZipUtil.<clinit>(ZipUtil.java:70)
at org.zeroturnaround.zip.ZipUtil.unpack(ZipUtil.java:1045)
at [my app's call to unpack()]
All online searches I've been seeing have suggested adding the SLF4J jar to the project. For Android, I decided to simply add it as a dependency to my build.gradle
:
implementation 'org.slf4j:slf4j-api:1.7.30'
Because I can't reproduce this on any of my own test devices, I'm not sure if this will work or not. Love to hear if you got resolution on this. Or better if we could get the library owners' (@toomasr) insight on this. Perhaps an option to disable logging might be useful in worse case scenarios.
Hi @brianliyang I did change my way to zip it, here is my code and it works fine, hope to be useful:
To zip:
File backupZip = new File(BACKUP_ZIP_FILE_PATH);
ZipParameters params = new ZipParameters();
params.setEncryptFiles(true);
params.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
params.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
params.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
params.setPassword(ZIP_PASSWORD);
ZipFile zipFile = new ZipFile(ZIP_FILE_PATH);
zipFile.addFolder(BACKUP_CACHE_ZIP_FOLDER_PATH, params);
And to extract zip file:
ZipFile zip = new ZipFile(ZIP_FILE_PATH);
zip.setPassword(BACKUP_ZIP_PASSWORD);
zip.extractAll(EXTRACTION_DIRECTORY_PATH);
File extractedFolder = new File(EXTRACTED_FOLDER_PATH);
Interesting.
For any Android folks, adding implementation 'org.slf4j:slf4j-api:1.7.30'
to my dependencies did seem to fix this issue.
Yeah, adding the dependency is the correct solution. I'll try to explain what is going on in the background.
The JDK itself added support for proper logging in the version 1.4 but already by that time there were better solutions out there and people were using commons-logging or log4j or something else. There are many logging frameworks for Java and each is improving some aspect of logging. Here is an overview https://en.wikipedia.org/wiki/Java_logging_framework#section8
SLF4J which is used in zt-zip is a Logging Wrapper. Once we do our logging through the SLF4J then actually every library user can choose which underlying framework they use because SLF4J is a wrapper. It does mean that zt-zip references the API classes of SLF4J as the minimal point of integration and expects to find the slf4j-api in the runtime classpath. It is quite cheap to add that because the sfl4j-api is just bunch of no operation method calls.
You can check out http://www.slf4j.org/android/ for the Android specific runtime so that the logging through SLF4J show up in the Google Android platform log environment.
@HosseinArabbeigi did you ever find a resolution to this? I've also been seeing crashes from an Android app I released to some test users but I can't reproduce it locally. My crash log is:
Caused by java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory at org.slf4j.LoggerFactory.class$(LoggerFactory.java:214) at org.slf4j.LoggerFactory.findPossibleStaticLoggerBinderPathSet(LoggerFactory.java:214) at org.slf4j.LoggerFactory.bind(LoggerFactory.java:125) at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107) at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269) at org.zeroturnaround.zip.ZipUtil.<clinit>(ZipUtil.java:70) at org.zeroturnaround.zip.ZipUtil.unpack(ZipUtil.java:1045) at [my app's call to unpack()]
All online searches I've been seeing have suggested adding the SLF4J jar to the project. For Android, I decided to simply add it as a dependency to my
build.gradle
:
implementation 'org.slf4j:slf4j-api:1.7.30'
Because I can't reproduce this on any of my own test devices, I'm not sure if this will work or not. Love to hear if you got resolution on this. Or better if we could get the library owners' (@toomasr) insight on this. Perhaps an option to disable logging might be useful in worse case scenarios.
This works, just add it to you app/build.gradle and re-run
Hi there! Thanks for amazing library, i have crash on zipping a folder. code :
ZipUtil.pack(new File(BACKUP_CACHE_FOLDER_PATH), backupZip); //source and target files exists
error :