How to create an android library project with no resources - android

I want to create a library project with just java/Android classes - but no resources. Basically it will contain helpers for IO etc. I have manually deleted the resources etc - the project is here - but I wonder if this can be done out of the box - or is my way not proper
NB: I need Android classes - so creating a regular java project is not an option (?)
Edit : if there is no out of the box way is there any catch in deleting the (edit: contents of the) res/ folder and the support library ? I would appreciate a 1-2-3 procedure

You need to keep project structure, incl. having res/ foder with drawable/ etc, but these folders can be empty. There's no requirement for your library to reference any drawable.
Others suggest it's mandatory for "app icon" but your library does not need any <application> entry in manifest, so it does not need any icon. The same applies to values/ and layout/ folders. Your library project have to have these folders (as required by build process), but having no file in them (so basically keeping them empty) is perfectly fine and valid and meets your requirements.

I believe you should keep all the required folders (including res) but you can leave them empty. Here is a guide for it.
http://developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject

I believe you cannot delete the res folder completely since the app icon is contained in it. However you can delete the default layout if you do not need it and any other content that is required for the app to work.
If you would like to access the Android classes you will have to create an Android project.
I hope this helps.

I have created a git repository to illustrate - I created a vanilla eclipse android library project (screens) added a git ignore (bin/) and then proceeded to delete unneeded resources (all the contents of the res/ folder) along with libs/ and assets/ and edit the manifest. The changes are in this commit for reference. Cleaning the project removed R.java along.
Will be adding more (.gitattributes and eclipse settings for android) but this is for now.

Related

Android/Cordova: Where to add files?

I have successfully created a project with the cordova command line tool and I am able to import this project in the Android Development Toolkit as well as run it in the emulator.
Now, I see the example files in the folder "/www". When I change these files, build the project (using CIT) and run it in the emulator, I do not see the changes I made. I assume that I need to change other files or put them in another folder. The assets folder is empty besides a file that says that I need to delete the exclusion filters to see the files. Do I need to change the files in there?
???
Thanks for any hint!
Once a cordova project has been created. It has a root /www folder where all resources are eligible to be shared on the added platforms (which you intends to add)
You should modify here. though its possible to modify resources per platform. (read more API)
Once any shared resource i.e. inside the main www folder are modified then you have to issue cordova build in order to reflect the changes in the corresponding platforms (which you have added)
You are unable to see the assets folder resources. Because by default it is hidden. Just select the project and go in properties and then remove the checks.
Import existing Android project --> select project --> right click select properties --> Resource --> Resource filters.
From the Exclude All , remove both items. This will show you resources inside assets folder.

How do I include ActionBarSherlock in the library so that it is reflected in all the systems?

I've included ActionBarSherlock in my project as a library, though it is not path independent. Thus, when I push it into my repo, the library path gets muddled up. How do I change that? How do I make it path independent?
If it were a Jar file, I could have included it in the lib folder of my project, but it is a library in itself. What to do about it?
Check your project.properties file to see where it is pointing to in regard to ABS..
if it says something like:
android.library.reference.1=/myfiles/location/bleh/blah/foo/ActionBarSherlock
and your project that references it is also in /myfiles/location/bleh/blah/foo/ (its nice to keep them in the same folder for simplicity)
you can change it to :
android.library.reference.1=../ActionBarSherlock
That way when you check out your repo all of your library references will be intact (provided that folder structure is intact on the actual repository).
and yes, despite the project.properties file saying "do not change me ohh nooo!" you can change it without any problems

Making subfolders in a resource folder

Is it possible to make subfolders in the resource folders in the Android project? I have about 200 images (thumbnails) that I need in my project and I could add them in the drawable-mdpi, but it would be better to not mix these images with the other ones. Something like drawable-mdpi --> thumbs --> all images here.
No this is not allowed. You are only allowed to make folders specified by the android documentation.
The allowed sub folder names are specified in the link. Android generates the R.java based on these structures and putting sub folders can cause errors.
actually, there are mechanisms in place that allow the R.java file to be generated when there are folders with non-standard names in the res folder.
(i ran into this wanting to share a git repo as a submodule of both an iOS and Android project, but not wantint the Android project to pick up files that resided in a folder i designated.)
aapt is the tool that creates the R.java file, and it can be invoked with the --ignore-assets argument. there is a set of defaults for this found in the google source documentation, or a less verbose description simply by invoking aapt from the command-line without any arguments (or --help, which isn't a valid argument, but presents help nevertheless). using the line aapt.ignore.assets=xxx in an ant.properties file in your Android project will accomplish pretty much the same thing, depending upon your needs or preferences.
if you do not have a build.xml or other mechanism that forces usage of ant (which i do not), one of the aapt --ignore-assets defaults is <dir>_*, which means ignore any folders starting with _.
this was my fallback: i created a directory called _iOS_retina and placed all of my #2x files in there. (in Xcode, i can simply pull in resources from wherever they reside). the default invocation of aapt simply ignores it. to further streamline my project, i also updated my .project file to contain a resource filter that ignores this folder, and thus it doesn't take any space in my eclipse environment, either.
<filteredResources>
<filter>
<id>1371429105277</id>
<name></name>
<type>26</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-true-false-_iOS_retina</arguments>
</matcher>
</filter>
</filteredResources>

Combining packages from different projects into a single project in eclipse

As part of the Android application I am developing in eclipse, I need to combine two packages from different projects into a single project. I tried copying the files in the package of the second project under the src folder of the first folder and copied other files required for second package into the res folder of the first project.
But the auto-generated Java files i.e R.java doesn't get updated on copying. I tried right clicking on the project and clicking on Android Tools -> Fix Project Properties. But nothing changed.
I would rather add a second source directory through a linked folder.
(Especially since they now support relative path (3.5), as the following picture illustrates (3.6 only)
alt text http://img411.imageshack.us/img411/1299/dynamicpathvariables.png)
Another solution is simply to add the second project in the "Project dependencies" of the first.
alt text http://img24.imageshack.us/img24/9511/eclipsebuildpath.png
I ran into difficulties with VonC's method producing force-close noclassdeffounderror at run-time since referencing the external project doesn't make the class available run-time. Perhaps I was not doing it correctly, but I found a different solution to share:
Put both projects that you need to combine into the same workspace and open both. Set one project as a library, and reference the library in the other "main" project, as shown in:
http://developer.android.com/guide/developing/projects/projects-eclipse.html
Don't forget to declare any applications you use from the library project in the main project's manifest.
You shouldn't have to resort to importing or cross-referencing projects.
As far as I am aware, the R.java file is generated from the XML files in res.
Specifically, it is created based on the "id" in layouts and "name" in the strings.xml file. (There are probably other things that do it, but this is what I know).
Perhaps, when copying your files, your ids are not formatted with the "+" that encourages the values to be created if they do not already exist.
For example, a TextView in a layout would contain:
<TextView
android:id="#+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
The plus there is crucial to new creation of values.
It may also help to put a basic edit into an xml file, save it, then undo the edit and save again. The saving may trigger the Eclipse plug-in to regenerate the R.java file.

Is there any way to make ADT project directory layout more flexible?

I asked this question on the android-developers group but didn't get any response, so I thought I'd try here.
The ADT eclipse plugin seems to have a pretty rigid idea of how an Android project should be structured - per http://developer.android.com/guide/developing/eclipse-adt.html, it needs to have the AndroidManifest.xml file at the root level of the project, plus res, assets, gen and src folders at the top level, and so on.
I'm wondering if it's possible to get the plugin to be a little more flexible with the layout it recognizes. In particular, I've been using a build plugin for the (scala-based) simple-build-tool, which expects projects to be laid out in a more Maven-like fashion, like so:
src/
main/
AndroidManifest.xml
assets/
res/
scala/
java/
test/
resources
<files to include in test jar here>
scala/
<test Scala sources>
java/
<test Java sources>
(see the simple-build-tool docs).
This is a layout I'm used to from maven-based java development. When I load a project like it up in ADT, though, I get a lot of complaints about a missing AndroidManifest.xml, a missing res directory, and so on. These things are all present, they just aren't where ADT expects them to be.
I don't necessarily need to use ADT to build my project, but I'd like to use it (and Eclipse) for editing. Can anybody tell me whether it's possible to make it more flexible in the directories it uses to find various Android-related resources?
Also, can anyone tell me whether the ADT plugin is open-source? I can't seem to find a link to its source code anywhere.
(As a note, I've also been trying to wrangle sbt to just do things in a way that ADT likes, and it's probably possible to do but it seems very tedious.)
Here's is where you can find the ADT source for r3 0.94, couldn't find the latest though
I do not believe you can change the Android project structure and have ADT understand it. It would be "very tedious" to do that even with the Ant-based command-line builds -- you'd have to make your own copy of the various Android Ant tasks, modify them to suit (and hope the underlying build tools allow what you want), then maintain them forever in the face of Android SDK updates.
Your structure is actually fairly close to the Android expectation, if you consider main/ to be the Android project. If you can convince sbt to allow src/ instead of java/ there, and if sbt won't complain about the resulting bin/ and gen/ you will wind up with in main/ after a compile, you might get it to work.
As far as I can tell, ADT requires those folder names, but there is a workaround: you can create "linked folders" in Eclipse. These are similar to symbolic links in Unix, but are stored in the Eclipse .project file instead of the filesystem, so they are only visible to Eclipse.
You can create one by right clicking in Eclipse the root of the project, and then selecting "Create New Folder". Click on "Advanced" and select the option to create a linked folder. Then type in where you want it to link to. You can use PROJECT_LOC at the begining to specify the project directory, so for your example you would type PROJECT_LOC/src/main/res as the folder to link to, and use the automatically generated name of "res" for the created folder.

Categories

Resources