How to include third party classes into the Android apk? - android

I have a couple of third party classes which serve as a library I can build my application upon. They are contained in a folder which was added Java Build Path -> Libraries (in Eclipse) with "Add Class Folder". It works fine so far an my app compiles. But the produced .apk contains only my classes and therefore the application does not run.
How can I tell Eclipse to package the third party classes into the .apk as well?

Eclipse will package all 3rd party classes in your apk that are in your Android project's classpath. It does this by default, as long as you are using the Android SDK plugin for Eclipse.
This is a duplicate of this question (and many others): How can I use external JARs in an Android project?

Don't need to add anything to Build Path. Just create a sub-folder called "libs" in the project. Put all jar files in libs.

Related

How to create Android library jar if not using resources?

I am creating an Android library, and I would like to create a distributable jar without revealing source code. The library does not use resources like layouts, images, etc. I understand that I can just copy the .jar automatically generated in the bin folder of an Eclipse Android project if I check 'is Library' under project properties.
Is there anything else I should be aware of? How does the client project know which permissions my library requires. Should I include those permissions in the Manifest of my library?
I understand that I can just copy the .jar automatically generated in the bin folder of an Eclipse Android project if I check 'is Library' under project properties.
I wouldn't, as you don't know how that JAR was created, and you don't know how that JAR might change as the tools change. That JAR is a side-effect of Android's internal build process and is not designed to be a production artifact. Create your own production JAR yourself (e.g., Ant <jar> task).
How does the client project know which permissions my library requires.
You tell them via well-written documentation.
Should I include those permissions in the Manifest of my library?
Since your JAR does not contain your manifest, that will not help.

Proguard Config File for Multi-Project Android App

I have a multi-project android application.
Project A has the Activities, but it has dependency on a Project B UI library project (which I also need to obfuscate), and a Project C Service Library(which I also need to obfuscate). These two jar files (uilib.jar and services.jar), appear under java build path of Project A as "Android Dependencies" along with a lot of third party libraries like commons.jar etc which I don't need to obfuscate. I need to know how to specify uilib.jar and services.jar so that these classes will be properly obfuscated. I would also like to remove all the other jars like common.jar from obfuscation since they are third party open source and I did not write them. Thanks

Does android-support-v4 jar will be bundled with the android application in which it is referred while compilation?

I have created an application on android, referring the "android-support-v4.jar" while compiling my application, so I want to know whether the generated apk will be bundled with the "android-support-v4.jar" or not?, If it gets bundled with the jar file then how can I ensure whether it is bundled or not?
Yes it will be bundled.
The classes you use from android-support-v4.jar have to be part of your .apk in the end. If they are not your app will crash because it refers to code that does not exist. If the app works you have successfully included it.
Edit: there is no .jar in the apk. The support classes are directly embedded with your classes into classes.dex.

How to include Java resources from a JAR in my Android APK?

I have an Android project that depends on a non-Android JAR that contains resources (Java resources, not Android resources), which classes within the JAR need to load. When running the application, these resources are not found (i.e., ClassLoader.getResourceAsStream() fails), apparently because the resources are not being included in the APK.
I found some discussion here:
http://code.google.com/p/android/issues/detail?id=10076#c7
But I need to build the APK in Eclipse. Short of doing a command-line build with a deprecated tool (ugh), or duplicating all the resources (ugh), how can I make it work?
Create your jar file with the classes you need and save it your computer. Then in the project explorer right click the project and go to properties -> Java Build Path -> Libraries. Now import the jar file.
You should now have full access to the classes and methods in your code and the jar file will be installed with your APK. My guess is you have utility classes and when you are calling them in your source Eclipse is importing them from another project.
The solution I have given works for sure (I do it myself).

Eclipse and Android application development

I am trying to use Roboguice in my app, but no matter how i try to add the jars they don't seem to be added to the apk doesn't include the roboguice/guice jars. What do I do? using eclipse 3.5 and adt .9.9
where did you put the jars?
I usually put 3rd party jars in the lib folder at the root of your Project folder (same level as src, assets etc) and they seem to get picked up when building the apk. Make sure in Eclipse you are referring to the jar from the lib folder as well!

Categories

Resources