Android 9

时间:2019-05-27 11:45:52

标签: android spring resttemplate spring-android

我的android代码是:

HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setConnectTimeout(10000);
RestTemplate restTemplate = new RestTemplate(factory);

自android 8起工作正常,但是当我在Android 9中测试该应用程序时,出现此错误:

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #4
    Process: atto.capturadordatosmedidores, PID: 27220
    java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:354)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/conn/scheme/SchemeRegistry;
        at org.springframework.http.client.HttpComponentsClientHttpRequestFactory.<init>(HttpComponentsClientHttpRequestFactory.java:75)
        at atto.capturadordatosmedidores.tasks.ListaServiciosTask.doInBackground(ListaServiciosTask.java:58)
        at atto.capturadordatosmedidores.tasks.ListaServiciosTask.doInBackground(ListaServiciosTask.java:25)
        at android.os.AsyncTask$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 
     Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.conn.scheme.SchemeRegistry" on path: DexPathList[[zip file "/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/base.apk", zip file "/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/split_lib_dependencies_apk.apk", zip file "/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/split_lib_resources_apk.apk", zip file "/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/split_lib_slice_0_apk.apk", zip file "/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/split_lib_slice_1_apk.apk", zip file "/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/split_lib_slice_2_apk.apk", zip file "/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/split_lib_slice_3_apk.apk", zip file "/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/split_lib_slice_4_apk.apk", zip file "/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/split_lib_slice_5_apk.apk", zip file "/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/split_lib_slice_6_apk.apk", zip file "/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/split_lib_slice_7_apk.apk", zip file "/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/split_lib_slice_8_apk.apk", zip file "/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/lib/x86, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at org.springframework.http.client.HttpComponentsClientHttpRequestFactory.<init>(HttpComponentsClientHttpRequestFactory.java:75) 
        at atto.capturadordatosmedidores.tasks.ListaServiciosTask.doInBackground(ListaServiciosTask.java:58) 
        at atto.capturadordatosmedidores.tasks.ListaServiciosTask.doInBackground(ListaServiciosTask.java:25) 
        at android.os.AsyncTask$2.call(AsyncTask.java:333) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 
        Suppressed: java.io.IOException: No original dex files found for dex location /data/app/atto.capturadordatosmedidores-e67fyMqjt8bwfcZRLFOksw==/split_lib_resources_apk.apk
        at dalvik.system.DexFile.openDexFileNative(Native Method)
        at dalvik.system.DexFile.openDexFile(DexFile.java:354)
        at dalvik.system.DexFile.<init>(DexFile.java:101)
        at dalvik.system.DexFile.<init>(DexFile.java:75)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
        at dalvik.system.DexPathList.<init>(DexPathList.java:164)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
E/AndroidRuntime:     at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
        at android.app.LoadedApk.getResources(LoadedApk.java:1032)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5749)
        at android.app.ActivityThread.access$1100(ActivityThread.java:199)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

我解决了删除HttpComponentsClientHttpRequestFactory工厂变量的问题,但未设置超时。我想知道是否还有其他解决方案。

我的build.gradle:

apply plugin: 'com.android.application'

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

android {
    compileSdkVersion 28

    defaultConfig {
        applicationId "atto.capturadordatosmedidores"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 2
        versionName "1.11"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
    implementation 'joda-time:joda-time:2.9.9'
    implementation 'com.github.rey5137:material:1.2.5'
    implementation 'com.github.jakob-grabner:Circle-Progress-View:v1.2.9'
    //Compatibilidad para PreferenceFragment
    implementation 'com.android.support:preference-v7:28.0.0'


}

1 个答案:

答案 0 :(得分:0)

将此代码放在清单中的应用程序标记内。这对我有用

# kerberos # nifi.kerberos.krb5.file=C:\nifi\conf\krb5.ini # kerberos service principal # nifi.kerberos.service.principal=nifi/user@mydomain.com nifi.kerberos.service.keytab.location=