Android的图书​​馆项目 - 找不到从库项目中的类在运行时? [英] Android Library Project - can't find class from library project at runtime?

查看:124
本文介绍了Android的图书​​馆项目 - 找不到从库项目中的类在运行时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个Android库项目,所以我可以做一个精简版和完整版我的共享code程序的。这里遵循的方向:

  http://developer.android.com/guide/developing/projects/projects-eclipse.html
http://blog.donnfelker.com/2010/08/05/howto-android-full-and-lite-versions/
 

运行我的精简版版本抛出一个ClassNotFoundException在运行时,因为它无法找到从共享项目活动类。这是因为如果项目链接(属性 - > Java构建路径 - >项目 - >添加)实际上并不包括任何的.class文件在运行时

任何人都遇到了这个问题?我不想输出从我的图书馆项目的.jar因为有了这个其他的方法,我们可以分享活动,例如它是理想的。我的精简版的项目,它引用库项目活动的清单:

 <应用
  机器人:名称=com.me.test.lib.App>
  <活动
    机器人:名称=com.me.test.lib.ActivityMain>
 

它无法找到任何在App类或ActivityMain类,它是图书馆计划的一部分。

感谢


例外 - 在ComponentInfo的路径看起来错误的,它应该被嵌套一样,

  04-29 16:49:01.759:ERROR / AndroidRuntime(2349):
  java.lang.RuntimeException的:无法实例活动
  ComponentInfo {
    com.me.test.lite / com.me.test.lib.ActivityMain}:
    抛出java.lang.ClassNotFoundException:com.me.test.lib.ActivityMain
    装载机dalvik.system.PathClassLoader [/data/app/com.me.test.lite-2.apk]
 

解决方案

我试图访​​问该活动在我的工具箱库时,有这个问题。请使用库确保项目提出的任何活动在自己的清单。该工具包实际上并没有指定其清单活动。这听起来像你这样做的部分权利。链接库中的机器人项目是Java项目不同。

对于库项目

右键单击Eclipse项目,选择属性。转到Android的标签。检查是图书馆,说的框

对于应用程序使用的库

右键单击Eclipse项目,选择属性。转到Android的标签。添加库项目作为参照

I'm trying to create an android library project so I can make a lite and full version of my app with shared code. Following the directions here:

http://developer.android.com/guide/developing/projects/projects-eclipse.html
http://blog.donnfelker.com/2010/08/05/howto-android-full-and-lite-versions/

Running my lite version throws a ClassNotFoundException at runtime because it cannot find the activity class from the shared project. It's as if the project linking (properties -> java build path -> projects -> add) isn't actually including any of the .class files at runtime.

Anyone else running into this problem? I don't want to export a .jar from my library project because with this other method we can share activities and such which is ideal. The manifest of my "lite" project, which references the library project activity:

<application 
  android:name="com.me.test.lib.App">
  <activity 
    android:name="com.me.test.lib.ActivityMain" >

It can't find either the App class or the ActivityMain class which are part of the library project.

Thanks


The exception - the path in the ComponentInfo looks wrong, should it be nested like that?

04-29 16:49:01.759: ERROR/AndroidRuntime(2349): 
  java.lang.RuntimeException: Unable to instantiate activity
  ComponentInfo{
    com.me.test.lite/com.me.test.lib.ActivityMain}: 
    java.lang.ClassNotFoundException: com.me.test.lib.ActivityMain 
    in loader dalvik.system.PathClassLoader[/data/app/com.me.test.lite-2.apk]

解决方案

I had this problem when trying to access the Activity in my toolkit library. Make sure project using the library puts any Activities in its own Manifest. The toolkit doesn't actually specify Activities in its Manifest. It sounds like you did that part right. Linking the library for android projects is different from java projects.

For the library project

Right click the Eclipse project, select Properties. Go to the Android tab. Check the box that says "Is Library"

For application using the library

Right click the Eclipse project, select Properties. Go to the Android tab. Add the library project as a reference

这篇关于Android的图书​​馆项目 - 找不到从库项目中的类在运行时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