I
I
Igor2015-06-29 19:25:50
Java
Igor, 2015-06-29 19:25:50

Why does the NoClassDefFoundError occur?

There is a project in Android Studio, it has a module, which has the following in Gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 19
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 16
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'commons-io:commons-io:2.4'
}

An error occurs here:
HttpURLConnection connection = (HttpURLConnection) fullUrl.openConnection();
            connection.setUseCaches(false);
            connection.setAllowUserInteraction(false);

            // Set the request method.
            connection.setRequestMethod(method);

            // Add the session cookie.
            connection.setRequestProperty("Cookie", "session=" + sessionKey);
            connection.setRequestProperty("Accept-Encoding", "gzip, deflate");

            if (method.equals("POST") && parameterString.length() > 0) {
                connection.setRequestProperty("Content-Length", Integer.toString(parameterString.length()));
                connection.addRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                connection.setRequestProperty("charset", "utf-8");
                connection.getOutputStream().write(parameterString.getBytes("UTF8"));
            }

            connection.connect();
            InputStream inputStream = connection.getInputStream();

            // If the output was gzipped, change the input stream to the ungzipped version.
            if ("gzip".equals(connection.getContentEncoding())) {
                inputStream = new GZIPInputStream(inputStream);
            }

            String output = IOUtils.toString(inputStream, "UTF-8");  <---- ОШИБКА
            inputStream.close();

Like this:
If you need the Gradle config of the main module, here it is:
apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.www"
        minSdkVersion 11
        targetSdkVersion 16
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:19.1.0'
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile files('libs/android-async-http-1.4.6.jar')
    compile files('libs/picasso-2.5.0.jar')
    compile files('libs/tinylinegzip.jar')
    compile 'com.laputapp:laputapp-pulltorefresh:2.1.1'
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
protven, 2015-06-29
@asdf999

'org.apache.commons:commons-io:1.3.2' Out of the
blue!

C
Copperfield, 2015-06-29
@Copperfield

With libs from Apache often such tricks. Try to download .jar and connect directly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question