You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Annotated code: Empty Activity with @EActivity annotation
Actual generated code: Looks correct, no issues here.
We want to use AndroidAnnotation generated classes in tests (unit/instrumentation) but since Kotlin 1.1.3 this does not work anymore. Tests implemented in Java instead of Kotlin work fine however.
Easiest way to reproduce (unit test):
Kotlin app project with AndroidAnnotations
enhance an activity with annotation @EActivity
write Kotlin unit test which creates an AndroidAnnotation generated activity instance (ExampleActivity_) and call setContentView(null)
expected is a stacktrace which contains information about AndroidAnnotation generated activity class
result is stacktrace with direct call to base class (skipping the generated one)
Other way to reproduce (instrumentation test):
This issue occurs also within Espresso tests. Espresso test references generated class, but it uses the base activity during runtime.
java.lang.RuntimeException: Could not launch activity
at android.support.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:430)
at android.support.test.rule.ActivityTestRule.launchActivity(ActivityTestRule.java:332)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:431)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
...
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)
Caused by: java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.company.myapp/.ui.MyActivity }
at android.app.Instrumentation.startActivitySync(Instrumentation.java:396)
at android.support.test.runner.MonitoringInstrumentation.access$101(MonitoringInstrumentation.java:96)
at android.support.test.runner.MonitoringInstrumentation$4.call(MonitoringInstrumentation.java:410)
at android.support.test.runner.MonitoringInstrumentation$4.call(MonitoringInstrumentation.java:407)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
...
Already tried:
use different Kotlin versions
with all Kotlin 1.1.2-* versions its works fine, with 1.1.3 this issue occurs
with Kotlin 1.1.51 the issue still exists
tools like dbflow looks working (possible not comparable)
I am afraid this is out of of the processor's reach, we cannot really do anything about this. But you can share the example project so we can take a look.
There are also other libraries included where I can access the generated classes in Kotlin based tests without any issue. Also the Java based tests work without any issue.
@nenick i checked your project, it is really strange... For some reason MainActivity_::class returns the Kotlin class for MainActivity. But this is only happening in the instrumented test, not in the app. It is also happening in the unit test. You should report this error in the upstream project (i am not sure which), because we cannot do anything from AA-side. :(
@WonderCsabo do you know why all classes generated by AndroidAnnotations have the @Metadata(...) annotation? When i remove this annotation from generated classes then tests work fine.
This line effects which class is loaded "Lde/nenick/example/MainActivity;",
tests load the correct class when it gets changed to "Lde/nenick/example/MainActivity_;",
Edit: @Metadata(...) is only added when enhanced class is written in kotlin. What works is to write an abstract enhanced kotlin class and extend it by an enhanced java class. But this results in uggly boilerplate code.
I just got feedback and it seems that after all this is an issue within android annotations as we copy annotations from the enhanced class and those include the kotlin.Metadata.
Activity
WonderCsabo commentedon Nov 18, 2017
I am afraid this is out of of the processor's reach, we cannot really do anything about this. But you can share the example project so we can take a look.
nenick commentedon Nov 19, 2017
Here is an example project which shows the issue https://github.com/nenick/android-kotlin-androidannotations
There are also other libraries included where I can access the generated classes in Kotlin based tests without any issue. Also the Java based tests work without any issue.
Really strange behaviour I hope you have an idea.
WonderCsabo commentedon Nov 29, 2017
@nenick i checked your project, it is really strange... For some reason
MainActivity_::classreturns the Kotlin class forMainActivity. But this is only happening in the instrumented test, not in the app. It is also happening in the unit test. You should report this error in the upstream project (i am not sure which), because we cannot do anything from AA-side. :(nenick commentedon Dec 9, 2017
@WonderCsabo do you know why all classes generated by AndroidAnnotations have the
@Metadata(...)annotation? When i remove this annotation from generated classes then tests work fine.This line effects which class is loaded
"Lde/nenick/example/MainActivity;",tests load the correct class when it gets changed to
"Lde/nenick/example/MainActivity_;",Edit:
@Metadata(...)is only added when enhanced class is written in kotlin. What works is to write an abstract enhanced kotlin class and extend it by an enhanced java class. But this results in uggly boilerplate code.nenick commentedon Jan 22, 2018
I found temporal acceptable workaround
saschak42 commentedon Mar 6, 2018
Same issue here. @nenick your workaround is working, thank you! When will there be an official fix for that?
adammach commentedon Aug 10, 2018
Where in structure of gradle should I put this "fix"? Thanks.
saschak42 commentedon Aug 10, 2018
You can put it simply at the end of the build.gradle file.
adammach commentedon Aug 10, 2018
Ok. kapt[buildVariant]Kotlin fixed the problem.
dodgex commentedon Oct 14, 2018
I have opened a ticket in kotlin issue tracker: https://youtrack.jetbrains.com/issue/KT-27571
please vote for it and hope they'll fix this soon :)
dodgex commentedon Oct 18, 2018
I just got feedback and it seems that after all this is an issue within android annotations as we copy annotations from the enhanced class and those include the
kotlin.Metadata.I'll prepare a PR to fix this.
WonderCsabo commentedon Oct 20, 2018
Finally fixed, thanks @dodgex!