Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nanthakumaran-s opened this issue Sep 17, 2024 · 8 comments
Labels
无效问题 This doesn't seem right

Comments

@nanthakumaran-s
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

* 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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

* 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
Copy link
Owner

FlyJingFish commented Sep 17, 2024

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
Copy link
Owner

FlyJingFish commented Sep 18, 2024

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.

@FlyJingFish FlyJingFish added the 无效问题 This doesn't seem right label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
无效问题 This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants