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。
3 Answers
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. 2 Comments
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