Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android java.lang.NoClassDefFoundError:org.springframework.web.client.RestTemplate_Android_Spring Boot_Resttemplate_Spring Android - Fatal编程技术网

Android java.lang.NoClassDefFoundError:org.springframework.web.client.RestTemplate

Android java.lang.NoClassDefFoundError:org.springframework.web.client.RestTemplate,android,spring-boot,resttemplate,spring-android,Android,Spring Boot,Resttemplate,Spring Android,我在android应用程序中使用resttemplate时出现以下错误。我在代码中使用resttemplate时出现此错误 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.lss.loop, PID: 17285 java.lang.NoClassDefFoundError: org.springframework.web.client.RestTemplate

我在android应用程序中使用resttemplate时出现以下错误。我在代码中使用resttemplate时出现此错误

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.lss.loop, PID: 17285
              java.lang.NoClassDefFoundError: org.springframework.web.client.RestTemplate
                  at com.esp.office.services.ServerAuthenticateService.<init>(ServerAuthenticateService.java:240)
                  at com.esp.office.authentication.AccountGeneral.<clinit>(AccountGeneral.java:30)
                  at com.esp.office.view.LoginActivity.onCreate(LoginActivity.java:138)
                  at android.app.Activity.performCreate(Activity.java:5459)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2458)
                  at android.app.ActivityThread.access$900(ActivityThread.java:172)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:146)
                  at android.app.ActivityThread.main(ActivityThread.java:5598)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:515)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
                  at dalvik.system.NativeStart.main(Native Method)
下面是我的graddle配置:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.esp.office"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }

    lintOptions {
        checkReleaseBuilds false
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    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 {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:26.0.0'
    compile 'com.android.support:design:26.0.0'
    compile 'com.android.support:cardview-v7:26.0.0'
    compile 'com.android.support:recyclerview-v7:26.0.0'
    compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
    compile('org.springframework.android:spring-android-auth:2.0.0.M3') {
        exclude module: 'spring-core'
    }
    compile 'org.springframework.android:spring-android-core:2.0.0.M3'
    compile 'joda-time:joda-time:2.3'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.9.0'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
    compile 'com.fasterxml.jackson.core:jackson-core:2.9.0'

    compile 'com.google.code.gson:gson:2.8.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'net.sourceforge.jexcelapi:jxl:2.6.12'
    compile 'com.getbase:floatingactionbutton:1.10.1'
    compile 'com.github.ganfra:material-spinner:2.0.0'
    compile 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.14'
    compile 'commons-io:commons-io:1.3.2'
    compile 'de.hdodenhof:circleimageview:2.2.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'

    testCompile 'junit:junit:4.12'
}
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '26.1.0'
            }
        }
    }

}
build.gradle:

 buildscript {
 repositories {
    jcenter()
 }
 dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
 }
}

allprojects {
  repositories {
    jcenter()
    maven {
        url "https://maven.google.com"
    }
    maven { url "https://jitpack.io" }
    maven { url "https://repo.spring.io/libs-milestone" }

 }
}

task clean(type: Delete) {
 delete rootProject.buildDir
}

上述错误的原因是什么。请帮助我修复此问题。

好吧,您的gradle中缺少maven存储库

dependencies {
    compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
} repositories {
    maven {
        url 'https://repo.spring.io/libs-milestone'
    }
}

您可以看到,依赖项上的版本似乎不兼容。@JonathanJohx哪一个?我要添加asnwerTry wit old
spring android rest模板:2.0.0.M1
@IntelliJAmiya不工作我在您的gradle代码中看不到它@KJEjava48你能在你的问题中添加存储库部分吗?它在外部build.gradle文件中,我将在我的问题中更新它。我已经用两个build.gradle文件更新了代码。立即选中删除所有项目和存储库将在外部,您认为有必要覆盖所有项目任务吗?你有多少个项目?
 buildscript {
 repositories {
    jcenter()
 }
 dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
 }
}

allprojects {
  repositories {
    jcenter()
    maven {
        url "https://maven.google.com"
    }
    maven { url "https://jitpack.io" }
    maven { url "https://repo.spring.io/libs-milestone" }

 }
}

task clean(type: Delete) {
 delete rootProject.buildDir
}
dependencies {
    compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
} repositories {
    maven {
        url 'https://repo.spring.io/libs-milestone'
    }
}