Post

Generate Java bindings for libappindicator - reduced to the max

Introduction

Generating the Java bindings for libappindicator is straight forward, but produces a jar file, that is 9,6M big. That’s quite a lot for a library.

It then contains bindings for the following shared libraries, that are referenced by libappindicator:

  • gtk-3.0
  • glib-2.0
  • cairo
  • gdk-pixbuf-2.0
  • pango-1.0
  • atk-1.0
  • harfbuzz

It can be questioned, whether all these are required to address libappindicator.

Reduce to the max

There is not much documentation around about libappindicator, so to answer the questions which methods and classes are definitely required when using libappindicator, I took a look at a wiki page about the library and into the libraries code, so see, which methods are included there and need to be available in the generated Java bindings too.

This led to a subset of methods and classes, that are specified on jextract execution. Note the --include-function and --include-typedef parameters below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
jextract --source \
	-t org.purejava.linux \
	-I /usr/include/gtk-3.0/ \
	-I /usr/include/glib-2.0/ \
	-I /usr/include/cairo/ \
	-I /usr/include/gdk-pixbuf-2.0/ \
	-I /usr/include/pango-1.0/ \
	-I /usr/include/atk-1.0/ \
	-I /usr/include/harfbuzz/ \
	-I /usr/lib/glib-2.0/include/ \
	--include-function app_indicator_build_menu_from_desktop \
	--include-function app_indicator_get_category \
	--include-function app_indicator_get_attention_icon \
	--include-function app_indicator_get_id \
	--include-function app_indicator_get_icon \
	--include-function app_indicator_get_label \
	--include-function app_indicator_get_menu \
	--include-function app_indicator_get_ordering_index \
	--include-function app_indicator_get_status \
	--include-function app_indicator_get_title \
	--include-function app_indicator_new \
	--include-function app_indicator_set_attention_icon \
	--include-function app_indicator_set_icon \
	--include-function app_indicator_set_label \
	--include-function app_indicator_set_menu \
	--include-function app_indicator_set_ordering_index \
	--include-function app_indicator_set_status \
	--include-function app_indicator_set_title \
	--include-function g_error_free \
	--include-function g_object_set_data_full \
	--include-function g_signal_connect_object \
	--include-function gtk_action_get_name \
	--include-function gtk_action_group_new \
	--include-function gtk_action_group_add_action \
	--include-function gtk_action_group_add_actions \
	--include-function gtk_container_add \
	--include-function gtk_init \
	--include-function gtk_main \
	--include-function gtk_menu_item_new \
	--include-function gtk_menu_item_set_label \
	--include-function gtk_menu_item_set_submenu \
	--include-function gtk_menu_new \
	--include-function gtk_menu_shell_append \
	--include-function gtk_message_dialog_new \
	--include-function gtk_scrolled_window_new \
	--include-function gtk_scrolled_window_set_policy \
	--include-function gtk_scrolled_window_set_shadow_type \
	--include-function gtk_statusbar_new \
	--include-function gtk_table_new \
	--include-function gtk_table_attach \
	--include-function gtk_text_view_new \
	--include-function gtk_widget_destroy \
	--include-function gtk_widget_destroyed \
	--include-function gtk_widget_grab_focus \
	--include-function gtk_widget_show \
	--include-function gtk_widget_show_all \
	--include-function gtk_window_add_accel_group \
	--include-function gtk_window_new \
	--include-function gtk_window_set_default_size \
	--include-function gtk_window_set_icon \
	--include-function gtk_window_set_icon_name \
	--include-function gtk_window_set_title \
	--include-function gtk_ui_manager_add_ui \
	--include-function gtk_ui_manager_add_ui_from_string \
	--include-function gtk_ui_manager_get_accel_group \
	--include-function gtk_ui_manager_get_widget \
	--include-function gtk_ui_manager_insert_action_group \
	--include-function gtk_ui_manager_new \
	--include-typedef GCallback \
	/usr/include/libappindicator3-0.1/libappindicator/app-indicator.h

The newly generated jar file has a size of 31K.

This post is licensed under CC BY 4.0 by the author.

Trending Tags