gpt4 book ai didi

java - 运行 Android 应用程序会产生 java.lang.NoClassDefFoundError : retrofit. RestAdapter$Builder

转载 作者:太空宇宙 更新时间:2023-11-03 11:11:06 25 4
gpt4 key购买 nike

我正在 Android 上使用 Flickr API 制作一个照片库应用程序(使用 Eclipse 和 4.4 SDK)。该项目已成功编译,但应用程序在再次运行 4.4 的 Nexus 7 (2012) 上启动后立即崩溃。

我的构建路径中包含以下 jar: 改造-1.6.1 okhttp-2.0.0 gson-2.2.4 picasso-2.3.2

相关文件如下:

GalleryApp.java

import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import utils.Constants;
import android.app.Application;
import apiService.FlickrService;

public class GalleryApp extends Application {

private FlickrService mFlickrService;

public synchronized FlickrService getFlickrService() {

if (mFlickrService == null) {

RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(FlickrService.FLICKR_API_URL)
.setRequestInterceptor(new RequestInterceptor() {
@Override
public void intercept(RequestFacade requestFacade) {
requestFacade.addQueryParam("format", "json");
requestFacade.addQueryParam("api_key", FlickrService.FLICKR_API_KEY);

requestFacade.addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.ACCEPT_APPLICATION_JSON);
}
})
.build();
/*
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(FlickrService.FLICKR_API_URL)
//.setConverter(new GsonConverter(GsonUtil.getGsonInstance()))
.setClient(new OkClient())
.setLogLevel(RestAdapter.LogLevel.FULL)
.setRequestInterceptor(new RequestInterceptor() {

@Override
public void intercept(RequestFacade requestFacade) {
// Get responses in JSON
requestFacade.addQueryParam("format", "json");
requestFacade.addQueryParam("api_key", FlickrService.FLICKR_API_KEY);

requestFacade.addHeader(Constants.HTTP_HEADER_ACCEPT, Constants.ACCEPT_APPLICATION_JSON);
}
})
.build();
*/
mFlickrService = restAdapter.create(FlickrService.class);
}
return mFlickrService;
}
}

FlickrService.java

import models.PhotoResponse;
import retrofit.Callback;
import retrofit.http.GET;
import retrofit.http.Query;

public interface FlickrService {

public static final String FLICKR_API_KEY = "dcf5dc19f9d4e86ead9722a634907e6e";
public static final String FLICKR_API_URL = "http://api.flickr.com/services/rest";

public static final String NO_JSON_CALLBACK = "&nojsoncallback=1";

@GET("/?method=flickr.photos.search&extras=original_format" + NO_JSON_CALLBACK)
void searchPhotos(@Query("text") String searchText, @Query("per_page") String perPage,
@Query("page") String page, Callback<PhotoResponse> cb);
}

完整错误日志

