how to invoke an activity of a library project from an android apps
Posted
by
Austin
on Stack Overflow
See other posts from Stack Overflow
or by Austin
Published on 2011-06-30T14:56:56Z
Indexed on
2011/06/30
16:22 UTC
Read the original article
Hit count: 187
android
I have an open source android code that I need to use in my android apps. It has all the source code as well as resource files, manifest files and class path. It can be compiled as a separate android apps. I have constraints for using the open source.
1. I can't change a single line of code.
2. I can't use it as a separate apps.
These constraints are non negotiable.
What I have done is I have compiled the open source as class library(in Eclipse: Project Properties->Android-> Tick check box Is Library). This has resulted in generation of .class files(in bin) for the java files and resource files. This open source has an android activity that i want to open from my application. So I have linked the directory of these sets of class files in the source section of my java build path( in .classpath). I have declared the activity in my manifest file with proper action intent filters. Now when I am trying to call activity from my code, its not working. Cleaning and rebuilding doesn't help.
However, if I build the open source project and my apps in the same workspace of eclipse and link the open source in my apps in exact same manner it works fine. I am not able to identify the difference. All settings seems to be same(all files are identical in both the cases). But only in the second case it works.
I have tried it as jar file also. I have build the open source as project library and exported it into a jar file(excluding manifest file). But in that case I am getting the following error
UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: .... Conversion to Dalvik format failed with error 1
This I guess is coming because the android library(2.2) has been included twice in my apps( one for building my apps & another for building the open source). I dont know how to avoid this. Cleaning the project doesn't help.
What i require is to use the open source and invoking it's activities in my apps without violating the constraints. If i can use the open source as bunch of .class files then great, or else any other way will do fine.
Please look into it and let me know.
Thanks
© Stack Overflow or respective owner