Some time ago need to do an SDK project, is depressed with what packaging method, if using jar packaging, jar can only package class file, want to package the resource file in
The more troublesome the opinion thing, the interface is not many words can use the reflection call, the resource file all through this reflection of R reference.
String PackageName = Context.getpackagename (); 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)) { Desir EClass = Classes[i]; break; } } if (desireclass! = NULL) id = Desireclass.getfield (name). GETINT (Desireclass);
Now that's not so much of a hassle, Android studio gives us a much easier way to package class and res files at the same time, and now support V7 and gson-2.21 are the AAR packaging
Packaging method:
Let's start with a project that we want to package as an SDK for Android Libraries B don't build Android project then we build a new Android project a go to call write good libraries B
After running, Studio automatically packs our Librarys B into an AAR package, which is the SDK we want (path: libraries b\build\outputs\aar\)
How to use:
1. Copy the well-made AAR package to the Android Engineering Libs directory that needs to be referenced.
2. Modify Gradle settings for Android Studio
repositories{ flatdir{ dirs ' libs ' }}dependencies {// compile Filetree (dir: ' Libs ', include: [' * '). Jar ', ' *.aar ']) compile ' com.android.support:appcompat-v7:19.+ ' compile project (name ': App2 ', ext: ' AAR ')// Import App2.aar and Execute}
Look at the external lib. A app2 (containing a jar and a res) means success.
Android hit AAR pack