java-json-tools / json-schema-validator

A JSON Schema validation implementation in pure Java, which aims for correctness and performance, in that order
http://json-schema-validator.herokuapp.com/
Other
1.62k stars 399 forks source link

Android app crashes because schema (v4) cannot be found at runtime #374

Closed zollole closed 3 years ago

zollole commented 3 years ago

The app uses a Kotlin library with the schema validator (2.2.14) as a dependency. During the initialization of the validator the draftv4/schema resource cannot be found. This call in line 65 of SchemaVersion.java returns 'null':

SchemaVersion.class.getResource(resource)

zollole commented 3 years ago

More info on this from a previous issue: https://stackoverflow.com/questions/24728894/get-exceptionininitializererror-when-adding-json-schema-validator-to-android-tes

zollole commented 3 years ago

Turns out I also excluded the schema v3 and v4 files in the build.gradle not knowing it would exclude both of the instances.

Solution: use 'pickFirst' instead of 'exclude'.

    packagingOptions {
        exclude 'META-INF/ASL-2.0.txt'
        exclude 'META-INF/LGPL-3.0.txt'
        //...
        pickFirst 'draftv3/schema'
        pickFirst 'draftv4/schema'
    }