miaowmiaow / fragmject

fragmject is a learning project prepared for Kotlin and Jetpack Compose. | fragmject 是一个为初学者准备的上手项目。 通过对 Kotlin 和 Compose 的系统运用,实现的一个功能完备符合主流市场标准 App。 fragmject 没有复杂的业务和多余的封装, 完全依照 Android Developer 官方的写法。 代码简单,内容全面,快速上手,对理解其他项目设计思想和封装技巧也很有帮助。
Apache License 2.0
1.32k stars 233 forks source link

字节码插桩,我随便写了个方法,没有输出方法的执行时间? #10

Closed hanxiaofeng closed 2 years ago

hanxiaofeng commented 2 years ago

override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_home)

    showMainName()
}

fun showMainName() {
    val textView = TextView(this)
}

筛选execution time,onCreate和showMainName都没有输出执行时间,求解惑!

miaowmiaow commented 2 years ago

请检查是否正确加载插件: 根目录下:build.gradle app目录下:build.gradle 请检查是否正确配置打印方法: timeMethod = [ [ 'time' : 100L, 'owner': 'com/google', ] ]

hanxiaofeng commented 2 years ago

请检查是否正确加载插件: 根目录下:build.gradle app目录下:build.gradle 请检查是否正确配置打印方法: timeMethod = [ [ 'time' : 100L, 'owner': 'com/google', ] ]

直接在你项目里测试的,新建了个module,build.gradle代码如下:

`plugins { id 'com.android.application' id 'miaow' }

android { compileSdk 32

defaultConfig {
    applicationId "com.android.asmtest"
    minSdk 21
    targetSdk 32
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

}

dependencies {

implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

}

miaow { //方法耗时打印 timeMethod = [ [ 'time' : 0L, 'owner': 'com/android/asmtest', ], // [ // 'time' : 100L, // 'owner': 'com/google', // ] ] }`

期望可以打印onCreate的耗时,logcat筛选System.out,但没任何打印输出

hanxiaofeng commented 2 years ago

我在onMethodExit打印了下,执行到了的,但是就是没输出

image
miaowmiaow commented 2 years ago

通过上述的信息我没有办法帮你排查到具体问题,你可以参考README中的字节码文章。

miaowmiaow commented 2 years ago

哈喽,已经对AGP 7.0做适配,请拉取最新代码查看