07-10 18:41:06.535: E/dalvikvm(3164): Could not find class 'retrofit.RestAdapter$Builder', referenced from method com.example.retrofitgallery2.GalleryApp.getFlickrService
07-10 18:41:06.535: W/dalvikvm(3164): VFY: unable to resolve new-instance 1138 (Lretrofit/RestAdapter$Builder;) in Lcom/example/retrofitgallery2/GalleryApp;
07-10 18:41:06.535: D/dalvikvm(3164): VFY: replacing opcode 0x22 at 0x0005
07-10 18:41:06.535: D/dalvikvm(3164): DexOpt: unable to opt direct call 0x2243 at 0x07 in Lcom/example/retrofitgallery2/GalleryApp;.getFlickrService
07-10 18:41:06.535: D/dalvikvm(3164): DexOpt: unable to opt direct call 0x224a at 0x12 in Lcom/example/retrofitgallery2/GalleryApp;.getFlickrService
07-10 18:41:06.535: I/dalvikvm(3164): Failed resolving Lcom/example/retrofitgallery2/GalleryApp$1; interface 1137 'Lretrofit/RequestInterceptor;'
07-10 18:41:06.535: W/dalvikvm(3164): Link of class 'Lcom/example/retrofitgallery2/GalleryApp$1;' failed
07-10 18:41:06.535: D/dalvikvm(3164): DexOpt: unable to opt direct call 0x20f3 at 0x1b in Lcom/example/retrofitgallery2/GalleryApp;.getFlickrService
07-10 18:41:06.535: I/dalvikvm(3164): Failed resolving Lviewer/MainActivity$1; interface 1135 'Lretrofit/Callback;'
07-10 18:41:06.535: W/dalvikvm(3164): Link of class 'Lviewer/MainActivity$1;' failed
07-10 18:41:06.535: E/dalvikvm(3164): Could not find class 'viewer.MainActivity$1', referenced from method viewer.MainActivity.onCreate
07-10 18:41:06.535: W/dalvikvm(3164): VFY: unable to resolve new-instance 1149 (Lviewer/MainActivity$1;) in Lviewer/MainActivity;
07-10 18:41:06.535: D/dalvikvm(3164): VFY: replacing opcode 0x22 at 0x0027
07-10 18:41:06.535: I/dalvikvm(3164): Failed resolving Lviewer/MainActivity$1; interface 1135 'Lretrofit/Callback;'
07-10 18:41:06.535: W/dalvikvm(3164): Link of class 'Lviewer/MainActivity$1;' failed
07-10 18:41:06.535: D/dalvikvm(3164): DexOpt: unable to opt direct call 0x2258 at 0x29 in Lviewer/MainActivity;.onCreate
07-10 18:41:06.535: D/AndroidRuntime(3164): Shutting down VM
07-10 18:41:06.535: W/dalvikvm(3164): threadid=1: thread exiting with uncaught exception (group=0x41854ba8)
07-10 18:41:06.545: E/AndroidRuntime(3164): FATAL EXCEPTION: main
07-10 18:41:06.545: E/AndroidRuntime(3164): Process: com.example.retrofitgallery2, PID: 3164
07-10 18:41:06.545: E/AndroidRuntime(3164): java.lang.NoClassDefFoundError: retrofit.RestAdapter$Builder
07-10 18:41:06.545: E/AndroidRuntime(3164): at com.example.retrofitgallery2.GalleryApp.getFlickrService(GalleryApp.java:20)
07-10 18:41:06.545: E/AndroidRuntime(3164): at viewer.APIRestActivity.onCreate(APIRestActivity.java:16)
07-10 18:41:06.545: E/AndroidRuntime(3164): at viewer.MainActivity.onCreate(MainActivity.java:29)
07-10 18:41:06.545: E/AndroidRuntime(3164): at android.app.Activity.performCreate(Activity.java:5231)
07-10 18:41:06.545: E/AndroidRuntime(3164): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-10 18:41:06.545: E/AndroidRuntime(3164): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
07-10 18:41:06.545: E/AndroidRuntime(3164): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
07-10 18:41:06.545: E/AndroidRuntime(3164): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-10 18:41:06.545: E/AndroidRuntime(3164): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-10 18:41:06.545: E/AndroidRuntime(3164): at android.os.Handler.dispatchMessage(Handler.java:102)
07-10 18:41:06.545: E/AndroidRuntime(3164): at android.os.Looper.loop(Looper.java:136)
07-10 18:41:06.545: E/AndroidRuntime(3164): at android.app.ActivityThread.main(ActivityThread.java:5001)
07-10 18:41:06.545: E/AndroidRuntime(3164): at java.lang.reflect.Method.invokeNative(Native Method)
07-10 18:41:06.545: E/AndroidRuntime(3164): at java.lang.reflect.Method.invoke(Method.java:515)
07-10 18:41:06.545: E/AndroidRuntime(3164): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-10 18:41:06.545: E/AndroidRuntime(3164): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-10 18:41:06.545: E/AndroidRuntime(3164): at dalvik.system.NativeStart.main(Native Method)

最佳答案

我在 Android 4.4 及以下版本上遇到了同样的错误。它与 multiDexEnabling 相关联。

尝试在 build.gradle 中添加“multiDexEnable true”:

defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 16
versionName "1.5"
multiDexEnabled true
}

如果这没有帮助,只需添加这一行

android:name="android.support.multidex.MultiDexApplication"

AndroidManifest.xml 中如下所示:

    <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name="android.support.multidex.MultiDexApplication">
...

关于java - 运行 Android 应用程序会产生 java.lang.NoClassDefFoundError : retrofit. RestAdapter$Builder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24677527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com