I use the widget DateSlider provided by http://code.google.com/p/android-dateslider/
However, it also has its own resource files, I wonder how I can separate those resource files from mine.
You can set up an Android library project for that slider and include the library into your own project.
Take a look at the library project documentation
Related
I'm turning my one app into several similar apps and using a base library project. I want to load a video that will be in res/raw/welcome.m4a in the dependent applications.
This is how is was being done before using the library project:
vv.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.welcome));
This produces an error in my library project, because res/raw/welcome.m4v doesn't exist, it will only be in the App Project res/ folder, and will be different for each app.
My current workaround is to create a dummy res/raw/welcome.m4v in the base library project so it stops complaining.
So my question is how do I have code in the Library Project that refers to resources that don't exist in the Library Project?
If it is only happening infrequently, you can try this:
vv.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+getResources().getIdentifier("welcome", "raw", getPackageName())));
Not as performant as using the id, but it should work.
I try to use the dateslider in my android project to have a combined date-time picker im my gui.
The authors of the widget suggest to include the java- and resource-sources directly into my app.
1st try copy java and resources into main app:
Result: The widget java classes cannot compile because the resourceids R.xxxx cannot be resolved.
Reason: The widget classes are implemented in package "com.googlecode.android.widgets.DateSlider" and my app
has a different namespace "my.namespace.myApp" so that the resourceids come from my.namespace.myApp.R.xxx.
To fix this i would have to touch every widget java source to import my.namespace.myApp.
Is there a way to have 2 resource-sets with different namespaces so that there are my.namespace.myApp.R.xxx and com.googlecode.android.widgets.DateSlider.R in the main app?
2nd try put widget java+resources into seperate jar/library:
result: every thing compiled. but after appstart i get a runtimererror: the runtime cannot resolve the widget resource IDs from the jar/lib.
Note: i can call methods from the jar as long as these do not need resources.
So my question: what is the best way to consume a reusable gui element with resources in android?
I am using android 2.2.
Note: Android: How do I create reusable components? does not help because it tells you how to create library-projects.
update 16.3.2012
Since the current version 16 /17-pre of of the eclipse adt-tools do not support resources in jars (as of try 2) what is the best/easiest way to consume them until there is support for this?
update 4.4.2012
with the new R17-tools i succeeded to consume libraryproject-with-resources that creates the jar. Android-Lint helped me to find out what to change in the lib to make it usable.
eclipse-workspace
DateSliberLib
src
res
...
MyAppUsingLib
src
res
...
with this layout MyAppUsingLib is running fine
However I am still not able to use the DateSliberlib.jar alone
eclipse-workspace
MyAppUsingLib
src
res
lib
DateSliberLib.jar
...
This setting can be comiled but the app crashes because it cannot find the resources of the lib.
[update 2014-11-17]
6 months ago i switched from eclipse/ant-build to android-studio/gradle build which introduced *.aar files that are jar-files with android resources.
android-studio/gradle build can cope with resources in libs.
Is there a way to have 2 resource-sets with different namespaces so that there are my.namespace.myApp.R.xxx and com.googlecode.android.widgets.DateSlider.R in the main app?
No, sorry.
Note: Android: How do I create reusable components? does not help because it tells you how to create library-projects.
However, that is the right answer. Download the full project from their repo, import it into Eclipse, and mark it as a library project (Properties > Android). Then, add it as a library project to your app's project.
Eventually (which now appears like it will be the R18 version of tools or later), the tools should support packaging reusable components in a JAR, with resources, in such a manner that you can add them to a host project and the resources will be blended in automatically. Right now, that's not an option.
I am currently working on a Android Project where we are expected to merge our App with 2 more apps from vendors who wouldn't be sharing their code.So just wanted to know Is there any way we could just include there Source code as JAR Files in our project and then include their resources and point to them(I did do it using getResources().getIdentifier("splash", "layout", getPackageName()) But Its still not working ?? I think I have tried all possible methods so hoping you guys could help me with this.
To quote CommonsWare from this question:
Bear in mind that your packaged classes cannot reference resources (at
least not via R. syntax), and that JARs cannot package resources,
manifest entries, etc. If all you are trying to JAR up is pure Java
code (perhaps using Android APIs), then you should be fine.
Basically, you can only use JARs that contain pure java as libraries in your app, not entire other projects.
The Activities can be compiled into a jar and added to the main Android project and we need to add their project's resources into your Project. The only we could make it work is using the getResources().getIdentifier("splash", "layout", getPackageName()). Even the Widgets like TextView, Button and all those should be referred to using the getResources() method. Like, for example, If you want to perform a action on particular button then we need to identify them by getResources().getIdentifier("Button" /*id in the XML File*/, "id"/*type*/, getPackageName()).
One more thing: you need to specify all the Activities in your Main Android Project's AndroidManifest.xml file with their package name. I hope this solves something.
In order to support faster build times, the r16 tools are creating their own jar files inside of Android Library Projects. You can use this feature to solve this issue. If a vendor would like to release their Android Library Project but without source code, they can make a copy of that Android Library Project that contains everything except for the source code tree. Next, include the jar file from the original Android Library Porject (the one that the r16 tools built.) This will allow you to have a component you can distribute that does not require source code. The consumer of this new Android Library Project will need to manually add any necessary meta data to their own project's AndroidManifest.xml file as needed (Activities, Providers, Permissions, etc).
I want to build a java library with some useful things I done to Android. Just like my other project: https://github.com/MarkyVasconcelos/Towel
My question is, what is the best way to share a library on Android?
Source codes from a entirely Android project(res, src, Manifest, etc..)?
Only source codes(.java)?
A generated jar with the 'src' folder?
Thanks.
I'd distribute an Android library project. I have several such projects in my various GitHub repositories -- those links are just three of 'em.
Although never done myself I think you have to provide an Android Library Project if your library contains android specific content.
I am successfully linking some of my code stored in a .jar-based library to my Android app. The .jar code references Android library content just fine.
The problem is I need to include 'res' resources in the library but can't work out how to do this.
Any suggestions?
This discussion http://www.anddev.org/viewtopic.php?p=30725 indicates this isn't currently possible.