go wails3 android learn notes
·
wails 3 android slop, change source code of wails v3 stuff
$ GOOS=android GOARCH=arm64 go build -buildmode=c-shared -tags android,debug -buildvcs=false -gcflags=all="-l"
# github.com/wailsapp/wails/v3/pkg/application
../../../go/pkg/mod/github.com/wailsapp/wails/v3@v3.0.0-alpha.74/pkg/application/events_common_android.go:9:9: undefined: events.Android
../../../go/pkg/mod/github.com/wailsapp/wails/v3@v3.0.0-alpha.74/pkg/application/messageprocessor.go:199:16: undefined: iosMethodNames
../../../go/pkg/mod/github.com/wailsapp/wails/v3@v3.0.0-alpha.74/pkg/application/application_android.go:436:17: not enough arguments in call to runtime.Core
have ()
want (map[string]any)
- …/…/…/go/pkg/mod/github.com/wailsapp/wails/v3@v3.0.0-alpha.74/pkg/application/events_common_android.go
//go:build android
package application
import "github.com/wailsapp/wails/v3/pkg/events"
// Map platform events → common events (same pattern as macOS & others)
//var commonApplicationEventMap = map[events.ApplicationEventType]events.ApplicationEventType{
// //events.Android.ActivityCreated: //events.Common.ApplicationStarted,
//}
var commonApplicationEventMap = map[events.ApplicationEventType]events.ApplicationEventType{}
// setupCommonEvents forwards Android platform events to their common counterparts
func (a *androidApp) setupCommonEvents() {
for sourceEvent, targetEvent := range commonApplicationEventMap {
sourceEvent := sourceEvent
targetEvent := targetEvent
a.parent.Event.OnApplicationEvent(sourceEvent, func(event *ApplicationEvent) {
event.Id = uint(targetEvent)
androidLogf("info", "[events_common_android.go] Forwarding Android event %d → common %d", sourceEvent, targetEvent)
applicationEvents <- event
})
}
}
- …/…/…/go/pkg/mod/github.com/wailsapp/wails/v3@v3.0.0-alpha.74/pkg/application/messageprocessor.go
func (m *MessageProcessor) logRuntimeCall(req *RuntimeRequest) {
objectName := objectNames[req.Object]
methodName := ""
switch req.Object {
case callRequest:
return // logs done separately in call processor
case clipboardRequest:
methodName = clipboardMethods[req.Method]
case applicationRequest:
methodName = applicationMethodNames[req.Method]
case eventsRequest:
methodName = eventsMethodNames[req.Method]
case contextMenuRequest:
methodName = contextmenuMethodNames[req.Method]
case dialogRequest:
methodName = dialogMethodNames[req.Method]
case windowRequest:
methodName = windowMethodNames[req.Method]
case screensRequest:
methodName = screensMethodNames[req.Method]
case systemRequest:
methodName = systemMethodNames[req.Method]
case browserRequest:
methodName = browserMethodNames[req.Method]
case cancelCallRequest:
methodName = "Cancel"
case iosRequest:
//methodName = iosMethodNames[req.Method]
case androidRequest:
methodName = androidMethodNames[req.Method]
}
m.Debug("Runtime call:", "method", objectName+"."+methodName, "args", req.Args.String())
}
- …/…/…/go/pkg/mod/github.com/wailsapp/wails/v3@v3.0.0-alpha.74/pkg/application/application_android.go
//export Java_com_wails_app_WailsBridge_nativeOnPageFinished
func Java_com_wails_app_WailsBridge_nativeOnPageFinished(env *C.JNIEnv, obj C.jobject, jurl C.jstring) {
cUrl := C.jstringToC(env, jurl)
defer C.releaseJString(env, jurl, cUrl)
url := C.GoString(cUrl)
androidLogf("info", " [JNI] nativeOnPageFinished called: %s", url)
globalAppLock.RLock()
app := globalApp
globalAppLock.RUnlock()
if app == nil {
androidLogf("error", " [JNI] nativeOnPageFinished: app is nil")
return
}
// Inject the runtime into the first window (with proper locking)
app.windowsLock.RLock()
windowCount := len(app.windows)
androidLogf("info", " [JNI] nativeOnPageFinished: window count = %d", windowCount)
for id, win := range app.windows {
androidLogf("info", " [JNI] Found window ID: %d", id)
if win != nil {
androidLogf("info", " [JNI] Injecting runtime.Core() into window %d", id)
// Get the runtime core JavaScript
//runtimeJS := runtime.Core()
//androidLogf("info", " [JNI] Runtime JS length: %d bytes", len(runtimeJS))
app.windowsLock.RUnlock()
// IMPORTANT: We must bypass win.ExecJS because it queues if runtimeLoaded is false.
// On Android, we need to inject the runtime directly since the runtime hasn't been loaded yet.
// This is the bootstrap injection that enables the runtime to load.
androidLogf("info", " [JNI] Calling executeJavaScript directly (bypassing queue)")
//executeJavaScript(runtimeJS)
// Emit event
app.Event.Emit("PageFinished", url)
return
}
}
app.windowsLock.RUnlock()
androidLogf("warn", " [JNI] nativeOnPageFinished: no windows found to inject runtime")
// Emit event even if no windows
app.Event.Emit("PageFinished", url)
}
and toolchain env variable setup for build libwails.so
export ANDROID_NDK=/home/etcix/Android/Sdk/ndk/29.0.13599879
export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64
export CGO_ENABLED=1
# [IMPORTANT] go cc compiler, don't use gcc
export CC=$TOOLCHAIN/bin/aarch64-linux-android29-clang
# I don't know below 3 line of code
export CGO_CC=$TOOLCHAIN/bin/aarch64-linux-android24-clang
export CGO_CFLAGS="-I$TOOLCHAIN/sysroot/usr/include -I$TOOLCHAIN/sysroot/usr/include/aarch64-linux-android"
export CGO_LDFLAGS="-L$TOOLCHAIN/sysroot/usr/lib/aarch64-linux-android/24 -llog"
# then next build libwails.so lib
GOOS=android GOARCH=arm64 go build -buildmode=c-shared -tags android,debug -buildvcs=false -gcflags=all="-l" -o libwails.so
here is android header include files output example
$ ls /home/etcix/Android/Sdk/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
aarch64-linux-android c++ errno.h GLES3 limits.h netdb.h resolv.h stdint.h termios.h video
aaudio camera error.h glob.h link.h netinet riscv64-linux-android stdio_ext.h threads.h vk_video
alloca.h complex.h execinfo.h grp.h linux netpacket sched.h stdio.h time64.h vulkan
amidi cpio.h fcntl.h i686-linux-android locale.h nl_types.h scsi stdlib.h time.h wait.h
android ctype.h features.h iconv.h malloc.h OMXAL search.h string.h uchar.h wchar.h
ar.h dirent.h fenv.h ifaddrs.h math.h paths.h semaphore.h strings.h uconfig_local.h wctype.h
arm-linux-androideabi dlfcn.h fnmatch.h inttypes.h media poll.h setjmp.h sys ucontext.h x86_64-linux-android
arpa drm fts.h jni.h memory.h pthread.h signal.h syscall.h unicode xen
asm-generic EGL ftw.h KHR misc pty.h SLES sysexits.h unistd.h xlocale.h
assert.h elf.h getopt.h langinfo.h mntent.h pwd.h sound syslog.h utime.h zconf.h
bits endian.h GLES lastlog.h mtd rdma spawn.h tar.h utmp.h zlib.h
byteswap.h err.h GLES2 libgen.h net regex.h stdatomic.h termio.h utmpx.h
android lib path example
$ ls /home/etcix/Android/Sdk/ndk/29.0.13599879/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/24
crtbegin_dynamic.o crtend_android.o libandroid.so libc++.so libEGL.so libGLESv3.so libmediandk.so libOpenSLES.so libz.so
crtbegin_so.o crtend_so.o libc++.a libc.so libGLESv1_CM.so libjnigraphics.so libm.so libstdc++.so
crtbegin_static.o crt_pad_segment.o libcamera2ndk.so libdl.so libGLESv2.so liblog.so libOpenMAXAL.so libvulkan.so
if want verbose build libwails.so or error log example
GOOS=android GOARCH=arm64 go build -v -x -a -buildmode=c-shared -tags android,debug -buildvcs=false -gcflags=all="-l" -o libwails.so
GOOS=android GOARCH=arm64 go build -buildmode=c-shared -tags android,debug -buildvcs=false -gcflags=all="-l" -o libwails.so 2&> error.log
ref links
- this note comes from lazydir: https://github.com/iercann/lazydir
more info
- actually I build out the libwails.so and copy to
$ pwd
/home/etcix/code/gotest/lazydir
$ ls build/android/app/src/main/jniLibs/arm64-v8a/libwails.so
build/android/app/src/main/jniLibs/arm64-v8a/libwails.so
- and build the android app and run it found error, see screenshots

- this experiment is fun even tought I failed, I really want to see wails 3 can handle android side now
footnote
- see wails repo issue #5020 and #5022, it maybe doc above error things
更多推荐


所有评论(0)