Android uses the aar package and androidaar package
Some time ago, I needed to build an sdk project. I was bored with what packaging method I used. If I used jar to package, jar can only package class files. If I wanted to package the resource files
If there are not many interfaces, you can use reflection to reference resource files through this reflection R.
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)) { desireClass = classes[i]; break; } } if (desireClass != null) id = desireClass.getField(name).getInt(desireClass);
Now it's not so troublesome, Android studio provides us with a simpler way, You can package the class and res files at the same time, now the support v7 and gson-2.21 is aar packaging method
Packaging method:
First, we need to package the project into sdk into Android libraries B, instead of building an Android project, and then we create A new Android project A to call the prepared libraries B.
After running, studio automatically packs librarys B into an aar package. This is the sdk we want (Path: libraries B \ build \ outputs \ aar \)
Usage:
1. Copy the prepared aar package to the libs directory of the Android project to be referenced.
2. Modify gradle settings of 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 and execute app2.aar}
Check if there is not much app2 under external lib (including a jar and a res), it means the operation is successful.