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.
Related
I'm switching from Elcipse to Android Studio. In Eclipse I have some "library projects" (no jar files, but Android projects marked as "library") that are used by several apps. In Eclipse I used to have this library project in only one place, and I liked to modifiy the library only once, and see the effect on all the other projects depending on it.
In Android Studio, when I add a library module, all the code is copied inside the app. I don't like it, because it's easier to maintain having it only in one place. Is there any way to reference the original library instead of copy it inside the project?
I've been reading a lot of about this, but I can't find the right solution. These are the ways I'm thinking to do it:
a) Aar files and local maven repository: I would compile the library module into an aar file, and I'll save in an local maven repository, so I can reference it on my projects. But this has a drawback: every time I want to modify the library, I need to recompile to an aar file before I can test the changes in my project.
b) Symbolic links: Instead of copy all the library module inside the app folder, I'm thinking in creating symbolic links to the original folder. So the library will stay in only one folder. But I think this approach is so tricky, and there must be a better way to do it.
Android project referencing to multiple libraries, with resource files.
I want to generate a jar with resource files from the library project and want to use it in
main android project, am not using eclipse, I want this to be done through ant .
Is it possible, because I checked few sites, where they have given to delete the src
and distributing it as zip.
If its possible please give me the process how to go with building through ant.
As far I know this is not possible. Android does not package xml files or drawables in jar files and you cannot access them from another project. You could look at *.aar files, which were introduced last year. But it only works with the Gradle system and Android Studio. It can contain xml and drawable resources from your project.
I have a project that uses some resources.I want to create a library from it and publish it.I create a jar file with export option of eclipse,but it did not work.Then I search the we b and it seems that way works if and only if project does not use resources.But I saw this post.Here CommonsWare saya there is a way to create a jar file from a project that uses resources.But that answer has two link that do not open any page on the web and I could not test CommonsWare's answer.So my question is:
Is there any way to create jar library file from project that uses resources?
Note:
I read docs that say:
If you have source code and resources that are common to multiple
Android projects, you can move them to a library project so that it is
easier to maintain across applications and versions.
But as I said before,I want to publish my jar and docs say we can not create jar file from library project.And so I can not publish it.
Here CommonsWare saya there is a way to create a jar file from a project that uses resources.
Not in that answer. You can tell that by actually reading the answer.
But that answer has two link that do not open any page on the web
Sorry, Google reorganized their site and broke the original links. The answer has been updated with current links.
Is there any way to create jar library file from project that uses resources?
No.
You can create an Android library project that includes a JAR instead of Java source code. 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)
And the new Gradle-based build system supports the AAR package for distributing libraries and such, though I have not played with this yet.
As the topic indicates I would like to create a jar library that uses some android functions (no layouts) and that will be included in an Android project.
Is that possible and how?
From the research I've made I managed to include a simple jar file that uses pure Java (JAVA SE 1.6), but
when I tried creating a jar file I encountered the following exception when I tried to run the Andoid app: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: mylib.pleasework.amen
I tried including android.jar in my library and removing the java library, so that the jar file is build against android sdk, but it didn't work.
I tried including the jar file under a /libs folder as it is said to be the correct way to import jars in android projects from ADT v17 and after, but that didn't work either.
The jar I want to create will not use any resources (xml layouts, strings.xml) just Log.d and WifiManager.I am aware of Android Library Project but my library source is sensitive and I am afraid that it won't be safe if exposed in a Android library project. I was thinking of creating a jar and using ProGuard ( http://developer.android.com/tools/help/proguard.html ) obfuscate it.
I think I mentioned everything. Any help will be appreciated.
Thanks,
Thomas
As the topic indicates I would like to create a jar library that uses some android functions (no layouts) and that will be included in an Android project. Is that possible and how?
Use the jar command, or the <jar> Ant task. I am sure that there are ways to export a JAR from Eclipse, but I personally have never used them.
For example, in this GitHub repo I have a reusable component and a sub-project that is a sample app. My build.xml for the repo contains the following custom task:
<target name="jar" depends="debug">
<jar
destfile="bin/CWAC-WakefulIntentService.jar"
basedir="bin/classes"
/>
</target>
This generates a JAR file, that other Android applications can use by adding to their libs/ directories.
I am aware of Android Library Project but my library source is sensitive and I am afraid that it won't be safe if exposed in a Android library project.
It won't be safe exposed as a JAR, then, either. You can create an Android library project for public consumption that replaces the src/ tree's contents with a compiled JAR in libs/ in the library.
The way I did it in the end was: to create an Android Library project (check isLibrary checkbox in project properties) export it through Eclipse (right click on the project->export->jar file, careful to deselect all resources - res folder, androidmanifest.xml, *.png etc) and put it in the project you want by importing it under /libs folder. I don't know if this is the best solution but it worked for me.Used ADT r20, Eclipse 3.7.1, Android api level 7
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.