public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Problems with old kawa android code
@ 2020-12-07 21:28 Peter
  2020-12-08  1:22 ` Per Bothner
  0 siblings, 1 reply; 3+ messages in thread
From: Peter @ 2020-12-07 21:28 UTC (permalink / raw)
  To: kawa mailing list

Hello!

I have a bunch of old apps, that used to compile fine with kawa ~2.

Now I'm running into many problems :-/ One of them is as follows:

Code (foo.scm):

(require 'android-defs)
(define (bar (context :: android.content.Context))
  (let ((layout (android.widget.LinearLayout context)))
    layout))

Compile with:
CLASSPATH=/~/src/android/kawa/kawa.jar:/opt/android-sdk/platforms/android-14/android.jar java kawa.repl -d bin/classes -P at.nexoid. --module-static-run --warn-undefined-variable --warn-unknown-member --warn-invoke-unknown-method -C foo.scm

Output:
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 :-/

Greetings, Peter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Problems with old kawa android code
  2020-12-07 21:28 Problems with old kawa android code Peter
@ 2020-12-08  1:22 ` Per Bothner
  2020-12-08  9:10   ` Peter
  0 siblings, 1 reply; 3+ messages in thread
From: Per Bothner @ 2020-12-08  1:22 UTC (permalink / raw)
  To: Peter, kawa mailing list

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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Problems with old kawa android code
  2020-12-08  1:22 ` Per Bothner
@ 2020-12-08  9:10   ` Peter
  0 siblings, 0 replies; 3+ messages in thread
From: Peter @ 2020-12-08  9:10 UTC (permalink / raw)
  To: kawa mailing list

> Short answer:
> The simplest fix is probably to remove
>     (require 'android-defs)
> and add whatever aliases you need.

Thanks, this worked well!

I've run into another (probably unrelated to Android) problem:

I use an anonymous subclass of android.os.AsyncTask, which has a
function:

protected final void publishProgress (Progress... values)

If I just use publishProgress directly, kawa complains that no such slot
exists, but if I just define-simple-class the subclass (making it
non-anonymous), things work fine.

Is it possible that there's a bug with anonymous subclasses and
protected and/or final functions?

Thanks a lot for your help with this!

Greetings, Peter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-08  9:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-07 21:28 Problems with old kawa android code Peter
2020-12-08  1:22 ` Per Bothner
2020-12-08  9:10   ` Peter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).