I have a working app and now wish to include an advertising system by mopub. Looking at their getting started guide it says I should fist extract a "library project" (I'm not even sure what that is) using git. After having done that I now see that I have a directory called mopub-android-sdk inside this directory are a tree of further files and subdirectories.
The guide then states "Make sure the Android SDK files are in the same parent folder as your project"... this is where I'm confused. I have all my source files, androidmanifest etc in a directory c:\android\mygame am I now supposed to put mopub-android-sdk and all its sub-tree inside c:\android? or inside c:\android\mygame? (or somewhere else?)
EDIT: Some answers/comments have discussed the idea of converting the library project into a .jar file and then putting that in my libs directory... I have no objection to this so long as someone tells me there are no disadvantages to this compared to not making a jar - thinking about it more, wouldn't the jar have to include every single function, whereas if I left it as a library project, the compiler may be able to omit unused code?
EDIT: Now I am getting more sceptical about the make-jar-then-put-in-libs approach. I found mopub-android-sdk.jar in the bin\res directory and copied it to my projects libs directory. The ad system seemed to work fine, except in the location on screen where I expect to see a specific icon (to dismiss the full screen ad) there is a junk image. I noticed that amongst the tree of files beneath mopub-android-sdk there is a res directory containing png files. I suspect that these images are not in the jar file.
If you're simply including a *.jar library, put it in the libs/ folder of your project.
If you're trying to include an entire project...
Right click the project you want it to be included into and go to properties. On the left side where there are tabs, select "Android". In the area that says "Library" press the "Add..." button and then select the project you want to include. Do a clean build of your project.
Download the library to your host development system.
Create a new folder, libs, in your Eclipse/Android project.
Right-click libs and choose Import -> General -> File System, then Next, Browse in the filesystem to find the library's parent directory (i.e.: where you downloaded it to).
Click OK, then click the directory name (not the checkbox) in the left pane, then check the relevant JAR in the right pane. This puts the library into your project (physically).
Right-click on your project, choose Build Path -> Configure Build Path, then click the Libraries tab, then Add JARs..., navigate to your new JAR in the libs directory and add it. (This, incidentally, is the moment at which your new JAR is converted for use on Android.)
Related
We have an android application and are using some third party licenses. What is the best place to include these licenses in the app? In iOS we include it in the setting bundle, but I am not sure the best place to do so in android.
Thanks for you help
For my apps I generally place the license .txt file in the assets directory. Read the Github (I generally use library from github) page thoroughly about licencing. Notify the original creator about the use of his library. Then, if the product is of a client I will ask if to include the creator with link in the about section(if there is one). In my own apps I will include the link and author in the about section somewhere in my app.
Here is the step-by-step:
Download the library to your host development system.
Create a new folder, libs, in your Eclipse/Android project.
Right-click libs and choose Import -> General -> File System, then
Next, Browse in the filesystem to find the library's parent directory
(i.e.: where you downloaded it to).
Click OK, then click the directory name (not the checkbox) in the
left pane, then check the relevant JAR in the right pane. This puts
the library into your project (physically).
Right-click on your project, choose Build Path -> Configure Build
Path, then click the Libraries tab, then Add JARs..., navigate to
your new JAR in the libs directory and add it. (This, incidentally,
is the moment at which your new JAR is converted for use on Android.)
NOTE
Step 5 may not be needed, if the lib is already included in your build path. Just ensure that its existence first before adding it.
This is also explained at adding-a-library-jar-to-an-eclipse-android-project.
The title might seem confusing (although accurate). Let me explain it in more words:
I have an android Library project, lets call it ProjectA. I also have second android Library project, lets call it ProjectB. The ProjectB and ProjectA are in the same workspace, and ProjectB is referencing ProjectA in it's libraries list (project properties). So ProjectB is using ProjectA.
Now what I want to accomplish is to get a simple jar of the library - ProjectB, and include this jar as external library in my yet another android project (android application this time).
However... when I compile ProjectB, the jar size is way too small (the ProjectA's jar is over 300KB, yet ProjectB's jar is only 14KB), so I'm sure it does not contain ProjectA's in the jar file I find inside bin folder (of the ProjectA). To do a quick math, ProjectB's jar should be ~300KB bigger.
So to repeat, I'd like to have everything the library needs, packed in one jar file (jar file of ProjectB's), so that when I import it into libs of an Android Application I can use it.
Any help here from expierienced Android dev?
If you are searching for the quickest way to do this, in Eclipse highlight your library project, then go to File > Export and under Java select JAR. From there, you can select a multitude of options, including which other referenced projects should be exported as part of the JAR.
Commonsware is correct, it's just a JAR, there is no magic. If you need a build system option then consider using Ant or Gradle to package the JAR for you. Do not however, try to use what is in the bin folder, as that is not meant for you to use.
You need to make sure you export the library in your Build Path. For Eclipse, you can Right-click on the project, choose "Build Path" > "Configure Build Path", go to the "Order and Export" tab on the right side, and make sure that your library is checked in the list there (it might be contained in one of several library groups if your Project has multiple dependencies).
I am trying to compile a java project which makes uses of android libraries. The project I am using is checked out from a svn repository.
In order to take a use of that project I am required to define some jar files and libraries for that project.
Here are the files that I need to make sure they are defined:
•"lib/apache-mime4j-0.4.jar" : Jar
•"lib/httpmime-4.0-beta1.jar" : Jar
•"lib/slf4j-android-1.5.8.jar" : Jar
•"JUnit 4.libraryclasspath" : Library
•"ANDROID_SDK_PLATFORM/android.jar" : var
•"Java JRE System Library" : Library
Does anyone have any idea about what should I do to define these files? I am a noob here.I do not know which selection should I choose When I clicked "project -> properties -> java build path -> libraries"
For example if I want to define the first jar file, there are a "add external jar" and a "add libraries" selections.
However you can see a "lib" here in front of the "apache-mime4j0.4.jar file" in this list above..
So I don't understand if it is asking me to add a jar file or the librabry.. I am getting very confused about this.
And also How can I do anything with "JUnit 4.libraryclasspath" file? I think it is a classpath file so I cannot either choose "add jar files" or "add libraries" to define it..
Hope someone has any knowledge about this and I will be very appreciated!
I think You are unable to include the files due to SVN path but will discuss it later.At first we look how to add jar files
Right click on your project in which you want to add the jars
1.select build path and then "configure build path"
2.click on "Libraries" tab
3.Now click on Add external jars (as your all jars files would be placed in some directory outside the project folder or anywhere else)
4.Select these jars and now do OK ... Now these jars are in your class path and you can use these files.
Now another thing, As You told that you are using svn , It means many of other developers are also using the same project then it is compulsory that all of you have same path of jars in your systems for instance in Dev1 PC the jar if the jar file is placed in d:/lib/jars folder then all other DEV2 , DEV3 ... DEVn must have d:/lib/jars folder and their jars must be placed there and you have to add these jars from d:/libs/jars
Last thing , If you are still unable to understand the solution and remove the bugs then simply do this.
Copy all jar files manually (ctrl+c) and copy to lib folder in your project as i have seen that in your project the person who commits the code place them there.
after then , right click on your project and click refresh(as it is bad practice to put jar files in project by creating folder like lib etc unless it is a web project)
Let me know if anything is unclear about this
I deleted a jar from my libs file and now I cannot build the project and the jar will not go away.
I've tried cleaning the project, fixing the android properties now I'm stuck.
Has anyone else had this problem?
Description Resource Path Location Type
Archive for required library: 'C:/apps/APP/libs/imagecrop.jar' in project 'APP' cannot be read or is not a valid ZIP file APP Build path Build Path Problem
Solution.
Don't use clean or "fix project properties"
Simply right click on the project and press "Refresh"..
You need to remove it from your build path. Right click your project, go to Properties->Build Path. The build path contains four tabs:
The Java Build Path properties page contains four tabs:
Source. The source and output folders. If you initially create a project without separate source and output folders, you can change it here. Multiple source folders can be used in one project; e.g., to separate application source code from unit tests.
Projects. Check-off other projects in the workspace whose output folders should be added to this build path.
Libraries. Location of other archive files required by this project.
Order and Export. Order in which projects and libraries appear in the build path and the default runtime classpath; e.g., use classes from a workspace project before using the same classes from an archive library.
Go to libraries tab and remove the jar file you deleted.
Also refresh your project by right click -> Refresh so it will realize you deleted jar file.
I'm working on an Android project and i need to import an XML library called XOM. The only way i found was to right click on the project name -> Properties -> Libraries tab -> click on "Add external Jar". But that only references it from it's original path, what happens when i compile the app and move it to my phone? Will the Jar be in there?
Might be a stupid question, sorry if that's the case.
It's fine to do that but what I normally do is create a folder called liband then add Jars from there. I find that makes it easier to see what Jars I have in my application.
The main disadvantage of your original approach is that what if the path to that library externally accidentally changes? then your program will not compile. It's better to have everything in the one place to make things easier.
.apk is nothing but a collection or zipped version of a file. it contains all the resources and compiled java files.
So you need not have to worry about the inclusion of your library files. if you have set proper path to your libraries in eclipse then these will be included in your apk file.
Create a directory called "libs" in your under your root directory. You can do it by,
Right click on the project which is in the Package Explorer window in
Eclipse.
New -> Folder -> give "libs" as the Folder name
Copy your jar file and paste it to in the "libs" folder
Expand the "libs" folder
Right click on your copied jar file -> Build Path -> Add to build
path
That's it