jorabin / KeePassJava2

Java API for KeePass Password Databases - Read/Write 2.x (File versions 3 and 4), Read 1.x
Apache License 2.0
250 stars 71 forks source link

java.lang.NoSuchMethodError saving SimpleDatabase on Android #24

Closed lubbo closed 2 months ago

lubbo commented 4 years ago

When I save the SimpleDatabase

        val basePath = ContextWrapper(context).filesDir
        val credentials = KdbxCreds(credentials.toByteArray())
        val db = secureDatabase ?: return
        FileOutputStream("$basePath${File.separator}$database.kdbx").use { outputStream ->
            db.save(credentials, outputStream)
        }

I get this error:

java.lang.NoSuchMethodError: No static method encodeBase64String([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
        at org.linguafranca.pwdb.kdbx.Helpers.encodeBase64Content(Helpers.java:119)
        at org.linguafranca.pwdb.kdbx.simple.converter.Base64ByteArrayConverter.write(Base64ByteArrayConverter.java:38)
        at org.linguafranca.pwdb.kdbx.simple.converter.Base64ByteArrayConverter.write(Base64ByteArrayConverter.java:28)
        at org.simpleframework.xml.convert.AnnotationStrategy.write(AnnotationStrategy.java:180)
        at org.simpleframework.xml.convert.AnnotationStrategy.write(AnnotationStrategy.java:156)
        at org.simpleframework.xml.core.Source.setOverride(Source.java:384)
        at org.simpleframework.xml.core.Factory.setOverride(Factory.java:170)
        at org.simpleframework.xml.core.Composite.isOverridden(Composite.java:1312)
        at org.simpleframework.xml.core.Composite.writeElement(Composite.java:1234)
        at org.simpleframework.xml.core.Composite.writeUnion(Composite.java:1127)
        at org.simpleframework.xml.core.Composite.writeElements(Composite.java:1098)
        at org.simpleframework.xml.core.Composite.writeSection(Composite.java:1004)
        at org.simpleframework.xml.core.Composite.write(Composite.java:975)
        at org.simpleframework.xml.core.Composite.write(Composite.java:952)
        at org.simpleframework.xml.core.Composite.writeElement(Composite.java:1256)
        at org.simpleframework.xml.core.Composite.writeElement(Composite.java:1239)
        at org.simpleframework.xml.core.Composite.writeUnion(Composite.java:1127)
        at org.simpleframework.xml.core.Composite.writeElements(Composite.java:1098)
        at org.simpleframework.xml.core.Composite.writeSection(Composite.java:1004)
        at org.simpleframework.xml.core.Composite.write(Composite.java:975)
        at org.simpleframework.xml.core.Composite.write(Composite.java:952)
        at org.simpleframework.xml.core.Traverser.write(Traverser.java:236)
        at org.simpleframework.xml.core.Traverser.write(Traverser.java:208)
        at org.simpleframework.xml.core.Traverser.write(Traverser.java:186)
        at org.simpleframework.xml.core.Persister.write(Persister.java:1180)
        at org.simpleframework.xml.core.Persister.write(Persister.java:1162)
        at org.simpleframework.xml.core.Persister.write(Persister.java:1140)
        at org.simpleframework.xml.core.Persister.write(Persister.java:1259)
        at org.simpleframework.xml.core.Persister.write(Persister.java:1241)
        at org.simpleframework.xml.core.Persister.write(Persister.java:1222)
        at org.linguafranca.pwdb.kdbx.simple.SimpleDatabase.save(SimpleDatabase.java:236)
...

any suggestion?

lubbo commented 4 years ago

Is this project still alive?

jorabin commented 4 years ago

sure, why do you ask?

jorabin commented 4 years ago

You are picking up Base64 from /system/framework/org.apache.http.legacy.boot.jar rather than commons-codec.1.11.jar - you'll need to find a way to exclude the first from your classpath

ivanovpv commented 4 years ago

Please include in your build.gradle following reference to base64 support:

implementation group: 'commons-codec', name: 'commons-codec', version:'1.10'

jorabin commented 4 years ago

Thanks Pavel - NB it's 1.11

ivanovpv commented 4 years ago

Workable example for Android is here

Though it's a bit outdated, but still usable

lubbo commented 4 years ago

sure, why do you ask?

I haven't see commits since 2018 ... sorry.

lubbo commented 4 years ago

Please include in your build.gradle following reference to base64 support:

implementation group: 'commons-codec', name: 'commons-codec', version:'1.10'

I tried but the error persists ... trying resetting AndroidStudio cache... Nope. It doesn't work.

lubbo commented 4 years ago

Workable example for Android is here

Though it's a bit outdated, but still usable

I'm not able to open it in AndroidStudio ... Have you used Eclipse?

jorabin commented 1 year ago

Coming back to review, this still looks as though there are multiple JARs on the classpath and that an out of date version is being picked up - see earlier comment - I will close unless there is more discussion needed.

jorabin commented 2 months ago

closing as no longer a live issue