Lifecycle annotations seem to have wrong annotation javaName
See original GitHub issueHello there,
It seems that the [Lifecycle.Event.OnStart]
, [Lifecycle.Event.OnStop]
and other from the AndroidX.Lifecycle
namespace have their java annotation counterparts set to the old libraries.
Found this while testing the migration in the Toggl app, we are using the old [Lifecycle.Event.OnStart]
, [Lifecycle.Event.OnStop]
here:
https://github.com/toggl/mobileapp/blob/d79af0ab5522a325046baf19b4616cb086b1bc71/Toggl.Droid/Startup/TogglApplication.cs#L83-L99
Test branch: https://github.com/toggl/mobileapp/tree/doivid/androidx-migration-test
After migrating, we get this error while building:
TogglApplication.java(34, 25): error: package android.arch.lifecycle does not exist
@android.arch.lifecycle.OnLifecycleEvent(android.arch.lifecycle.Lifecycle.Event.ON_START)
TogglApplication.java(43, 25): error: package android.arch.lifecycle does not exist
@android.arch.lifecycle.OnLifecycleEvent(android.arch.lifecycle.Lifecycle.Event.ON_STOP)
Checking the generated source code, I found this:
namespace AndroidX.Lifecycle
{
[Register("androidx/lifecycle/Lifecycle", DoNotGenerateAcw = true)]
public abstract class Lifecycle : Java.Lang.Object
{
...
[Register("androidx/lifecycle/Lifecycle$Event", DoNotGenerateAcw = true)]
public sealed class Event : Java.Lang.Enum
{
internal new static readonly JniPeerMembers _members = (JniPeerMembers) new XAPeerMembers("androidx/lifecycle/Lifecycle$Event", typeof (AndroidX.Lifecycle.Lifecycle.Event));
[Register("ON_ANY")]
public static AndroidX.Lifecycle.Lifecycle.Event OnAny
{
get
{
return Java.Lang.Object.GetObject<AndroidX.Lifecycle.Lifecycle.Event>(AndroidX.Lifecycle.Lifecycle.Event._members.StaticFields.GetObjectValue("ON_ANY.Landroidx/lifecycle/Lifecycle$Event;").Handle, JniHandleOwnership.TransferLocalRef);
}
}
[Register("ON_CREATE")]
public static AndroidX.Lifecycle.Lifecycle.Event OnCreate
{
get
{
return Java.Lang.Object.GetObject<AndroidX.Lifecycle.Lifecycle.Event>(AndroidX.Lifecycle.Lifecycle.Event._members.StaticFields.GetObjectValue("ON_CREATE.Landroidx/lifecycle/Lifecycle$Event;").Handle, JniHandleOwnership.TransferLocalRef);
}
}
[Register("ON_DESTROY")]
public static AndroidX.Lifecycle.Lifecycle.Event OnDestroy
{
get
{
return Java.Lang.Object.GetObject<AndroidX.Lifecycle.Lifecycle.Event>(AndroidX.Lifecycle.Lifecycle.Event._members.StaticFields.GetObjectValue("ON_DESTROY.Landroidx/lifecycle/Lifecycle$Event;").Handle, JniHandleOwnership.TransferLocalRef);
}
}
[Register("ON_PAUSE")]
public static AndroidX.Lifecycle.Lifecycle.Event OnPause
{
get
{
return Java.Lang.Object.GetObject<AndroidX.Lifecycle.Lifecycle.Event>(AndroidX.Lifecycle.Lifecycle.Event._members.StaticFields.GetObjectValue("ON_PAUSE.Landroidx/lifecycle/Lifecycle$Event;").Handle, JniHandleOwnership.TransferLocalRef);
}
}
[Register("ON_RESUME")]
public static AndroidX.Lifecycle.Lifecycle.Event OnResume
{
get
{
return Java.Lang.Object.GetObject<AndroidX.Lifecycle.Lifecycle.Event>(AndroidX.Lifecycle.Lifecycle.Event._members.StaticFields.GetObjectValue("ON_RESUME.Landroidx/lifecycle/Lifecycle$Event;").Handle, JniHandleOwnership.TransferLocalRef);
}
}
[Register("ON_START")]
public static AndroidX.Lifecycle.Lifecycle.Event OnStart
{
get
{
return Java.Lang.Object.GetObject<AndroidX.Lifecycle.Lifecycle.Event>(AndroidX.Lifecycle.Lifecycle.Event._members.StaticFields.GetObjectValue("ON_START.Landroidx/lifecycle/Lifecycle$Event;").Handle, JniHandleOwnership.TransferLocalRef);
}
}
[Register("ON_STOP")]
public static AndroidX.Lifecycle.Lifecycle.Event OnStop
{
get
{
return Java.Lang.Object.GetObject<AndroidX.Lifecycle.Lifecycle.Event>(AndroidX.Lifecycle.Lifecycle.Event._members.StaticFields.GetObjectValue("ON_STOP.Landroidx/lifecycle/Lifecycle$Event;").Handle, JniHandleOwnership.TransferLocalRef);
}
}
internal new static IntPtr class_ref
{
get
{
return AndroidX.Lifecycle.Lifecycle.Event._members.JniPeerType.PeerReference.Handle;
}
}
public override JniPeerMembers JniPeerMembers
{
get
{
return AndroidX.Lifecycle.Lifecycle.Event._members;
}
}
protected override IntPtr ThresholdClass
{
get
{
return AndroidX.Lifecycle.Lifecycle.Event._members.JniPeerType.PeerReference.Handle;
}
}
protected override System.Type ThresholdType
{
get
{
return AndroidX.Lifecycle.Lifecycle.Event._members.ManagedPeerType;
}
}
internal Event(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
[Register("valueOf", "(Ljava/lang/String;)Landroidx/lifecycle/Lifecycle$Event;", "")]
public static unsafe AndroidX.Lifecycle.Lifecycle.Event ValueOf(string name)
{
IntPtr jobject = JNIEnv.NewString(name);
try
{
JniArgumentValue* parameters = stackalloc JniArgumentValue[1];
parameters[0] = new JniArgumentValue(jobject);
return Java.Lang.Object.GetObject<AndroidX.Lifecycle.Lifecycle.Event>(AndroidX.Lifecycle.Lifecycle.Event._members.StaticMethods.InvokeObjectMethod("valueOf.(Ljava/lang/String;)Landroidx/lifecycle/Lifecycle$Event;", parameters).Handle, JniHandleOwnership.TransferLocalRef);
}
finally
{
JNIEnv.DeleteLocalRef(jobject);
}
}
[Register("values", "()[Landroidx/lifecycle/Lifecycle$Event;", "")]
public static unsafe AndroidX.Lifecycle.Lifecycle.Event[] Values()
{
return (AndroidX.Lifecycle.Lifecycle.Event[]) JNIEnv.GetArray(AndroidX.Lifecycle.Lifecycle.Event._members.StaticMethods.InvokeObjectMethod("values.()[Landroidx/lifecycle/Lifecycle$Event;", (JniArgumentValue*) null).Handle, JniHandleOwnership.TransferLocalRef, typeof (AndroidX.Lifecycle.Lifecycle.Event));
}
>>>>>> This package is from the old lib, right? <<<<<<<<<
[Annotation("android.arch.lifecycle.OnLifecycleEvent(android.arch.lifecycle.Lifecycle.Event.ON_CREATE)")]
public class OnCreateAttribute : Attribute
{
}
>>>>>> This package is from the old lib, right? <<<<<<<<<
[Annotation("android.arch.lifecycle.OnLifecycleEvent(android.arch.lifecycle.Lifecycle.Event.ON_START)")]
public class OnStartAttribute : Attribute
{
}
>>>>>> This package is from the old lib, right? <<<<<<<<<
[Annotation("android.arch.lifecycle.OnLifecycleEvent(android.arch.lifecycle.Lifecycle.Event.ON_RESUME)")]
public class OnResumeAttribute : Attribute
{
}
>>>>>> This package is from the old lib, right? <<<<<<<<<
[Annotation("android.arch.lifecycle.OnLifecycleEvent(android.arch.lifecycle.Lifecycle.Event.ON_PAUSE)")]
public class OnPauseAttribute : Attribute
{
}
>>>>>> This package is from the old lib, right? <<<<<<<<<
[Annotation("android.arch.lifecycle.OnLifecycleEvent(android.arch.lifecycle.Lifecycle.Event.ON_STOP)")]
public class OnStopAttribute : Attribute
{
}
>>>>>> This package is from the old lib, right? <<<<<<<<<
[Annotation("android.arch.lifecycle.OnLifecycleEvent(android.arch.lifecycle.Lifecycle.Event.ON_DESTROY)")]
public class OnDestroyAttribute : Attribute
{
}
>>>>>> This package is from the old lib, right? <<<<<<<<<
[Annotation("android.arch.lifecycle.OnLifecycleEvent(android.arch.lifecycle.Lifecycle.Event.ON_ANY)")]
public class OnAnyAttribute : Attribute
{
}
}
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
@CustomTestApplication value cannot be annotated with ...
And so I get this error: java.lang.IllegalStateException: Hilt test, MainTest, cannot use a @HiltAndroidApp application but found MyApplication.
Read more >Which lifecycle for a Java annotation that generates ...
Annotations are processed by the Java compiler directly. For Maven, one can use the maven-compiler-plugin . It is also possible to perform ...
Read more >Data modeling annotations - Documentation
Enables objects of the target class to be exported to a custom package identified by the value element. This annotation is used in...
Read more >Core Technologies
Java configuration typically uses @Bean -annotated methods within a @Configuration class. These bean definitions correspond to the actual ...
Read more >Core Features
An application is considered live as soon as the context has been refreshed, see Spring Boot application lifecycle and related Application Events.
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
Fixed. Tagging for new preview!
I believe this is fixed and released in preview. If you still have problems with this, please open a new issue.