On 12/7/20 1:28 PM, Peter via Kawa wrote:
> foo.scm:3:17: warning - type android.app.Activity is incompatible with required type android.view.View
> foo.scm:3:46: warning - type android.content.Context is incompatible with required type android.view.View
>
> I don't understand either of these.. The single parameter to the
> constructor on line 3 (android.widget.LinearLayout) is a Context, as it
> should be.. why does kawa want a *View* here?
>
> Also, where does the Activity come from at all? I don't mention it
> anywhere, why does kawa *want* an Activity here?
>
> Thanks for any help with this :-/
Short answer:
The simplest fix is probably to remove
(require 'android-defs)
and add whatever aliases you need.
Long answer:
The android-defs import defines some "magic" features, and it would not
shock me if they no longer work with modern Android/Kawa/JDK.
I have not worked on or even tested the Android code in quite a while.
One of the things android-defs (gnu/kawa/android/defs.scm") does
is "sugar" the constructors of classes (such as LinearLayout) that extend View.
The idea was that the code to build a nested View object would be nested
in the same way as the View nesting.
From what I can figure out, in old versions of Android a View constructor
would take an Activity initial argument. This argument was conceptually redundant,
since the current Activity was redundant. The magic provided by android-defs
was to provide the Activity argument automatically.
See:
https://www.gnu.org/software/kawa/Android-view-construction.html#View-object-allocation
https://www.gnu.org/software/kawa/Allocating-objects.html
This code in defs.scm:
(define-constant {gnu.kawa.reflect/ObjectBuilder}:android.view.View
"gnu.kawa.android.ViewBuilder")
is to "customize" the object constructors for Android View objects,
using the ViewBuilder class (which is run at compile-time).
ViewBuilder is a sub-class of the generic ComplileBuildObject class,
which implements the general compile-time transformation described in:
https://www.gnu.org/software/kawa/Allocating-objects.html
CompileBuildObject has some "hooks" to customize this re-writing,
and those hooks are used by gnu.kawa.android.ViewBuilder.
I don't believe there is any documentation (except the code) for
how CompileBuildObject can be customized.
My guess is the Android View API at some point was changed so
the initial constructor argument was generalized from Activity to Context,
and this broke the logic in ViewBuilder.scm. It's probably fixable without
too much effort, but I'm unlikely to do so. Maybe a volunteer wants to
figure it out?
--
--Per Bothner
per@bothner.com http://per.bothner.com/