use resources from jar (Facebook SDK as jar) - android

I'm using Facebook SDK project on my own project by adding it as a library inside my workspace, like:
Project properties -> Android -> Add.. -> Facebook SDK
Like this i have access to classes and resources inside this project. For example in one of my layout files i have:
android:drawable="#drawable/com_facebook_loginbutton_blue_normal"
But if i want to change the way i use this Facebook SDK project, and simple export it as jar file, and add it to libs folder in my app, i have the error:
error: Error: No resource found that matches the given name (at 'drawable' with value '#drawable/com_facebook_loginbutton_blue_normal').
How to access the resources inside my jar file?

The short answer is, you can't. The Facebook SDK is an android library, and is being shipped as such, and should be used as such. Trying to import it as just a jar file will not work. Do you have a specific use case that requires you to only use jar libraries?

From what i can understand..
That,s because that drawable resource is in different package than yours, try accessing it with full package name
EDIT
What I meant was add
android:drawable="#packageName:drawable/com_facebook_loginbutton_blue_normal"
Like this:-
android:drawable="#com.google.android:drawable/com_facebook_loginbutton_blue_normal"
I don't know what package name is defined in Android SDk so change package name accordingly.
Hope this helps.

Related

Android studio -- how to include resource file in Java package using gradle

I have an android project which requires to include a non-java resource file to included in the final package with Java class.
If you are using Eclipse, it is very easy, just put the non-Java resource file in the same package of Java classes, Eclipse will automatically copy the resource file to the destination.
I tried the same method in Android Studio, which uses Gradle for building, but it doesn't pack the resource file in the final Java class package. I have no control over how to read the resource file, it must use class.getResourceAsStream() to read the resource file.
Is there any way to pack resource file in Java package in the final product? Any suggestion is much appreciated.
First, Create a java resources folder.
Second, Create the same structure with a package name of a class.
for example, picture blow, you will have the same folder structure if you have a Tobee.class in a com.tobee package.
You can read a file in a Tobee class by calling a getResource or getResourceAsStream method.
getClass().getResourceAsStream("jar_properties");
Alright, I have solved the issue: pack everything in a jar including resource files then import this jar into the Android project.

Can't use the appcompat support library

I want to use the appcompat for my project in AIDE.
so I downloaded the jar file, add it into lib folder & coded my project.
but when I theming, by putting the code
android:theme="#style/Theme.AppCompat"
into AndroidManifest.xml, it gets an error, showing that no resources found that matches the name.
I modified the project.properties file, but still the same thing happens.
what shall I do?
AppCompact is a Library project. You must reference it in your Andorid Project instead of adding it as a jar.
Read
No resource found that matches the given name '#style/Theme.AppCompat.Light'

How to build an Android project to jar that included other project

How can I build one Android project to jar that is can included in other android project? When I use eclipse export an Android project to jar and use the jar to other android project ,The "R" file and the resource files will be error。
Android resource files (which are represented in your R.java files) cannot be put into Jars. That is why libraries such as ActionBarSherlock require to be opened as library projects, instead of simple Jars.
You can build Android Library Project to jar, but within library project you should prevent using R class, Instead of R class you can use reflection to load resources.
For example if you need to load string from strings.xml file
int id = context.getResources().getIdentifier("string_name", "string", context.getPackageName());
String value = context.getString(id);
But this is what they mentioned about getIdentifier method:
Note: use of this function is discouraged. It is much more efficient to retrieve resources by identifier than by name.
You can build Android Project to jar file but don't use any Resource file.
B'coz when you will try to use that jar file in your application at run time Resource not Found exception will come.
So while creating jar file please unchecked res,gen,Manifest, etc.
You can Define your Base Activity class, Base Interface, Database Manager, GPS Manager
in your library project and use it in your our application it will surely work.
So see the below screen shots.
Thanks

How to reference a drawable from a library project into a main project's layout in android?

I have a android library project and reusable drawable resources in it.
Lets say package name is: com.vijay.mylib;
Then i have a main project and it uses the above library project.
Lets say its package name is:com.vijay.myproject.
Consider that I have linked library project with my main project correctly.
In my main project i have a layout called main.xml.
I want to use some drawable rom library project in main.xml.
How can i do it in xml?
Refering in normal way like "#drawable/myImage" didn't work for me. The referece chooser windows shows me the drawables only from main project. Not from library project.
(Note : Both projects have different package for R.java. Does it has do anything with this?)
You probably would need to add your own uri for library and use it to refer to drawable.
xmlns:vijay="http://schemas.android.com/apk/res/com.vijay.mylib"
Then you should be able to access drawable using
#vijay:drawable/myImage
The best way to determine which drawable resources are used between a library project (lib project) and an application project (app project) is down to design:
By default, an app project's drawable resource will supersede the use of an identically named lib project's drawable resource. Therefore, the best way to ensure the lib project resource is used, is to remove the resource from the app project altogether.
Another issue i came across is that if you want the app project resource to be used in preference, be sure that the drawable folder name in the app project is identical to the resource folder name in the library project. I.e. if your lib project resources live in drawable-mdpi, ensure the folder is called drawable-mdpi in the app project too!
In 2022, it's easy to use, if the lib is imported to your project, as it's shown in below picture.
1- where do you want use it, just write R.drawable.any_png
2- open icon in left side, then chose the libraries item
3- you can see all the pictures are in two place in 3,2

Where to place twitter4j.properties in android project?

I'm developing Twitter application with xAuth support using twitter4j jar file.
I want to place my consumer key/secret in twitter4j.properties file.
Where should I put this file in directory structure?
On Eclipse project, put in "src" directory just below.
On Android Studio (gradle-style) project, put in /app/src/main/resources/ .
twitter4j.properties should be located
under either the default directory,
the root of your classpath, or the
WEB-INF/ directory
heres the doc.
http://www.devcomments.com/Twitter4J-now-supports-xAuth-at106339.htm

Categories

Resources