Reference to external project doesn't work - android

Since I updated android SDK tools to rev19 my external Library Projects discontinued to be visible by referencing projects.
With new dependency behavior I moved jars to /libs folder which has fixed references with external jars.
Addining a link to the LIbProject
Link added with the absolute path
When properties reopened again the link appears broken
This link helped with external jars. http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
This is literally what I'm getting, not with jars but Library Projects.
http://code.google.com/p/android/issues/detail?id=27490
How to reference external projects now?
Edit:
Somehow reference to the Library Project is broken. From the referencing project I add link to a LibProject. Project->Properties->Android->Library->Add. When the lib project added, reopening properties shows that the link is broken. Projects are on different logical disks. If projects in a common root folder then linking works.

Where to store the actual library project does not matter, as long as you use a relative link to reference it. Check out the Library Projects - Development considerations:
Library project storage location
There are no specific requirements on where you should store a library project, relative to a dependent application project, as long as the application project can reference the library project by a relative link. What is important is that the main project can reference the library project through a relative link.
Check out my answer here to see the screenshot examine how correct (by using relative path) and broken (by using absolute path) library reference links are shown in Properties window.

Related

Remove appcompat_v7 project without affecting its functionality

While create an Android project in eclipse, it created 2 projects.
appcompat_v7
MasterCopy <- This is the name of my project
I understand that appcompat_v7 is a library project that android automatically created for me.
Once the above projects are created I got an error message 'The container 'Android Dependencies' references non existing library'. To address this I just build the appcompat_v7 project and that clears the error.
Basically I don't want appcompat_v7 as a separate project. This is how looks like.
If I delete the appcompat_v7 project I got the 'Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar' in styles.xml file.
Is there a way I add appcompat as external library or JAR file into the MasterCopy project and keep one project as whole without loosing the functionality?
I am not sure whether I am making any sense here... But this is how I asked to create the project.
Explanation
The issue you're going to have is that resources, such as styles like Theme.AppCompat.Light.DarkActionBar, cannot be packaged simply in a jar file. As Google's documentation explains:
Some Support Libraries contain resources beyond compiled code classes,
such as images or XML files. For example, the v7 appcompat and v7
gridlayout libraries include resources.
Google has specific documentation for how to include libraries that contain resources, which it appears you've followed:
https://developer.android.com/tools/support-library/setup.html#libs-with-res
The reason why it's a good idea to keep this in a separate project, is that it allows you to easily upgrade, build, and otherwise manage that project separate from your own as the compatibility library changes.
(Unrecommended) Solution
That said, if you really want to have a single project, you could manually copy everything from the sample project for the app compat library (located in <sdk>/extras/android/support/v7/appcompat/) into your project. Notably, you'll need to copy everything from the res/ folder and merge it with your own resources, or rename google's XML files such as res/values/strings.xml to strings-appcompat.xml, and of course the appcompat jar file itself.
Again though, you'll have to go through this process every single time you want to update the version of the compatibility library that you use.
(Good) Alternative Solution
Google has specifically created the AAR format, which bundles resources with a jar file. If you transition to a Gradle build system (easy if you're using Android Studio), then all you have to do is refer to this app-compat-v7 aar artifact (also explained at the link above), and you can maintain a single project.

Importing android gradle project into eclipse

I need to import this library project into my eclipse. While i am trying to use this project it have some error. Can you help me on this. https://github.com/daimajia/AndroidImageSlider
That project is created for use with Gradle for Android. Eclipse does not support that yet. It is also distributed as an AAR, which Eclipse does not support. There are recipes for converting AARs into Eclipse-friendly Android library projects that you can try. Otherwise, you will need to reorganize the project code yourself to support the classic Eclipse-style project structure. Mostly, that will involve moving the contents of library/src/main/ into a regular Eclipse Android library project:
The res/ directory and AndroidManifest.xml file would go in the library project root directory
The java/ directory would be renamed src/ and also go in the library project directory
However, you will have to repeat this process each and every time the library's author updates the library, at least for those updates that you are interested in.
You may wish to see if there is an alternative library that meets your needs but is better packaged for use with Eclipse.
Basically there are some changes to be done to eclipse project before importing it to eclipse like src folder.
The project you posted may contains many error since it have two more android project dependency.
I tired to convert above project with its dependency :
Checkout Complete Source Code
There is one more project lib u need to add LIB

How to include external libs in Android source controlled project?

How should external libraries be included into Android projects?
I see this documentation from Google:
http://developer.android.com/tools/support-library/setup.html#libs-with-res
...which says they should be kept outside the source tree for the project, and referenced as dependencies.
The guide for Facebook libraries says the same thing:
https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/
What about when the project is going into source control, and will be worked on by multiple developers? Is it possible to be sure other developers will have the correct versions of libraries if they're not included in source control?
It seems as though it might be better to check in the whole tree of these external libraries under say an "external" folder in the project and then reference them as libraries from there? The above links don't say this is wrong, but is there any reason not to do that?
I could not find anything against this approach, but maybe my search skills are off.
Thanks!
You have basically tree options (referring to git):
Putting the source or binaries into your git repository.
You can create/clone extra repositories and link these as submodule into your main repository.
Use gradle/android-studio to maintain remote binary dependencies.
In my opinion, option 3. is the best. It speeds up build time and reduces the date saved in your internal repository. Referencing most open source projects, googles libraries and even the Facebook API is just a one liner in your build.gradle file.
For internal libraries or anything not uploaded to some maven repository, you can create a local maven repository and link that.
And in the end, you have the option 2. to create a library submodule within git and gradle to handle it efficiently.
If you want to stick to eclipse + ant, try 2. first.
At least ant will work out of the box for building all things.
Setting up eclipse is a bit more difficult but can be done.
Option 1. is easy to implement, but It might get messy at some point.
Copy jar file in android project libs forlder and right click on jar file and click on bulid path-> add to build path.
If you want to add jar file then copy your jar file and put in to libs folder, and if you want to add external library then import your library project go to project properties and select android tab and add external library with add button.

Create a JAR for Android Library Distribution

I am working on an android library, and wish to export a JAR file that I can distribute for others to use in their apps. I don't want to distribute the source code as it contains details on posting to my web server.
I have tried using the JAR file that is created in the bin directory and copying the jar file to my project and referencing it within my project and ticking the export button.
When I try and run my project referencing the library that I've copied, my app throws an exception with NoClassDefFoundError. I've done some Googling and everything I have found suggests you have to provide the source code and let the user import into their IDE and then reference that project into their app which I don't want to do. It must be possible as other companies provide JAR files for libraries that can be included.
Thanks for your help.
I don't want to distribute the source code as it contains details on posting to my web server.
Bear in mind that anyone who wants to can get that data out of the JAR.
It must be possible as other companies provide JAR files for libraries that can be included.
AFAIK, this recipe still works:
Create an Android library project, with your source code, resources, and such, and get it working
Compile the Java source (e.g., via Ant) and turn it into a JAR file
Create a copy of your original Android library project to serve as a distribution Android library project
Place the compiled JAR from step #2 and put it in libs/ of the distribution library project from step #3.
Delete everything in src/ of the distribution library project (but leave the now-empty src/ directory there)
Distribute the distribution library project (e.g., ZIP it up)
This effectively gives you what you see with the Play Services SDK -- a library project with no source code, but instead a JAR in libs/, along with the resources and such.
I will be reconfiming this recipe tomorrow and will try to remember to update this answer if I find that it needs adjusting for the current crop of tools.
And the new Gradle-based build system supports the AAR package for distributing libraries and such, though I have not played with this yet.
UPDATE
This recipe works, so long as the library project does not itself have dependencies upon another JAR or library project. In those cases, things seem to get messed up in the build process -- everything can compile, but class references from the dependencies cannot be resolved at runtime.
Did you try putting your jar file in libs folder?And if you are exporting a jar library for android be sure it has no /res folder. As you know you can't reference to your res folder from a jar therefore you have to use library project to reference your res folder (drawable,xml,ect...)On the other hand you cant make your code safe (the part you say about posting to your web service) by using it as jar since it is so easy to retrieve by reverse engineering. you better use some encoding (like base64 or any algorithm that bouncycastle provides)

What does checking the "is Library" checkbox do "Under the Cover"?

I noticed that when I convert an existing Android Application project to an Android Library project by checking the "is Library" checkbox, nothing changes in the project's source code or XML files.
So what really happens when the "is Library" checkbox is checked? What changes internally, in the package and/or project files? Where can I learn more about this?
To better explain my question:
What I am interested to know (mainly
for troubleshooting purposes) is
what differentiates an Application package from a Library
package "under the cover"?
Is the fact that a project is
"Library Project" marked
somewhere? If so, where does it
mark it (obviously not in the source
files and not even in the res XML
files)
From the Managing Projects from the Command Line page:
The create lib-project command creates
a standard project structure that
includes preset property that
indicates to the build system that the
project is a library. It does this by
adding this line to the project's
default.properties file:
android.library=true
In other words, it's a property that is utilized by the build system and not by the operating system.
UPDATE: I'm on my iPhone so I won't type out a whole paraphrase, but here's a pretty good blog article discussing the differences between a Java JAR and an Android Library Project, including how the dex tools add the resources and dex code to the .apk:
http://devmaze.wordpress.com/2011/05/22/android-application-android-libraries-and-jar-libraries/
From the devsite: http://developer.android.com/guide/developing/projects/projects-eclipse.html
You can also designate an Android
project as a library project, which
allows it to be shared with other
projects that depend on it. Once an
Android project is designated as a
library project, it cannot be
installed onto a device.
A library project isn't packaged as a seperate redistributable file as you're used to with a jar. It's merged with the the apk file of your application.
The page you linked to mentions it in the Referencing a library project section.
As soon as the Properties dialog closes, Eclipse rebuilds the project, including the contents of the library project.

Categories

Resources