with AGP 4.2.x, 7.0.0 / java.lang.IllegalAccessError: Method 'boolean[] com.sebiya.myapplication.ktx.LiveDataExtKt.$jacocoInit()' is inaccessible to class 'com.sebiya.myapplication.ktx.LiveDataExtTest$test$1' during instrumentation test
See original GitHub issueVersions
- Hilt: 2.38.1
- AGP: 4.2.x, 7.0.0
- Gradle: 7.0.2-all
I’ve got below exception during android instrumentation test with hilt
--------- beginning of main
08-10 11:05:58.239 10364 25204 25237 E TestRunner: failed: test(com.sebiya.myapplication.ktx.LiveDataExtTest)
08-10 11:05:58.239 10364 25204 25237 E TestRunner: ----- begin exception -----
08-10 11:05:58.240 10364 25204 25237 E TestRunner: java.lang.IllegalAccessError: Method 'boolean[] com.sebiya.myapplication.ktx.LiveDataExtKt.$jacocoInit()' is inaccessible to class 'com.sebiya.myapplication.ktx.LiveDataExtTest$test$1' (declaration of 'com.sebiya.myapplication.ktx.LiveDataExtTest$test$1' appears in /data/app/com.sebiya.myapplication.test-M9bh20Enr1T3hIa4Y5a1tA==/base.apk!classes4.dex)
08-10 11:05:58.240 10364 25204 25237 E TestRunner: at com.sebiya.myapplication.ktx.LiveDataExtTest$test$1.invokeSuspend(LiveDataExtTest.kt:11)
08-10 11:05:58.240 10364 25204 25237 E TestRunner: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
08-10 11:05:58.240 10364 25204 25237 E TestRunner: at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
08-10 11:05:58.240 10364 25204 25237 E TestRunner: at android.os.Handler.handleCallback(Handler.java:883)
08-10 11:05:58.240 10364 25204 25237 E TestRunner: at android.os.Handler.dispatchMessage(Handler.java:100)
08-10 11:05:58.240 10364 25204 25237 E TestRunner: at android.os.Looper.loop(Looper.java:237)
08-10 11:05:58.240 10364 25204 25237 E TestRunner: at android.app.ActivityThread.main(ActivityThread.java:8167)
08-10 11:05:58.240 10364 25204 25237 E TestRunner: at java.lang.reflect.Method.invoke(Native Method)
08-10 11:05:58.240 10364 25204 25237 E TestRunner: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
08-10 11:05:58.240 10364 25204 25237 E TestRunner: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
08-10 11:05:58.240 10364 25204 25237 E TestRunner: ----- end exception -----
08-10 11:05:58.241 10364 25204 25237 I TestRunner: finished: test(com.sebiya.myapplication.ktx.LiveDataExtTest)
java.lang.IllegalAccessError: Method 'boolean[] com.sebiya.myapplication.ktx.LiveDataExtKt.$jacocoInit()' is inaccessible to class 'com.sebiya.myapplication.ktx.LiveDataExtTest$test$1' (declaration of 'com.sebiya.myapplication.ktx.LiveDataExtTest$test$1' appears in /data/app/com.sebiya.myapplication.test-M9bh20Enr1T3hIa4Y5a1tA==/base.apk!classes4.dex)
at com.sebiya.myapplication.ktx.LiveDataExtTest$test$1.invokeSuspend(LiveDataExtTest.kt:11)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
it seems to happen when using an inline function in test target package.
app module code (test target package)
LiveDataExt.kt
inline fun <T> LiveData<T>.filter(crossinline predicate: (T) -> Boolean): LiveData<T> {
return MediatorLiveData<T>().apply {
addSource(this@filter) {
if (predicate(it)) {
value = it
}
}
}
}
app module test (test package)
LiveDataExtTest.kt
class LiveDataExtTest {
@Test
fun test() = runBlocking(Dispatchers.Main) {
MutableLiveData("test").filter { it != null }.observeForever {
Log.d("test", it)
}
}
}
An exception is not thrown when testing with the following combinations.
- agp 4.1.0 + hilt 2.38.1
- agp 7.0.0 + hilt 2.29-alpha
you can reproduce issue with below repository https://github.com/kshdreams/agp_hilt_jacoco_runtime_issue
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
IllegalAccessError: Method is inaccessible to class
When I try to run the app through IDE, it works fine. java.lang.IllegalAccessError: Method 'int <package>.BaseActivity$Companion.
Read more >AGP 7.0.0 does not create unit test jacoco exec files correctly ...
1 for instrumentation tests. The issue is not observed using AGP 4.1.3. The generated coverage.ec file's size is 0B. After adding the --debug...
Read more >Android Studio 2021.1.1 Closed Issues
plist within macOS Application has incorrect file permissions. Gradle Files Editor. Issue #197553058. Bug: IDE suggests to update to a androidx.
Read more >AGP 7.0: Next major release for the Android Gradle plugin
With this release we are adjusting the version numbering for our Gradle plugin and decoupling it from the Android Studio versioning scheme. In...
Read more >Gradle 7.0 Release Notes
A version catalog enables build authors to centralize the dependency coordinates (group, artifact, version) of their third party dependencies in a conventional ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The reason why the issue is not in 2.29-alpha or when AGP 4.1.0 is used, is because it was not until Hilt 2.31 that Hilt migrated to using the newer ASM transform that is available in AGP 4.2.0.
Looks like the tools team filled a new bug for this: https://issuetracker.google.com/197065758, hopefully a fix for this will be available soon.
Will close this one out since the fix is in AGP and there is no code change for us.