Android studio recommends public class library projects and exports aar

    The commonly used UI controls, utility classes, etc. are encapsulated in a package (jar/aar) for reference by other projects.

    1. Establish a common library and export aar
    When such a project is established in ADT, it is enough to mark the Project as As a library in the new process. In Android Studio, you need to create a new project, and then create a new Module, similar to Android Library.
   When exporting an aar package, it is generally necessary to obfuscate the package. In AS 2.0, edit the build.gradle corresponding to this module, modify
      buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

miifyEnabled defaults to false, change to true.
   Modify the obfuscation configuration file proguard-rule.pro corresponding to the module. Do not confuse the exposed methods, variables, and some methods that the parent class component needs to call. Reference:
http://blog.csdn.net/kangbulb/article/details/40625149
   Start exporting the aar package, two ways. 1. Direct build-->make module, the XXX-debug.aar package will be generated in the build/output directory of the module. 2. Open the Gradle projects window (usually on the right side of AS), find assembleRelease under this module, and double-click to run it. The XXX-reelase.aar package will be generated in build/output, which is obfuscated.

   Second, use this aar.
   Put the exported aar in the libs directory.
   In the module where you want to use the public aar, modify build.gradle. Add the libs directory in the android{...} section:
    repositories {
        flatDir {
            dirs 'libs'
        }
    }

    In dependencies{}, add a reference to the exported package
  
compile(name: 'XXX-release', ext: 'aar')

  
   In this way, the content in the public library can be directly referenced in the project.
  

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326725764&siteId=291194637