- How to integrate leakcanary-android service through AAR form
- How to get all relevant dependency files by online reference?
- #1. Disable Gradle offline mode
- #2. Add project dependencies as required by the documentation
- #3.Sync will parse and cache all related dependencies online after synchronization
- #4. Find the *.pom file in the directory where the dependency cache is located and analyze its sub-dependencies
- #5. Copy all dependencies out.
- #6. Retrofit .aar dependency file
- #7. Modify the project dependencies in the original online form to dependencies in the AAR form
- #8. Enable Gradle offline mode to use it normally.
- How to transform Release dependencies .aar file to integrate JAR class library files that are only used in Release mode?
- How to get all relevant dependency files by online reference?
How to integrate leakcanary-android service through AAR form
leakcanary-android 官网:square/leakcanary: A memory leak detection library for Android and Java.
How to get all relevant dependency files by online reference?
#1. Disable Gradle offline mode
#2. Add project dependencies as required by the documentation
In your build.gradle:
dependencies {
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
}
#3.Sync will parse and cache all related dependencies online after synchronization
#4. Find the *.pom file in the directory where the dependency cache is located and analyze its sub-dependencies
The general path of the Windows system cache:
.gradle\caches\modules-2\files-2.1\com.squareup.leakcanary\leakcanary-android\1.5.4
.gradle\caches\modules-2\files-2.1\com.squareup.leakcanary\leakcanary-android-no-op\1.5.4
The following types of files generally exist in subdirectories: *-sources.jar, .aar or .jar, *.pom
Open the *.pom file through the text tool, it can be seen that it is the text in XML format, and you can get the sub-dependency information by finding the following node data:
project - dependencies - dependency - artifactId
#5. Copy all dependencies out.
*.aar或*.jar
Copy all file dependencies in the cache and put them in the specified flatDir
directory (such as a libs
directory.)
#6. Retrofit .aar dependency file
Integrate JAR class library files that are only used in Release mode
#7. Modify the project dependencies in the original online form to dependencies in the AAR form
debugImplementation(name: 'leakcanary-android-1.5.4', ext: 'aar')
releaseImplementation(name: 'leakcanary-android-no-op-1.5.4', ext: 'aar')
Note that dependencies in the form of AAR need to build.gradle
be added with the following settings:
repositories {
flatDir {
dirs 'libs'
}
}
#8. Enable Gradle offline mode to use it normally.
How to transform Release dependencies .aar file to integrate JAR class library files that are only used in Release mode?
The ultimate goal is to:
- To ensure that the function can be used normally in the running mode ,
debug
leakcanary-android
- Ensure that no extra code and resources are added in release mode (only no-op classes are added to ensure that compilation does not report errors)
Release
Before retrofit: leakcanary-android-1.5.4.aar > libs is empty
After transformation: Add all its dependent JAR packages to the directory. leakcanary-android-1.5.4.aar > libs
leakcanary-android
Dependencies that are originally JARs are:
- leakcanary-watcher-1.5.4.jar
- haha-2.0.3.jar
Some of the dependencies are AARs that need to be extracted out of the JAR file:
- leakcanary-analyzer-1.5.4.aar
After decompressing it, extract it and change the name to distinguish it.
classes.jar
leakcanary-analyzer-1.5.4.jar
The final leakcanary-android-1.5.4.aar > libs
directory contains the following files:
- leakcanary-watcher-1.5.4.jar
- haha-2.0.3.jar
- leakcanary-analyzer-1.5.4.jar
Result verification
Release mode class structure diagram:
Debug mode class structure diagram: