Android 4.3:FileUtils.readFileToString-java.lang.NoClassDefFoundError:java.nio.charset.StandardCharsets

时间:2018-12-19 09:33:04

标签: apache-commons android-studio-3.0

Android 3.2.1

在我的app / build.gradle中:

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.myproject"
        minSdkVersion 18
        targetSdkVersion 28
        versionCode 423
        versionName "2.1.423"


}

dependencies {
    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
    annotationProcessor "org.androidannotations:ormlite:$AAVersion"

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:animated-vector-drawable:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:customtabs:28.0.0'
    implementation 'com.android.support:exifinterface:28.0.0'
    implementation 'com.android.support:support-media-compat:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'

    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7'
    implementation 'com.google.android.gms:play-services-gcm:16.0.0'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.j256.ormlite:ormlite-android:5.1'
    implementation 'commons-codec:commons-codec:1.11'
    implementation 'commons-io:commons-io:2.6'
    implementation 'org.apache.commons:commons-lang3:3.8.1'
    implementation 'org.apache.httpcomponents:httpclient:4.5.6'
    implementation "org.androidannotations:androidannotations-api:$AAVersion"
    implementation "org.androidannotations:ormlite-api:$AAVersion"


    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
}

这是我的java类:

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.json.JSONException;
import org.json.JSONObject;

private String getFileContent(String fileName) {
        try {
            File file = new File(fileName);
            String fileContent = FileUtils.readFileToString(file, "UTF-8"); // error here 
            return fileContent;
        } catch (IOException e) {
            if (BuildConfig.DEBUG) Log.e(TAG, e.getMessage(), e);
        }
        return null;
}

当我在 Android 4.4 上启动时,项目成功运行。

但是当我在 Android 4.3 上启动时,出现错误:

FATAL EXCEPTION: PERFORM_NETWORKING_THREAD
 java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets
    at org.apache.commons.io.Charsets.<clinit>(Charsets.java:120)
    at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:1822)
    at com.myproject.transport.lite.CacheService.getFileContent(CacheService.java:92)
    at com.myproject.transport.lite.CacheService.getLastUpdate(CacheService.java:107)
    at com.myproject.transport.lite.CacheService.executeCacheableRequest(CacheService.java:195)
    at com.myproject.transport.lite.FOServiceLite.executeCommand(FOServiceLite.java:515)
    at com.myproject.transport.lite.FOServiceLite.executeCommand(FOServiceLite.java:679)
    at com.myproject.service.ProviderService.sync(ProviderService.java:53)
    at com.myproject.main.MainApp$1.run(MainApp.java:173)
    at java.lang.Thread.run(Thread.java:841)
:

此行中的错误:

String fileContent = FileUtils.readFileToString(file, "UTF-8"); // error here

0 个答案:

没有答案