How to integrate Leakcanary-android service through AAR form

Source: Internet
Author: User

    • How to integrate Leakcanary-android service through AAR form
      • How do I get all the relevant dependency files in a way that is referenced online?
        • #1. Disabling Gradle offline mode
        • #2. Add project dependencies as required by the documentation
        • #3. Sync will parse and cache all dependent dependencies online after synchronization
        • #4. Find the *.pom file in the directory where the dependency cache is located analyze its child dependencies
        • #5. Copy all dependencies.
        • #6. Transforming the. AAR dependency file
        • #7. Modifying the original online form of the project depends on the dependency of the Aar form
        • #8. Enable Gradle offline mode for normal use.
      • How to transform the release dependency. aar files integrate only Jar class library files used in release mode into one piece?
        • Pre-Retrofit: Leakcanary-android-1.5.4.aar > Libs Empty
        • After transformation: Add all of its dependent jar packages to the ' Leakcanary-android-1.5.4.aar > Libs ' directory.
        • Result validation
How to integrate Leakcanary-android service through AAR form

Leakcanary-android Official website: square/leakcanary:a memory leak detection library for Android and Java.

How do I get all the relevant dependency files by online referencing? #1. Disable Gradle Offline mode # # # 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 dependent dependencies online after synchronization. Find the *.pom file in the directory where the dependency cache is located analyze its child dependencies

The Windows system cache is typically located on the path:

    • .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 are generally present in subdirectories: *-sources.jar, . Aar or . jar, *.pom

Open the *.pom file with the Text tool, visible in XML-formatted text, find the following node data to learn its child dependency information:

Project-dependencies-dependency-artifactid

#5. Copy all dependencies.

Copies all the file dependencies in the cache for all *.aar或*.jar formats. and put it in the specified flatDir directory (such as the libs directory.)

#6. Transforming the. AAR dependency file

The Jar class library files that are used only in release mode are integrated into a piece

#7. Modifying the original online form of the project depends on the dependency of 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 depending on the Aar form, the build.gradle following settings should be added:

repositories {
flatDir {
dirs ‘libs‘
}
}
#8. Enable Gradle offline mode for normal use. How to transform the release dependency. aar files integrate only Jar class library files that are used in release mode?

The ultimate goal is to:

    1. The debug leakcanary-android function that can be used normally in operation mode is guaranteed,
    2. Ensure that Release you do not add any extra code and resources in the release mode (only add No-op class to ensure the compilation does not error)
Before transformation: Leakcanary-android-1.5.4.aar > Libs after an empty retrofit: Add all of its dependent jar packages to leakcanary-android-1.5.4.aar > libs in the catalogue.

leakcanary-androidDependencies are inherently jars:

    1. Leakcanary-watcher-1.5.4.jar
    2. Haha-2.0.3.jar

Part of the dependency is that the AAR needs to extract the jar file:

    1. Leakcanary-analyzer-1.5.4.aar

After extracting it, extract and classes.jar change the name leakcanary-analyzer-1.5.4.jar to differentiate.

leakcanary-android-1.5.4.aar > libs The following files are in the final directory:

    1. Leakcanary-watcher-1.5.4.jar
    2. Haha-2.0.3.jar
    3. leakcanary-analyzer-1.5.4. Jar
Result validation

Release mode class structure diagram:

Debug mode class structure diagram:

How to integrate Leakcanary-android service through AAR form

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.