Android:Java 无法在运行时从我创建的 JAR 中找到类
我正在研究 facebook-sdk 示例,并尝试利用以 .JAR 形式提供的类集合。我对 java 和 eclipse 比较陌生,所以我预计我会犯一些明显的错误。
问题是一切似乎都编译得很好,但是当我运行项目(使用 android 模拟器)时,dalvik vm 无法找到我从此 facebook sdk 引用的第一个类。 ( com/facebook/android/Facebook.class )
顺便说一句,如果我将源代码作为附加包直接复制到我的项目中,则一切正常。
第 1 步:我将 com_facebook_android 项目导出为 .JAR 文件。 (右键单击项目,导出,java / jar 文件)我选择 c:\data\jag\jar 作为保存 facebooksdk.jar 的位置。
第 2 步:我点击了 HelloGoogleMaps 项目的属性,选择了 Java 构建路径,库,添加外部 JARS... 我直接选择了 c:\data\jag\jar\facebooksdk.jar 文件。
此时我的项目似乎构建得很好(没有错误)。
步骤 3:调试项目并收到错误:
[2010-11-19 09:05:08 - 示例] ActivityManager:错误:活动类 {com.facebook.android/com.facebook.android.Example} 不存在。 [2010-11-19 09:05:11 - 示例] 在设备上启动活动 com.facebook.android.Example [2010-11-19 09:05:12 - 示例] 新包尚未在系统中注册。下次尝试前等待 3 秒。
[2010-11-19 09:05:15 - 示例] 在设备上启动 Activity com.facebook.android.Example
[2010-11-19 09:05:17 - 示例] ActivityManager: 启动: Intent { act=android.intent .action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.facebook.android/.Example }
[2010-11-19 09:05:17 - 示例] 新包尚未在系统中注册。下次尝试前等待 3 秒。
[2010-11-19 09:05:20 - 示例] 在设备上启动 Activity com.facebook.android.Example
[2010-11-19 09:05:21 - 示例] ActivityManager: 启动: Intent { act=android.intent .action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.facebook.android/.Example }
[2010-11-19 09:05:21 - 示例] ActivityManager:错误类型 3
[2010-11- 19 09:05:21 - 示例] ActivityManager:错误:活动类 {com.facebook.android/com.facebook.android.Example} 不存在。
SHAWN —— 这是我的项目的 Android 属性。
I am working through a facebook-sdk example and trying to utilize the collection of classes as provided as a .JAR. I am relatively new to java and eclipse so I expect I am making some obvious blunder.
The issue is that everything seems to compile fine, but when I run the project (using the android emulator) dalvik vm is unable to find the first class I reference from this facebook sdk. ( com/facebook/android/Facebook.class )
As an aside, if I copy the source directly into my project as an additional package everything works fine.
Step 1: I exported the com_facebook_android project as a .JAR file. ( right click project, export, java / jar file ) I choose c:\data\jag\jar as my location to save facebooksdk.jar.
Step 2: I hit properties on the project HelloGoogleMaps, Selected Java Build Path, Libraries, Add External JARS... I the directly selected the c:\data\jag\jar\facebooksdk.jar file.
At this point my project seems to be building just fine ( no errors ).
Step 3: Debug the project and receive the error:
[2010-11-19 09:05:08 - Example] ActivityManager: Error: Activity class {com.facebook.android/com.facebook.android.Example} does not exist.
[2010-11-19 09:05:11 - Example] Starting activity com.facebook.android.Example on device
[2010-11-19 09:05:12 - Example] New package not yet registered with the system. Waiting 3 seconds before next attempt.
[2010-11-19 09:05:15 - Example] Starting activity com.facebook.android.Example on device
[2010-11-19 09:05:17 - Example] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.facebook.android/.Example }
[2010-11-19 09:05:17 - Example] New package not yet registered with the system. Waiting 3 seconds before next attempt.
[2010-11-19 09:05:20 - Example] Starting activity com.facebook.android.Example on device
[2010-11-19 09:05:21 - Example] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.facebook.android/.Example }
[2010-11-19 09:05:21 - Example] ActivityManager: Error type 3
[2010-11-19 09:05:21 - Example] ActivityManager: Error: Activity class {com.facebook.android/com.facebook.android.Example} does not exist.
SHAWN -- Here are the Android properties for my project.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您设置 Java 构建路径时,您只需执行以下操作:设置构建路径本身。这使您获得成功的编译。但是,当创建 .apk 文件时,系统并不知道您需要将外部 jar 文件与源文件捆绑在一起。
我以前没有这样做过,但看起来如果你右键单击你的 com_facebook_android 项目并选择 Properties > Android,您应该选择“是库”框。然后进入主项目的 Android 属性,单击“添加...”并选择外部库。我相信这会满足您的需要。
编辑:
这称为库项目,是 SDK 的一个相当新的补充。您可以在 http://developer.android.com/guide 找到更多信息/developing/eclipse-adt.html#libraryProject
When you set the Java Build Path, you only did that: set the build path itself. This caused you to get a successful compile. However, when the .apk file is created, the system does not know that you need external jar files to be bundled along with your source files.
I have not done this before, but it looks like if you right click on your com_facebook_android project and select Properties > Android, you should select the Is Library box. Then go into the Android properties of your main project and click Add... and choose the external library. I believe this will do what you need.
EDIT:
This is called a Library Project, and is a fairly new addition to the SDK. You can find more information at http://developer.android.com/guide/developing/eclipse-adt.html#libraryProject
我认为您需要将 com.facebook.android 作为库添加到您的项目中...
如果我没记错的话,这是 android facebook sdk。
您可以查看此链接...
请参阅此处的说明:
https://github.com/facebook/facebook -android-sdk
希望对你有帮助........
谢谢
I think you will need to add com.facebook.android as a library into your project...
if i am not wrong this is android facebook sdk.
You can check this link out...
See the instructions over here:
https://github.com/facebook/facebook-android-sdk
Hope it helps you........
Thanksss
好吧,我对自己所做的一切感到非常不舒服。
1) 我将 .jar 添加为外部 jar。
2)然后我还将.apk文件作为.jar(不是外部jar)包含在内,我必须直接从com_facebook_android/bin/com_facebook_android.apk中选择它。
看来我正在用蛮力解决这个问题,其他的东西会更合适。
ok, really not comfortable about what I did to get me past this.
1) I added the .jar as an external jar.
2) I then also included the .apk file as a .jar (not external jar) I had to select this directly from com_facebook_android/bin/com_facebook_android.apk.
it seems like I am solving this with brute force and something else would be more appropriate.