Recently, we found a large number of Module layers nested and repeated dependencies in the Module library of the company, and we have a Maven private server. Recently, the private server has been suspended, and several AAR packages have been mounted on the private server. The friends who were involved in the private server have left, and there is no hope for private server repair. The following figure




aar.png

For example, location_core relies on core_log and location_GD, and core_log and location_GD modules rely on AAR packages. And business_core relies on location_core, both of which are modules. Don’t ask me why I’m so complicated. I look big holding grass. There are so many child modules that depend on the public common AAR (private SERVER AAR address). If the private server fails, the whole project cannot run. There was a serious problem with packing, and we had to

gradle aR --offline
Copy the code

Offline packaging, through cached JAR packages, but not for a long time, developers are miserable. Later referred to the article toss about for a long time to solve the problem. Record it and share it.

Solution [thinking a lot]

  • First move VS repair private server connection server, began to reverse company Maven private server, original company private server is the image created by Docker. Docker ps is docker log Nexus restart, Docker logs nexus, nexus private server how can not wake up. The guy who was doing private service probably ran away with his sister-in-law, so I can’t do anything about it.
  • The second recruit built private service


sifu.png






Maven Nexus Private server does not support SNAPSHOT version upload




snapnot.png

  • There seems to be no hope of bringing Maven Nexus back from the dead. Rebuilding Maven private server still doesn’t solve the problem. You had to rethink downloading all the AAR packages to rebuild the project.


commm.png


Create a new gradle configuration for common_module. Create a gradle configuration for common_module.

apply plugin: 'com.android.library'
android{
  repositories {
        flatDir {
            dirs 'libs'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile(name: 'aaar name ', ext: 'aar')
    compile(name: 'aaar name', ext: 'aar')
    compile(name: 'aaar name', ext: 'aar')
    compile(name: 'aaar name', ext: 'aar')
    // android support
    compile supportDependencies.appcompat
    compile supportDependencies.v4
}
Copy the code

Pay attention to the point

  repositories {
        flatDir {
            dirs 'libs'
        }
    }
Copy the code

FlatDir under Repositories must be under the Android {} node! I don’t think we’re done yet. Modules that require an AAR package only need to rely on them under Dependencies

  compile project(':common_module')
Copy the code

Wait, it’s not over yet. Any module that depends on this common_module must declare this lib location in its build.gradle.

repositories { flatDir { dirs 'libs', '.. /.. /.. /.. /common_module/libs' } }Copy the code

Similarly, his Build.grade repository flatDir must be under the Android {} node! For example, there is a module called business_core that needs some AAR that depends on common_module. Dependencies compile project(‘:common_module’) Then declare it under the Android {} node

repositories { flatDir { dirs 'libs', '/.. /common_module/libs' } }Copy the code

. /.. /.. /.. / represents the location, which can be modified depending on the location and common_module. Yet!!! Build. Gradle in the project root directory should also be changed! Build. gradle is added to the root directory in the same way as the other modules. Build. gradle is added to the project root directory under the AllProject node. As follows:

allprojects {
    repositories {
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}
Copy the code

The above steps, a little less will compile failure, more bullshit, record, share. It’s a little bit complicated to write an absolute path, but it could be a little bit simpler. Define the location of common_module/libs in dependencies. Gradle

ext{
   COMMON_MODULE_DIR_PATH = projectDir.getPath() +  "/common_module/libs"
}
Copy the code

Other build.gradle can be relied on in this way.


    repositories {
        flatDir {
            dirs 'libs',  rootProject.ext.COMMON_MODULE_DIR_PATH
        }
    }
Copy the code

Reference: Android Studio library Module references aar file blog.csdn.net/qq_20872573…