如何创建和使用Android库罐子? [英] How to create and use android libraries jar?
问题描述
我已经创建了简单的Android库项目。
i have created simple android libraries project..
我选择新的Android应用程序项目>>检查标志这个项目作为库,取消选择创建自定义启动器图标,取消选择创建活动。
I choose New Android Application Project >> check "mark this project as library" and uncheck "create custom launcher icon" and uncheck "create activity"..
在这之后,我创建一个名为MyClass.java简单的类,这里是我的code:
After that, i create simple class called MyClass.java and here's my code:
package android.external.jar;
public class MyClass {
public String helloWorld(){
return "Hello World";
}
}
然后,我选择出口>> >> Java的JAR文件>>全部取消除src文件夹(它是包含在AndroidManifest.xml中)>>并构建JAR文件。
And then, i choose export >> Java >> Jar File >> uncheck all except src folder (it is included with AndroidManifest.xml) >> and build that JAR file..
我有另外一个Android应用程序项目使用该JAR文件。
I have another Android Application project for using that JAR File..
我已经在我的项目>> >>属性Java构建路径>> >>图书馆做右键外部JAR添加到项目添加外部JAR。
i have add external JAR to this project by doing right click on my project >> properties >> java build path >> libraries >> add external jar..
和它是这样的:
我试过使用该库我的应用程序是这样的:
I've tried use that library to my application like this :
import android.external.jar.*;
...
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button1:
try {
MyClass myClass = new MyClass();
Toast.makeText(getActivity(), myClass.helloWorld(), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
}
break;
default:
break;
}
}
...
但它没有工作..:(
But it not works.. :(
和我有这样的错误:
有谁知道如何解决我的问题?真的需要你的建议。
Does anyone know how to fix my problem?? Really need your suggestion..
非常感谢..
推荐答案
的第一件事是你必须把你的库库
文件夹,然后
First thing is you have to place your library in libs
folder and then
您必须包括您的图书馆,并检查您的jar文件的属性 - > Java构建路径 - >为了和导出
You have to include your library and check your jar file in properties -> Java Build Path -> Order and Export
在清理项目和检查一次。
Once clean the project and check once.
这篇关于如何创建和使用Android库罐子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!