简体   繁体   中英

Android class not found when running on some devices but not on others

When I run my app on some devices, such as a tablet that I have it works fine, no crashes.

But when I try to run it on my phone, I get an error complaining that the class definition was not found.

java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:300)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NoClassDefFoundError: org.apache.commons.io.output.StringBuilderWriter

Here is the dependencies in the gradle file

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile project(':volley')
    compile files('libs/commons-io-2.4.jar')
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:design:25.0.0'
    compile 'com.android.support:support-v4:25.0.0'
    compile 'com.android.support:recyclerview-v7:25.0.0'
}

And the jar is in the lib folder.

Android versions: Phone: 4.4.2 Tablet: 5.1.1

SDK Setup: compileSdkVersion: 25 minSdkVersion: 15 targetSdkVersion: 24

Does anybody have any ideas?

Does anybody have any ideas

You should add apache commons directly to your project:

compile "commons-io:commons-io:2.5"

Turns out the real issue was with multiDexing

I added this to the defaultConfig :

defaultConfig {
    multiDexEnabled true
}

And included this to my dependencies :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM