When referencing a library project with the current version of the ADT, an Eclipse linkedResource will be created in the .project file. I have a few questions about this.
Why an Eclipse link at all? Why not simply add the src/ folder of the library directly using a relative path? You have to set a relative path to it in default.properties anyway, for aapt to see its resource files.
This is more an Eclipse question, but I couldn't find an answer to this. The link that will be created has type 2. What does that mean? Which types are there?
The link does not use the location attribute, but locationURI, having this format: _android_<lib_name>_5deb8a74/src/main/java What is that, and where does it point? Does the 5deb8a74 part carry any special meaning, or is it just a random string generated to avoid name clashes?
UPDATE
I found the documentation on link definition syntax:
link - the definition of a single linked resource.
name - the project-relative path of the linked resource as it appears in the workspace.
type - the resource type. Value values are: "1" for a file, or "2" for a folder.
location - the local file system path of the target of the linked resource. Either an
absolute path, or a relative path whose first segment is the name of a workspace path variable.
locationURI - if the file is not in the local file system, this attribute contains the absolute URI of the resource in some backing file system.
Still not sure why the ADT would use a locationURI, and I still haven't found where these URIs are defined (i.e. where they point to).
Related
I am getting the following error while trying to use the google maps api using googleplayservices in android.
I have added the google play services library as dependency project and declared it in android manifest also.
Please help me i am unable to proceed and i have done every possible solution I found in stakeoverflow to solve this error.
Error:
Official solution is
Allow src/doc attachement for 3rd party jars in libs/
Since those jars
are added dynamically through a classpath container, the devs cannot
set the source path and the javadoc through Eclipse UI (container
don't allow editing those). To fix this, and to make sure that both
paths are picked up not only by the current project, but also by other
projects (if the current project is a library project), the value is
set by a file sitting next to the jar file. The file is name after the
jar file, adding .properties at the end. For instance foo.jar ->
foo.jar.properties It can currently contain 2 properties: src:
relative or absolute path to the source folder (or archive). doc:
relative or absolute path to the javadoc.
Check following question for more details
The Jar of this class file belongs to container 'Android Dependencies' which does not allow modifications to source attachments on its entries
For exampel my application has com.example.app1 packageName. When importing R file it hase com.example.app1.R path. If I change packageName to com.example.app2 it will have com.example.app2.R path. So it must be changed in all files (Eclipse does it atomatically) but I don't want to do it. So can I have path to R file independent from packageName?
No, you can't do that.
R is generated at compile time by the Android development platform as a class (and a collection of inner classes) belonging to the package your.app.package.name. As of today (API 20), no user preference or setting allows changing the way it is generated.
Can I make R file path independent from packageName? NO
Eclipse will immediately generate the resource file R.java related to your package name, if it changes the imports must chage since R.java file have all the resources IDs provided to resources related to your package.
In my Google Drive (in browser f.e.) i can see file structure - files and folders. In Drive SDK v2 (Android) i can't see any path property for the file. So how can i insert file in specific folder since insert() method does not have path parameter? how can i check file existence in specific folder and so on? what does it mean the file can have few parents?
Use the parents property which provides an array of parent 'folders" for any given file. This is both how you add a file to a folder and also query which folder a file is in.
A file can be in more than one folder simply by having multiple parents.
Be careful that if you delete a folder, all of the files in that folder will be deleted, even if they also exist in other folders.
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>
In a class belonging to a Library project I call:
webview.loadUrl("file:///android_asset/info.html", null);
Unfortunately, this only works if I duplicate the file info.html into the Application's project asset folder as well.
Is there a way to tell an Android library code: "look for this file in the library's assets folder, not in the application's assets folder" ?
This answer is out of date, the gradle build system and AAR files support assets.
From the Android Docs:
Library projects cannot include raw assets
The tools do not support the use of raw asset files (saved in the assets/ directory) in a library project. Any asset resources used by an application must be stored in the assets/ directory of the application project itself. However, resource files saved in the res/ directory are supported.
If you want to include files from a Library project, you'll need to put it in the resources instead of the assets. If you're trying to load HTML files from your library project into a WebView, this means that you'll have to go a more roundabout method than the usual asset URL. Instead you'll have to read the resource data and use something like loadData.
This is now possible using the Gradle build system.
Testing with Android Studio 0.5.0 and v0.9 of the Android Gradle plugin, I've found that files such as
MyLibProject/src/main/assets/test.html
are correctly packaged in the final application and can be accessed at runtime via the expected URL:
file:///android_asset/test.html
You can achieve this by creating a symbolic link in the project's asset folder that points to the directory in the library project.
Then you can access as below:
webview.loadUrl("file:///android_asset/folder_in_a_libary_project/info.html", null);
Okay. Ive been stressing out and losing sleep about this for a while. Im the type of person that loves API creation, and HATES complicated integration.
There arent many solutions around on the internet, so im quite proud of what Ive discovered with a bit of Eclipse Hackery.
It turns out that when you put a file in the Android Lib's /assets folder. The target apk will capture this and place it on the root of the APK archive. Thus, making general access fail.
This can be resolved by simply creating a Raw Java Library, and placing all assets in there, ie (JAVALIB)/assets/fileX.txt.
You can in turn then include this as a Java Build Path Folder Source in
Project > Properties > Java Build Path > Source > Link Source.
Link Source
Click on Variables. and Add New Variable, ie VAR_NAME_X. location : ../../(relative_path_to_assets_project)
Click Ok
Now, when you build and run your app, the assets folder in the APK will contain your (GLOBAL Library) files as you intended.
No need to reconfigure android internals or nothing. Its all capable within a few clicks of Eclipse.
I confirm that Daniel Grant's approach works for at least the following situation: target project does NOT have an asset folder (or the folder is empty, so you can safely delete it).
I did not setup any variable.
Simply setup a LinkSource as follows (just an example)
Linked folder location: /home/matthew/workspace_moonblink/assetsForAdvocacy/assets
Folder name : assets
The "assetsForAdvocacy" is a Java project, (created with New- Project - Java Project) with empty src folder, and a new folder named "assets", which now provides the entire assets folder for the target project.
This is a fairly straightforward way within Eclipse to provide assets re-use across many different projects IF they do not already have assets, good enough to get going with. I would probably want to enhance it to become a content provider in the long run, but that is a lot more development.
My project accesses the assets with the following code:
String advocacyFolderInAssets = "no_smoking/"; //a folder underneath assets/
String fn =advocacyFolderInAssets+imageFilename;
Bitmap pristineBitmapForAdvocacy = getBitmapFromAsset(context, fn);
I use Motodev Studio 3.1.0 on Ubuntu. It would not let me 'merge' a new assets folder in the new assets-only project onto an existing assets folder in the target project.
If you want to use a setup where multiple derivate products are created from one library you might consider using svn:externals or similar solution in your SCM system. This will also do the trick that static assets like online help may be versioned seperately from the android source code.
I found this older question, it might help you, too.
This is the official way Google uses to archive this (from the above post): Link