Adding JsonPath in Android Studio causes non-zero

2019-02-25 11:54发布

When I add the JsonPath library to my Android Studio (1.4) project I get an error as following:

Error:Execution failed for task ':app:dexDebug'. \>
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException:
Process 'command 'C:\Program Files\JDK_64_bit\bin\java.exe'' finished with 
non-zero exit value 2

(I added the library via File > Project Structure > Dependencies > Library Dependency > com.jayway.jsonpath:json-path:2.0.0)

Trying to add MultiDex support for the app as suggested in a few other questions results in a different error:

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. \>
java.util.zip.ZipException: duplicate entry:
org/objectweb/asm/AnnotationVisitor.class

The external libraries in my project list both asm-1.0.2 and asm-3.3.1 but removing one or both does not solve my problem.

build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.REDACTED.REDACTED"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {

compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.jayway.jsonpath:json-path:2.0.0'
compile 'com.android.support:multidex:1.0.1'
}

app.iml (libraries):

    <orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" exported="" name="butterknife-7.0.1" level="project" />
    <orderEntry type="library" exported="" name="asm-3.3.1" level="project" />
    <orderEntry type="library" exported="" name="multidex-1.0.1" level="project" />
    <orderEntry type="library" exported="" name="json-path-2.0.0" level="project" />
    <orderEntry type="library" exported="" name="asm-1.0.2" level="project" />
    <orderEntry type="library" exported="" name="support-v4-23.1.0" level="project" />
    <orderEntry type="library" exported="" name="slf4j-api-1.7.10" level="project" />
    <orderEntry type="library" exported="" name="appcompat-v7-23.1.0" level="project" />
    <orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" />
    <orderEntry type="library" exported="" name="json-smart-2.1.1" level="project" />

androidmanifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.REDACTED.REDACTED" >
    <uses-permission android:name="android.permission.INTERNET" />
    <application

        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Thank you very much in advance!

2条回答
Rolldiameter
2楼-- · 2019-02-25 12:36

If you add compile 'net.minidev:json-smart:2.2', the problem will be resolved.

For more background on the problem, see https://github.com/jayway/JsonPath/issues/116 and https://github.com/jayway/JsonPath/pull/108. Version 2.1.0 of json-path, which hasn't been released yet, will point to the 2.2 version of json-smart, resolving this issue. Until then the above workaround is necessary.

查看更多
Root(大扎)
3楼-- · 2019-02-25 12:36

in your build.gradle file add following codes :

    defaultConfig {
     multiDexEnabled true
     minSdkVersion 15
     targetSdkVersion 23
     versionCode 1
     versionName "1.0"
   }

   dexOptions {
     javaMaxHeapSize "4g"
 }
查看更多
登录 后发表回答