Don't use android's built in org.json Don't use android's built in org.json json json

Don't use android's built in org.json


How could I fix this?

Change yours from org.json to org.something.else. You cannot replace system-supplied packages with ones from an app, even for your own process. You do not control the runtime classpath, and the firmware always wins.

Or, switch from org.json to something that performs better, such as Gson or Jackson.


You can relocate your org.json dependency to another package name.This can be done with the gradle shadow plugin.

Plugin project: https://github.com/johnrengelman/shadow
Plugin documentation: https://imperceptiblethoughts.com/shadow/

My working example:
Hint: I'm using a java library project "lib" within my Android project which has a dependency to org.json.

lib/build.gradle

apply plugin: 'java-library'apply plugin: 'com.github.johnrengelman.shadow'buildscript {    repositories {        maven {            url "https://plugins.gradle.org/m2/"        }    }    dependencies {        classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.3'    }}shadowJar {    relocate 'org.json', 'shadow.org.json'}dependencies {    implementation fileTree(dir: 'libs', include: ['*.jar'])    implementation('org.json:json:20180813')}sourceCompatibility = "1.7"targetCompatibility = "1.7"

app/build.gradle

apply plugin: 'com.android.application'android {    [..]}dependencies {    [..]    implementation project(path: ':lib', configuration: 'shadow')}