Giter Site home page Giter Site logo

aamp's Introduction

aamp

android aop

[来源]https://dashitesh.medium.com/android-method-profiler-tool-amp-using-aspectj-5c85af8ed599

更新为最新grade版本配置文件

classpath 'com.android.tools.build:gradle:7.4.1'

distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip

apply plugin: 'kotlin-kapt'

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'org.aspectj:aspectjtools:1.9.5'
    }
}


dependencies {
    implementation 'org.aspectj:aspectjrt:1.9.5'
    implementation project(':amp-runtime')
}


import org.aspectj.bridge.IMessage
import org.aspectj.bridge.MessageHandler
import org.aspectj.tools.ajc.Main

final def log = project.logger
final def variants = project.android.applicationVariants

variants.all { variant ->
    if (!variant.buildType.isDebuggable()) {
        log.debug("Skipping non-debuggable build type '${variant.buildType.name}'.")
        return
    }

    TaskProvider<JavaCompile> taskProvider = variant.getJavaCompileProvider()

    taskProvider.configure {

        String path = javaCompile.options.bootstrapClasspath.join(File.pathSeparator)
        String cp = javaCompile.classpath.asFileTree.filter {
            !it.canonicalPath.contains("transforms")
        }.asPath

        javaCompile.doLast {
            String[] args = ["-showWeaveInfo",
                             "-1.9",
                             "-inpath", javaCompile.destinationDir.toString(),
                             "-aspectpath", cp,
                             "-d", javaCompile.destinationDir.toString(),
                             "-classpath", javaCompile.classpath.asPath,
                             "-bootclasspath", path]

            String[] kotlinArgs = ["-showWeaveInfo",
                                   "-1.9",
                                   "-inpath", project.buildDir.path + "/tmp/kotlin-classes/debug",
                                   "-aspectpath", cp,
                                   "-d", project.buildDir.path + "/tmp/kotlin-classes/debug",
                                   "-classpath", javaCompile.classpath.asPath,
                                   "-bootclasspath", path]


            MessageHandler handler = new MessageHandler(true)
            new Main().run(args, handler)
            new Main().run(kotlinArgs, handler)

            for (IMessage message : handler.getMessages(null, true)) {
                println("MethodTracing app log " + message.getKind().toString() + " " + message.message)
                switch (message.getKind()) {
                    case IMessage.ABORT:
                    case IMessage.ERROR:
                    case IMessage.FAIL:
                        log.error message.message, message.thrown
                        break
                    case IMessage.WARNING:
                        log.warn message.message, message.thrown
                        break
                    case IMessage.INFO:
                        log.info message.message, message.thrown
                        break
                    case IMessage.DEBUG:
                        log.debug message.message, message.thrown
                        break
                }
            }
        }
    }


}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.