简体   繁体   English

Android:Java无法在运行时从我创建的JAR中找到类

[英]Android:Java Unable to find class at runtime from JAR I created

I am working through a facebook-sdk example and trying to utilize the collection of classes as provided as a .JAR. 我正在研究一个facebook-sdk示例,并尝试使用作为.JAR提供的类集合。 I am relatively new to java and eclipse so I expect I am making some obvious blunder. 我对java和eclipse比较陌生,所以我希望我犯了一些明显的错误。

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. 问题是,一切似乎编译正常,但当我运行项目(使用Android模拟器)时,dalvik vm无法找到我从这个facebook sdk引用的第一个类。 ( com/facebook/android/Facebook.class ) (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. 第1步:我将com_facebook_android项目导出为.JAR文件。 ( right click project, export, java / jar file ) I choose c:\\data\\jag\\jar as my location to save facebooksdk.jar. (右键单击项目,导出,java / jar文件)我选择c:\\ data \\ jag \\ jar作为保存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. 第2步:我点击项目HelloGoogleMaps,Selected Java Build Path,Libraries,Add External JARS ......我直接选择了c:\\ data \\ jag \\ jar \\ facebooksdk.jar文件。

At this point my project seems to be building just fine ( no errors ). 在这一点上,我的项目似乎建立得很好(没有错误)。 替代文字

Step 3: Debug the project and receive the error: 第3步:调试项目并收到错误:

[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:08 - 示例] ActivityManager:错误:活动类{com.facebook.android/com.facebook.android.Example}不存在。 [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. [2010-11-19 09:05:11 - 示例]在设备上启动活动com.facebook.android.Example [2010-11-19 09:05:12 - 示例]尚未向系统注册的新程序包。 Waiting 3 seconds before next attempt. 下次尝试前等待3秒。

[2010-11-19 09:05:15 - Example] Starting activity com.facebook.android.Example on device [2010-11-19 09:05:15 - 示例]在设备上启动com.facebook.android.Example活动

[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 - 示例] ActivityManager:开始: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. [2010-11-19 09:05:17 - 示例]尚未在系统中注册的新软件包。 Waiting 3 seconds before next attempt. 下次尝试前等待3秒。

[2010-11-19 09:05:20 - Example] Starting activity com.facebook.android.Example on device [2010-11-19 09:05:20 - 示例]在设备上启动com.facebook.android.Example活动

[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 - 示例] ActivityManager:开始: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 - 示例] ActivityManager:错误类型3

[2010-11-19 09:05:21 - Example] ActivityManager: Error: Activity class {com.facebook.android/com.facebook.android.Example} does not exist. [2010-11-19 09:05:21 - 示例] ActivityManager:错误:活动类{com.facebook.android/com.facebook.android.Example}不存在。

SHAWN -- Here are the Android properties for my project. SHAWN - 这是我项目的Android属性。

替代文字

When you set the Java Build Path, you only did that: set the build path itself. 设置Java Build Path时,只能这样做:设置构建路径本身。 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. 但是,在创建.apk文件时,系统不知道您需要将外部jar文件与源文件捆绑在一起。

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. 我之前没有这样做,但看起来如果你右键单击你的com_facebook_android项目并选择Properties> Android,你应该选择Is Library框。 Then go into the Android properties of your main project and click Add... and choose the external library. 然后进入主项目的Android属性,单击Add ...并选择外部库。 I believe this will do what you need. 我相信这会做你需要的。

EDIT: This is called a Library Project, and is a fairly new addition to the SDK. 编辑:这称为图书馆计划,是SDK的一个相当新的补充。 You can find more information at http://developer.android.com/guide/developing/eclipse-adt.html#libraryProject 您可以在http://developer.android.com/guide/developing/eclipse-adt.html#libraryProject上找到更多信息。

I think you will need to add com.facebook.android as a library into your project... 我想你需要将com.facebook.android作为库添加到你的项目中......

if i am not wrong this is android facebook sdk. 如果我没错,这是android facebook sdk。

You can check this link out... 你可以查看这个链接...

See the instructions over here: 请参阅此处的说明:

https://github.com/facebook/facebook-android-sdk https://github.com/facebook/facebook-android-sdk

Hope it helps you........ 希望它能帮到你........
Thanksss Thanksss

ok, really not comfortable about what I did to get me past this. 好吧,我真的不喜欢我做了什么让我过去了。
1) I added the .jar as an external jar. 1)我将.jar添加为外部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. 2)然后我还将.apk文件包含为.jar(不是外部jar)我必须直接从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. 看起来我用蛮力解决了这个问题,而其他东西则更合适。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM