Using net.sf.json in android

The json that comes with android is not very convenient to use. I want to use net.sf.json, but an exception is found when running: java.lang.VerifyError: net/sf/json/JSONObject

After various searches, it turns out that the json-lib-2.4-jdk15.jar package we used needs to reference several other jar packages, which means that if we want to use net.sf.json, we cannot just add a jar package.

Refer to the official website configuration: http://json-lib.sourceforge.net/index.html

All required jar packages are as follows

commons-beanutils-1.8.0.jar

commons-collections-3.2.1.jar

commons-lang-2.5.jar

commons-logging-1.1.1.jar

ezmorph-1.0.6.jar

json-lib-2.4-jdk15.jar

 

It is not enough to configure the above jar package, and a conflict error will be reported when compiling: multiple dex files define Lorg/apache/commons/collections/Buffer

I found that the commons-beanutils-1.8.0.jar package contains classes that conflict with commons-collections-3.2.1.jar, but I want to use the commons-collections-3.2.1.jar package

Method 1 (simple and rude): directly delete the org/apache/commons/collections directory and the class in the directory in commons-beanutils-1.8.0.jar (open it with the decompression tool and delete it directly), so that compile without error

Method Two:

First modify the Gradle configuration file to enable MultiDex and include MultiDex support:

defaultConfig {
        multiDexEnabled true
   }
dependencies { compile 'com.android.support:multidex:1.0.1' }

 (I've gotten to this point and it's working fine, but if it doesn't work, I'll have to continue)

Then let the application support multiple DEX files. Three optional methods are described in the MultiDexApplication JavaDoc:

1. Declare android.support.multidex.MultiDexApplication in the application of AndroidManifest.xml;
2. If you already have your own Application class, let it inherit MultiDexApplication;
3. If your Application class has inherited from other classes, you do not want to modify it it, then you can override the attachBaseContext() method:

@Override   
protected void attachBaseContext(Context base) {  
    super.attachBaseContext(base); MultiDex.install(this);  
}  

 It can be run at the end, and it may be packaged. This problem seems to be that the number of methods in the project exceeds the number of 65536 methods specified by Android.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326163970&siteId=291194637