FlyJingFish / AndroidAOP

🔥🔥🔥AndroidAOP 是专属于 Android 端 Aop 框架,只需一个注解就可以请求权限、切换线程、禁止多点、一次监测所有点击事件、监测生命周期等等,没有使用 AspectJ,也可以定制出属于你的 Aop 代码
Apache License 2.0
392 stars 26 forks source link

AndroidAOP is causing the application to fail during installation when running UI tests. #33

Closed nanthakumaran-s closed 5 hours ago

nanthakumaran-s commented 1 day ago

I have completed the initial configuration for AndroidAOP in my multi-module project. I’ve set up the androidAopConfig in the app-level Gradle file and installed the necessary packages in the module-level Gradle file. However, I want to ensure this works during Android tests, but I’m encountering an issue where the app is not being installed on the emulator when running the tests.

NOTE: I haven’t tried installing the app in normal mode since my focus is solely on resolving the issue with AndroidTest.

app level build.gradle

plugins {
    ...
    id "android.aop"
}

androidAopConfig {
    enabled true
    include "***.automation", "***.automation.core"
    exclude "kotlin.jvm", "kotlin.internal", "kotlinx.coroutines.internal", "kotlinx.coroutines.android"
    verifyLeafExtends true
    cutInfoJson false
    increment true
}

Module level build.gradle

plugins {
    ...
    id "android.aop"
}
dependencies {
    ....
    implementation("io.github.FlyJingFish.AndroidAop:android-aop-core:2.1.5")
    implementation("io.github.FlyJingFish.AndroidAop:android-aop-annotation:2.1.5")
    implementation("io.github.FlyJingFish.AndroidAop:android-aop-extra:2.1.5")
}

Inside the module MatchAll.kt

@AndroidAopMatchClassMethod(
    targetClassName = "***.automation.*",
    methodName = ["*"]
)
class MatchAll: MatchClassMethod {
    override fun invoke(joinPoint: ProceedJoinPoint, methodName: String): Any? {
        Log.e("MatchAll", "---->${joinPoint.targetClass}--${joinPoint.targetMethod.name}--${joinPoint.targetMethod.parameterTypes.toList()}");
        return joinPoint.proceed()
    }
}

I have also tried using @CustomInterceptor, but that’s not working either. Additionally, I’m facing some configuration issues with ksp.

Error Log

Exception thrown during onBeforeAll invocation of plugin com.google.testing.platform.plugin.android.AndroidDevicePlugin.
Failed to install APK(s): ***.apk
INSTALL_FAILED_INVALID_APK: Scanning Failed.: Package ***/base.apk code is missing
com.android.ddmlib.InstallException: INSTALL_FAILED_INVALID_APK: Scanning Failed.: Package ***/base.apk code is missing
        at com.android.ddmlib.internal.DeviceImpl.installRemotePackage(DeviceImpl.java:1373)
        at com.android.ddmlib.internal.DeviceImpl.installPackage(DeviceImpl.java:1199)
        at com.android.tools.utp.plugins.deviceprovider.ddmlib.DdmlibAndroidDevice.installPackage(DdmlibAndroidDevice.kt)
        at com.android.tools.utp.plugins.deviceprovider.ddmlib.DdmlibAndroidDeviceController$executeAsync$deferred$1.invokeSuspend(DdmlibAndroidDeviceController.kt:180)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

Library version number: AndroidAOP: 2.1.5

------------------------------------------------------------
Gradle 7.6
------------------------------------------------------------

Build time:   2022-11-25 13:35:10 UTC
Revision:     daece9dbc5b79370cc8e4fd6fe4b2cd400e150a8

Kotlin:       1.7.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.16.1 (Microsoft 11.0.16.1+1-LTS)
OS:           Mac OS X 14.1 aarch64

Computer Type: Mac

FlyJingFish commented 1 day ago

If it is convenient for you, please provide a test code that can reproduce this problem and describe your operation steps in detail. This will help me locate the problem quickly.

nanthakumaran-s commented 1 day ago

I’ve been setting up the tests, though there are only a few empty test cases at the moment. Also, after moving the androidAopConfig inside the module's build.gradle, the errors stopped appearing, but I'm still unable to log any messages using the aspect.

FlyJingFish commented 1 day ago

* cannot be used before a package name and can only appear once, for example com.test.*. The same applies to include and exclude

nanthakumaran-s commented 1 day ago

I’ve tried removing the configurations as it is optional as you mentioned, and now the app is successfully installed. However, the AOP logging is still not working correctly.

nanthakumaran-s commented 1 day ago

It’s also strange that whenever I include id("android.aop") in the app-level module, the application fails to install on the emulator.

nanthakumaran-s commented 1 day ago

* cannot be used before a package name and can only appear once, for example com.test.*. The same applies to include and exclude

I included the package name to conceal the actual one, but it has the correct package in reality. For discussion purposes, we can use com.example.

FlyJingFish commented 1 day ago

I have something to do today, so I can test it on the simulator tomorrow to see if I can reproduce this problem. If you are in a hurry, you can prepare a demo that can reproduce this problem for me before I reply to you.

FlyJingFish commented 1 day ago

I have tested a simple AndroidTest on the emulator and found no problems. If you want me to help you solve the problem, please provide a demo project code that can reproduce the problem. If you can't provide it, I will close this issue later.