Commit ed63d89
authored
[generator] restore
Fixes: dotnet/android#8337
A customer's app with the code:
SetContentView(Resource.Layout.activity_main);
FindViewById<Button>(Resource.Id.asd).Click += MainActivity_Click;
Crashes with `-c Release -p:AndroidLinkMode=r8` with:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.companyname.New_folder/crc64abe8cc9139195b67.MainActivity}: java.lang.ClassNotFoundException: android.view.View_IOnClickListenerImplementor
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3644)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3781)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2306)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7918)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.ClassNotFoundException: android.view.View_IOnClickListenerImplementor
at crc64abe8cc9139195b67.MainActivity.n_onCreate(Native Method)
at crc64abe8cc9139195b67.MainActivity.onCreate(MainActivity.java:30)
at android.app.Activity.performCreate(Activity.java:8342)
at android.app.Activity.performCreate(Activity.java:8321)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3625)
... 12 more
Which, can be solved by adding your own `proguard` rules like:
-keep class android.view.View_IOnClickListenerImplementor { *; }
In a91ae7f, we thought (incorrectly):
> Additionally, stop emitting the `[Register]` attribute for
> `*Implementor` classes:
>
> [global::Android.Runtime.Register ("mono/android/view/View_OnFocusChangeListenerImplementor")]
> partial class IOnFocusChangeListenerImplementor {/* … */}
>
> The `[Register]` attribute is not needed, because `*Implementor`
> classes are generated internal implementation details.
`proguard_xamarin.cfg` has the entry:
-keep class mono.android.** { *; <init>(...); }
We could do `-keep class android.**` [^0], but that would certainly
preserve way too much!
For now, let's just restore `[Register]` to revisit this issue at a
later date -- maybe .NET 9?
[^0]: Why is `View_IOnClickListenerImplementor` in the `android.view`
package?! Because package name generation for Java Callable
Wrappers is special-cased for `Mono.Android` to simply
[lowercase the namespace name][0], which applies only if the
type *doesn't* have `[RegisterAttribute]`!
[0]: https://github.com/xamarin/java.interop/blob/8e63cc8da1882cadc7db329bfa6cafb6f914769f/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs#L200-L209[RegisterAttribute] for *Implementor types (#1149)1 parent 8e63cc8 commit ed63d89
File tree
6 files changed
+6
-0
lines changed- tests/generator-Tests
- Unit-Tests/CodeGeneratorExpectedResults
- Common
- JavaInterop1
- XAJavaInterop1
- expected.xaji
- Core_Jar2Xml
- GenericArguments
- tools/generator/SourceWriters
6 files changed
+6
-0
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| 160 | + | |
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| 160 | + | |
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
165 | 166 | | |
166 | 167 | | |
167 | 168 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
0 commit comments