我正在尝试在Eclipse中为Android构建一个简单的OAuth客户端。
我按照code.google.com/p/google-api-java-client/wiki/Setup
的说明操作下载zip文件并将google-api-client-1.6.0-beta.jar
添加到Eclipse中的构建路径。所有13个依赖项现在都显示在Referenced Libraries下,如下所示。
代码很简单。我刚刚对默认的Activity进行了以下更改。
public class Testing1Activity extends Activity {
/** Called when the activity is first created. */
final String TAG = getClass().getName();
public static final String CLIENT_ID = "";
public static final String CLIENT_SECRET = "";
public static final String REDIRECT_URI = "";
public static final String SCOPE = "https://www.googleapis.com/auth/latitude.all.best";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Json s = new Json();
String authorizationUrl = new GoogleAuthorizationRequestUrl(CLIENT_ID, REDIRECT_URI, SCOPE)
.build();
}
}
我一直在犯这个该死的错误。 :(
W/dalvikvm( 591): Unable to resolve superclass of Lcom/google/api/client/googleapis/auth/oauth2/draft10/GoogleAuthorizationRequestUrl; (18)
W/dalvikvm( 591): Link of class 'Lcom/google/api/client/googleapis/auth/oauth2/draft10/GoogleAuthorizationRequestUrl;' failed
E/dalvikvm( 591): Could not find class 'com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAuthorizationRequestUrl', referenced from method com.rahul.Testing1Activity.onCreate
W/dalvikvm( 591): VFY: unable to resolve new-instance 37 (Lcom/google/api/client/googleapis/auth/oauth2/draft10/GoogleAuthorizationRequestUrl;) in Lcom/rahul/Testing1Activity;
D/dalvikvm( 591): VFY: replacing opcode 0x22 at 0x000d
D/dalvikvm( 591): VFY: dead code 0x000f-001c in Lcom/rahul/Testing1Activity;.onCreate (Landroid/os/Bundle;)V
D/AndroidRuntime( 591): Shutting down VM
W/dalvikvm( 591): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime( 591): FATAL EXCEPTION: main
E/AndroidRuntime( 591): java.lang.NoClassDefFoundError: com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAuthorizationRequestUrl
E/AndroidRuntime( 591): at com.rahul.Testing1Activity.onCreate(Testing1Activity.java:25)
答案 0 :(得分:1)
所以我终于弄明白了。
虽然eclipse显示了引用库下的所有依赖库,但它们并未添加到最终的apk中。必须逐个将它们中的每一个明确地添加到构建路径中。
同时从zip中添加所有依赖库将产生冲突,因为其中一些api已经是Android框架的一部分。它们不需要添加。
答案 1 :(得分:0)
请尝试创建lib文件夹并将其放在Workspace的Application Folder中,然后尝试Give Reference,它将被解析,而不是直接从不同的文件夹中添加Reference。我删除了我的错误。