Android Jar Libraries

How do you set up a project that could lead to the creation of a jar library file that can be used for Android? I want to create a custom library in all projects.

A few other questions:

  • Do I need to compile it for a specific version of Android-sdk?
  • When the android package is compiled against the jar library, are the classes needed to work with the code compiled with the main code in apk or are all jars included?
  • Any noticeable optimizations or pitfalls I need to know about using a flag instead of directly integrating the code?
  • Do I need to sign the bank, as it is necessary for apk?
+54
android jar
Dec 31 '09 at 2:17
source share
7 answers

Google will just release a new version of the SDK that handles shared libraries!

https://developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject

ADT 0.9.7 (May 2010)

Library projects:
The ADT plugin now supports the use of library projects during development, an ability that allows you to store shared Android application code and resources in a separate development project. You can then refer to the library project from other Android projects, and build time, tools compile common code and resources within dependent applications. More information about this feature is available in development in Eclipse with an ADT document. If you are not developing in Eclipse, SDK Tools r6 provides an equivalent library of project support through the Ant system design.

+29
May 21 '10 at 12:27
source share
β€” -

There is nothing special about customizing your project to create a jar file that will work in an Android app. Just create a regular Java project in Eclipse.

  • It does not need to be compiled on Android at all. You can include any jar file if it does not reference classes that are not included in Android. Just include your jar file in your build path for your Android projects in Eclipse and it will be automatically included in your APK file.

  • Not sure, but I assume that all classes in the jar file will be included in the APK.

  • I don't think it's just including some classes in jar vs. in the project will directly have some meaning in the resulting APK.

+29
Dec 31 '09 at 2:26
source share

I asked myselft the same question: can I export and reuse the layout in Android. I tried the following: export the project with XML resources to a JAR file, and then try to access the layout through it R.layout. Of course, this did not work, since R.layout.main was an integer, the same integer that was associated with a single layout (relative.xml) defined in the R.layout host project.

The kompiles Android SDK files host the XML files as View resources, and the XML files in the included JAR file are not xml layout files, they are not compiled, and the identifier is not associated with them in R.layout.

If you want to export a layout from your project, you must export it as XML and import it into a new project as a layout resource, and not as part of an external library.

If you want to reuse layouts from the JAR, you need to subclass the view and create the layout from the code. Then you can create an instance and install the created instance as an activity view or add an instance to your activity view.

+5
Oct 31 '10 at 20:18
source share

This work is for me !!!. if you want to use the .jar file in your application from a library project that uses resources such as attrs.xml (and let others, such as layouts, lines, etc.) that generate R.java. you should go to export->Java/Jar file-> in eclipse and check Export all output folders for marked projects -> Finish ... this ensures that at run time your application using this jar does not throw an exception for missing clans and resources.

Of course, include the bank in the new project. project properties-> Java build path -> Libraries -> Add external jar -> and you're done.

Hope this help!

+5
Mar 29 2018-12-12T00:
source share

To create a jar file, you must use the Export Eclipse option. In the export dialog, select java and JOP the subprocess. Then a wizard is displayed where you need to make some selections. You need to specify the location where the jar file will be stored.

The error I made the first time I created the jar file was to enable the Android manifest. When adding the created jar file, I got a conflict with the dual android manifest.

+3
Sep 14 '11 at 2:09
source share

You can use a custom method to dynamically access the R file, for example, the link below.

Pack Android Resource Files into a Distributed Jar File

 public static int getResourseIdByName(String packageName, String className, String name) { Class r = null; int id = 0; try { r = Class.forName(packageName + ".R"); Class[] classes = r.getClasses(); Class desireClass = null; for (int i = 0; i < classes.length; i++) { if(classes[i].getName().split("\\$")[1].equals(className)) { desireClass = classes[i]; break; } } if(desireClass != null) id = desireClass.getField(name).getInt(desireClass); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } return id; } 
+1
Jun 12 2018-12-12T00:
source share

If you look at the android.jar file in the platform / android-XX / android.jar file, it includes elements of XML layouts, so you can also create them. I'm just not sure exactly how you do it and how you refer to them in another project.

0
May 19 '10 at 5:16
source share



All Articles