Commit Graph

122 Commits

Author SHA1 Message Date
Ben Schwartz 8578da9835 all: modernize handling of Android SDK and NDK paths
This change removes Gomobile's dependency on ANDROID_HOME and
ANDROID_NDK_HOME.  Setting ANDROID_HOME is generally optional,
and ANDROID_NDK_HOME is deprecated.

This change also increases the minimum API version to 16, as
all SDKs that supported API 15 are now deprecated.

Fixes golang/go#52470

Change-Id: I546365774a089e5d7ae1be0a538efd72741d92ac
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/401574
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Daniel Skinner <daniel@dasa.cc>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-05-18 20:53:45 +00:00
Russ Cox ce6a79cf6a all: gofmt
Gofmt to update doc comments to the new formatting.

For golang/go#51082.

Change-Id: I9b4c287e2d25aa108adfa9fe2f972c8fd3d68fe1
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/399597
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
2022-04-14 15:34:00 +00:00
Hana (Hyang-Ah) Kim 447654d348 example/ivy: update robpike.io/ivy/mobile to 0.2.7
Change-Id: I0db9c1396f003eca30196aab14523d1cf7b85197
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/388375
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-25 16:17:04 +00:00
cuishuang 55113b94f0 mobile: fix some typos
Change-Id: Iaffde6f90b92b1f8b96c76d2bc3d8c312ebb764f
GitHub-Last-Rev: 7413e9537adc1626c76386cf2d47188eeed8342e
GitHub-Pull-Request: golang/mobile#76
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/390014
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-03-07 22:04:22 +00:00
Hana (Hyang-Ah) Kim 8a0a1e5073 example/ivy/android: update app version (1.4.0)
Add mavenCentral to repositories
needed to pull in necessary build tools dependencies

Change-Id: I9b8525430d4ba9535ad0d3bc6b4acd94f6ea0642
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/360835
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
2022-02-24 13:45:51 +00:00
Changkun Ou 1ab90197b3 example/ivy/ios: turn off quoted include warning from clang
Taking the same approach from the widely used CocoaPods who had facing
the same issue since Xcode 12. See discussion:
https://github.com/CocoaPods/CocoaPods/pull/9905

Fixes golang/go#48677

Change-Id: I92584e6cf87e34747db3ce32cda837d55e5f8b2c
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/369198
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-12-06 11:45:35 +00:00
Bryan C. Mills d61a72f26a example/ivy: add a "// +build" comment in tools.go
The modules in x/mobile are still tested under Go 1.16, which emits a
vet warning for files that have "//go:build" constraint comments
without matching "// +build" comments.

This fixes a build failure observed on the Go dashboard:
https://build.golang.org/log/2925343437d0c0559bcfa9d9de740a3a1aef2dc3

Change-Id: Ic0e3ed151a2ea3262d853c4e22cf042d54230ede
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/362575
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2021-11-09 19:11:25 +00:00
robaho e68c98865f example/ivy/ios: format code according to Google style guide
Change-Id: I4cef2b60756b3318c123b832bcdb719d2d45fadc
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/360607
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-11-03 15:16:57 +00:00
robaho 2ab7fee9df example/ivy/ios: enable return to continue demo
Change-Id: I189cd6b4953aeb988dfb1d28662f228508d463ff
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/360379
Reviewed-by: Rob Pike <r@golang.org>
Trust: Rob Pike <r@golang.org>
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-11-02 00:03:17 +00:00
robaho 170e11ba23 example/ivy/ios: enable demo functionality
And bring iOS app up to Android capabilities.

Fixes golang/go#48694

Change-Id: I0e853cab102e34053ecdb17edb99644aa2f8651a
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/357977
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Peter Weinberger <pjw@google.com>
2021-10-30 03:09:00 +00:00
Hana (Hyang-Ah) Kim 7b8bfe0993 example/ivy/android: remove prompt symbol
Now the user input is printed in bold, so it is obvious even with
out this dummy prompt-like symbol. This makes the output more like
the desktop version of Ivy tool.

Change-Id: I146685815ceb52aa5da6ddaa64f764e43839ffa9
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/356733
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
2021-10-29 12:31:40 +00:00
Hana (Hyang-Ah) Kim 93c5f8af85 example/ivy/android: fix demo to handle comments & 'quit' correctly
Demo feature is implemented by reading the demo.ivy file included
as an asset, read lines, and feed each line to mobile.Eval if it
is not a comment line. Comments can start from the middle of a line
so previously, the code simply looked for '#' in each line and
treated the substring starting from it as a comment. This assumption
is not correct - see ")format '%#x'". Without proper parsing, it is
hard to do it correctly. This CL passes the entire line to Ivy as
it is - the backend correctly parses the line with comments.
One drawback of this change is, unlike the line comments, we don't
apply the style for comments (gray font). But correctness is more
important. This also simplifies the code.

This CL implements the 'quit' command that terminates a demo
session (as mentioned in the demo.ivy script).

Change-Id: Ib0801338e0dd34c52c6c6209fe47a1846e71f0c8
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/356732
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
2021-10-29 12:31:31 +00:00
Hana (Hyang-Ah) Kim d263badac8 example/ivy/android: use escapeHtmlTags in ivy output processing
Android App emulates terminal-like functionality in WebView by
appending the input and output lines of Ivy to the WebView HTML
document as a new div entry using javascript. The app used
Android's TextUtils.htmlEncode to get HTML escaped representation
of the input and output. Among those escaped characters, `&` is
included (HTML entity prefix).

Ivy's mobile.Eval returns lines that include HTML entities (e.g.
&#92; instead of backslash -- see
https://github.com/robpike/ivy/blob/master/mobile/mobile.go#L43)
TextUtils.htmlEncode escapes this `&` and as a result, the backslash
is left broken.

escapeHtmlTags is identical to TextUtils.htmlEncode except it
leaves the entity alone.

Change-Id: Ifec401f07b46f4c6aee6d8df7d61933ae8dbc666
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/356731
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2021-10-28 16:12:33 +00:00
Hana (Hyang-Ah) Kim 3e409eeb21 example/ivy/android: use monospace & pre-wrap for WebView text formatting
Output from ivy is carefully formatted to work best in terminal.
Use of monospace & pre-wrap white space make table-format output look nicer.

Change-Id: If11fd57c8e685c01825fb1c2dd8b6d24fe860850
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/356730
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
Trust: Peter Weinberger <pjw@google.com>
2021-10-28 16:11:54 +00:00
Hana (Hyang-Ah) Kim eb3c0abee2 example/ivy: make ivy as a separate module, and update to use AndroidX
golang.org/x/mobile/example/ivy module specifies dependency on
golang.org/x/mobile and robpike.io/ivy versions.

- Updated to use AndroidX and target API level 30 to meet
the current Google Play policies
https://support.google.com/googleplay/android-developer/answer/9859152?visit_id=637402646062706504-1797308153&rd=1#targetsdk&zippy=%2Ctarget-api-level-requirements-for-play-console
- Updated demo.ivy script (copied from 66c48de6eb/demo/demo.ivy)
- Added example/ivy/android/README.md

Change-Id: Ie613ecdba4c3d77b5c45ef8a792fba6ee8a2c5cf
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/356729
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-10-27 13:47:44 +00:00
Randy Reddig b5eb1abba0 example: updates for XCFramework and Mac Catalyst
This updates examples for the changes in golang.org/cl/334689 for
.xcframework files and Mac Catalyst.

Depends on golang.org/cl/334689

https://go-review.googlesource.com/c/mobile/+/334689/28/example/bind/ios/README#1

Change-Id: Ice89e7e675c8f190c7040407908f619a7631fd2b
GitHub-Last-Rev: 64da8e6cad76f3e0530e36895bbfeacab7439b35
GitHub-Pull-Request: golang/mobile#72
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/350489
Reviewed-by: Changkun Ou <euryugasaki@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-22 14:22:29 +00:00
Changkun Ou 5d9a33257a example/ivy: make ivy work again
This CL allows a (super) outdated Xcode project - the Pob Pike's Ivy
work again and can compile and run on the latest iOS (tested on iOS 15
beta 8).

There are some changes to the project that might be worth mentioning:

- The UIWebView is deprecated in iOS 10, this CL migrates the code to
use the latest recommended WKWebView.
- The old project does not compatible with iOS 9 and later, the CL upgrades
the development target to iOS 14, and makes it compatible with all
all orientation (Portrait, landscape, upside down).
- The old Launch.storyboard is deprecated, the Main.storyboard cannot
be opened (will cause Xcode crash), this change slightly reworked on
the UI management, and merges the purpose of Launch.storyboard as well
as Main.storyboard into the single Main.storyboard.
- Injects a meta tag into the HTML header so that the fonts are properly
scaled on (very) high-resolution display.
- The app is not only tested on a simulator but also physically tested
on an iPhone 12 Pro.

See screenshots:

- iOS Home: https://changkun.de/midgard/img/ivy-ios-home.png
- iOS Help: https://changkun.de/midgard/img/ivy-ios-help.png
- Mac Home: https://changkun.de/midgard/img/ivy-mac-home.png
- Mac Help: https://changkun.de/midgard/img/ivy-mac-help.png

Change-Id: I1b8dec6b17d5722fddb1011453b3c8f86e4900e4
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/346949
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
2021-09-02 10:41:08 +00:00
Changkun Ou 80cb72e7af cmd/gomobile: use GOOS=ios for iOS builds
This change permits gomobile to build iOS applications by properly
set GOOS=ios in the build process. The change is locally tested on
darwin/arm64, and golang.org/x/mobile/example/basic can be build
using the following commands:

gomobile build -target=android -o=basic.apk \
golang.org/x/mobile/example/basic

gomobile build -target=ios -bundleid=org.golang.gomobiletest \
-o=basic.app golang.org/x/mobile/example/basic

The built binaries are also tested on iOS 15 beta7 and Android 12 API31.

Updates golang/go#47952
Fixes golang/go#47238

Change-Id: Ibf40a77933ac957640c78d0dbc1af043477e4b3a
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/346150
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-01 15:58:30 +00:00
Russ Cox bdb1ca9a1e all: go fmt ./...
Make all our package sources use Go 1.17 gofmt format
(adding //go:build lines).

Not strictly necessary but will avoid spurious changes
as files are edited.

Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

Change-Id: I30822eb504168b037ed3ec0f7759da1f41251f52
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/294374
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
2021-02-20 03:30:13 +00:00
Elias Naur 92f3b9caf7 misc,example/bind/hello: remove the Gradle plugin
And replace the plugin with instructions for rebuilding the .aar files
for the bind and ivy examples.

While here, fix a compile error in the Ivy example caused by gomobile
no longer prepending org.golang. to its generated Java packages by
default.

Fixes golang/go#25314
Fixes golang/go#28098
Fixes golang/go#25184

Change-Id: Iaccdd50850a185414ebcf21427cfd7f625c6a298
Reviewed-on: https://go-review.googlesource.com/c/141057
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2018-10-10 16:34:05 +00:00
Elias Naur 920b52be60 cmd/gomobile: bump minimum sdk version and update gradle for NDK 18
NDK 18 drops support for API levels below 16. Bump it to 16.

NDK 18 also needs a newer version of the Android gradle plugin.
Update the bind example and test build.gradle files.

Change-Id: I71499c88b48c43b2d4da50e415cb0b0dcbbbed75
Reviewed-on: https://go-review.googlesource.com/136775
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2018-09-22 16:38:55 +00:00
Hana Kim 274da16109 misc/androidstudio: release 0.2.13
$ docker run --rm -u root -v "$PWD":/home/gradle/project \
   -w /home/gradle/project gradle:latest gradle publishPlugins

gradle version 4.7

Change-Id: I5c86fed85c0e9896a413011fd04ce600743b8f54
Reviewed-on: https://go-review.googlesource.com/112616
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2018-05-10 18:31:09 +00:00
Elias Naur 2f2872eacd example/reverse: delete
The reverse bindings allow access to Java and ObjC APIs by importing
Java/... and Objc/... package from Go. The gobind tool automatically
create the bindings for the API referenced from the packages.

The reverse example takes that ability too far, however. It creates
a circular dependency from the Android databinding layout files to
exported Go types while those same Go types access the Java classes
generated by databinding. It works almost by accident, but not for
newer Gradle versions.

The circular dependencies are bad, but the underlying circular references
created by using the reverse bindings this way are worse. I haven't found
a satisfactory was to avoid retaining references to Go objects from Java
and back without carefully and manually breaking cycles at appropriate
times. One might succeed in ObjC where breaking reference cycles are
already necessary, but not in Java.

The reverse example is a nice technical feat, but promises more than
it can deliver. Delete it.

Fixes golang/go#19862
Fixes golang/go#18210

Change-Id: Ie6abd2a0ebd4c4ce36339d1294898e15f22f83bd
Reviewed-on: https://go-review.googlesource.com/101155
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-16 14:27:06 +00:00
Hana Kim 78f32148b9 misc/androidstudio: update plugin version to 0.2.11
https://plugins.gradle.org/plugin/org.golang.mobile.bind/0.2.11

Built/published with

$ docker run --rm -u root -v "$PWD":/home/gradle/project \
     -w /home/gradle/project gradle:latest gradle publishPlugins

Gradle version 4.5.1

Change-Id: I431101a2b9000147430632ec24e76e8216c66935
Reviewed-on: https://go-review.googlesource.com/95455
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2018-02-20 15:45:06 +00:00
Hana Kim 069be623eb example: update android examples to use 0.2.10 plugin
Also, modernize the build.gradle configurations
to work with recent Android plugin (>=3.0.0)

https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

Update golang/go#21594

Change-Id: Ic2162db7367b60ad873149ab62767f36481fa80f
Reviewed-on: https://go-review.googlesource.com/86795
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2018-01-09 15:14:44 +00:00
Elias Naur 2f6753be0d example/bind/ios/bind.xcodeproj: disable bitcode in Xcode settings
Go compiles to machine code, not bitcode and Xcode will complain if
the bitcode setting is left enabled (the default).

Change-Id: If2caca0b70419c2901b5bfc159669307be39f964
Reviewed-on: https://go-review.googlesource.com/72670
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-10-23 18:25:25 +00:00
Hana Kim 683b305bdb misc/androidstudio: version up gradle plugin to 0.2.9
Change-Id: Icedef49c575937fca885e050e569e513bb7880f7
Reviewed-on: https://go-review.googlesource.com/49258
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2017-07-17 18:12:14 +00:00
Elias Naur 226c1c8284 cmd/gomobile: avoid header guard clash in iOS headers
Fix manually verified; none of our tests or the hello example fails
without this fix.

While we're here, update the hello iOS example to actually include the
Hello.framework and to use module @import syntax.

Fixes golang/go#18693

Change-Id: Id2edf80e2ed9ed8060ec825369a64f276a3b3c1d
Reviewed-on: https://go-review.googlesource.com/35330
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-18 01:06:16 +00:00
Elias Naur d8b1e1aab8 bind,misc: guard reverse generated import with mobile os tags
Running go get golang.org/x/mobile/... results in errors because the
go tool fails to find the reverse generated Java ("Java/...") and
Objective-C ("ObjC/...") packages. Work around the errors by adding
the android and ios tags, respectively, to files importing those
packages.

The gobind gradle plugin is updated to pass along GOOS=android to
ensure the gobind tool continues to build Android reverse packages.

Fixes golang/go#17750

Change-Id: Id66a3c6cdfe249c6ed494192eb12195d6509332f
Reviewed-on: https://go-review.googlesource.com/34956
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-17 14:22:42 +00:00
Elias Naur d96b6de528 internal/importers: skip unexported embedded fields
When determining if a Go struct embeds prefixed types, don't consider
unexported fields. This is important to avoid references cycles with the
Android databinding library; see the reverse example for details.

Change-Id: Ia820ca7ba4d1ec11a1f48651fac248eb753aad75
Reviewed-on: https://go-review.googlesource.com/35188
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-17 14:04:58 +00:00
Elias Naur 3884e8cb98 internal,bind: resolve overloaded methods at runtime
Before this CL, calling overloaded methods on reverse bound Java
classes and interfaces involved confusing and ugly name mangling.
If a set of methods with the same name differed only in argument count,
the mangling was simply adding the argument count to the name:

func F()
func F1(int32)

But if two or more methods had the same number of arguments, the type
had to be appended:

func (...) F() int32
func (...) F1(int32) (int32, error)
func (...) F__I(int32, int32)
func (...) F__JLjava_util_concurrent_TimeUnit_2(int64, concurrent.TimeUnit)

This CL sacrifices a bit of type safety and performance to regain the
convenience and simplicity of Go by resolving overloaded method dispatch
at runtime.

Overloaded Java methods are combined to one Go method that, when invoked,
determines the correct Java method variant at runtime.

The signature of the Go method  is compatible with every Java method with
that name. For the example above, the single Go method becomes the most
general

func (...) F(...interface{}) (interface{}, error)

The method is variadic to cover function with a varying number of
arguments, and it returns interface{} to cover int32, int64 and no
argument. Finally, it returns an error to cover the variant that returns
an error. The generator tries to be specific; for example

func G1(int32) int32
func G2(int32, int32) int32

becomes

func G(int32, ...int32) int32

Overriding Java methods in Go is changed to use the Go parameter types to
determine to correct Java method. To avoid name clashes when overriding
multiple overloaded methods, trailing underscores in the method name are
ignored when matching Java methods.  See the Get methods of GoFuture in
bind/testpkg/javapkg for an example.

Change-Id: I6ac3e024141daa8fc2c35187865c5d7a63368094
Reviewed-on: https://go-review.googlesource.com/35186
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-17 14:03:33 +00:00
Elias Naur c90c4f7c8a bind,internal: change the default Java package to the empty string
The Objective-C bindings was recently changed to support the empty
name prefix and to use that as the default. This CLs changed the Java
generators in the same way, supporting the empty Java package and using
it as the default.

Change-Id: I857affce686c67638a2b6c4e1da5d6a88d7ba560
Reviewed-on: https://go-review.googlesource.com/34778
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-11 19:15:09 +00:00
Elias Naur ff6f6e8d8e bind,cmd,internal: generate reverse bindings for exported Go structs
Before this CL, the type of the implicit "this" parameter to Java methods
implemented in Go could only be a super class of the generated Java
class. For example, the following GoRunnable type is an implementation of
the Java interface java.lang.Runnable with a toString method:

package somepkg

import "Java/java/lang"

type GoRunnable struct {
    lang.Runnable
}

func (r *GoRunnable) ToString(this lang.Runnable) string {
    ...
}

The "this" parameter is implicit in the sense that the reverse generator
automatically fills it with a reference to the Java instance of
GoRunnable.

Note that "this" has the type Java/java/lang.Runnable, not
Java/go/somepkg.GoRunnable, which renders it impossible to call Java
methods and functions that expect GoRunnable. The most practical example
of this is the Android databinding libraries.

This CL changes the implicit this parameter to always match the exact
type. In the example, the toString implementation becomes:

import gopkg "Java/go/somepkg"

func (r *GoRunnable) ToString(this gopkg.GoRunnable) string {
    ...
}

One strategy would be to simply treat the generated Java classes
(GoRunnable in our example) as any other Java class and import it
through javap. However, since the Java classes are generated after
importing, this present a chicken-and-egg problem.

Instead, use the newly added support for structs with embedded prefixed types
and synthesize class descriptors for every exported Go struct type.

Change-Id: Ic5ce4a151312bd89f91798ed4088c9959225b448
Reviewed-on: https://go-review.googlesource.com/34776
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-11 19:06:53 +00:00
Elias Naur 6a96d4c7cf bind: make the default name prefix empty on ObjC
Since generated names now have their package names prefixed, the
extra prefix, "Go", is both confusing and counter-productive to
making the generated ObjC code look like any other native code.

Change the default to the empty prefix, while preserving support
for an explicit prefix if needed.

This is a backwards incompatible change; to keep the old behaviour,
specify "-prefix Go" to the gobind or gomobile command.

While we're here, fix the Ivy example for the recent change in
error returns.

Change-Id: I7fef4a92a18ddadee972ccf359652e3b31624f33
Reviewed-on: https://go-review.googlesource.com/34643
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-12-24 13:37:27 +00:00
Elias Naur b8794a2669 cmd: update documentation and add pure Go Android app example
Update outdated documentation and add documentation and references
for the the new reverse binding support.

Add a new example, reverse, that demonstrates how to use Android
API directly from Go and thereby implement an Android app in pure
Go.

Change-Id: Iac054dbc015d00a37c0cc234931f9bd90172848e
Reviewed-on: https://go-review.googlesource.com/31170
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-11-03 14:40:43 +00:00
Elias Naur 8b28d19931 example: fix Android examples
The Java methods names were recently changed to lowercase, but the
examples weren't updated. Fix that.

While we're here, comment out the GOPATH and GO settings from
the Go build.gradle file. They're confusing for the newcomer and only
needed in the rare case where GOPATH is wrong or missing or if go is
not in PATH.

Change-Id: Ib795b440a0127c402e56b70529f6bd71c6f1322b
Reviewed-on: https://go-review.googlesource.com/29594
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-09-22 17:09:31 +00:00
Jaana Burcu Dogan 7573efae75 exp/audio: remove the high-level player
Since nothing about this high-level player will stay the same after
the audio work core types are finalized, there is no good point in
keeping the naive implementation around.

Removing also the audio example.

Updates golang/go#9551.

Change-Id: I5a7666c77e043aeacf44356e20e8d90822fd78e7
Reviewed-on: https://go-review.googlesource.com/27671
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: Jaana Burcu Dogan <jbd@google.com>
2016-08-24 22:21:38 +00:00
Elias Naur 80e11ad074 mobile/bind: move generated Java classes to package level
Before this CL, generated Java classes or interfaces were inner
classes to the top package class. That is both unnecessary and creates
ugly class names. Instead, move every generated class and interface to its
own package level class.

NOTE: This is a backwards incompatible change and requires every client
of gomobile APIs to be updated to leave out the package class in the
type names. For example, the Go type

package pkg

type S struct {
}

now generates (with the default java package name go) a Java class named
go.pkg.S. The name before this CL was go.pkg.Pkg.S.

Also, change the custom java package to specify the package prefix and
not the full package as before. This is an unfortunate change needed
to avoid name clashes between two bound packages. On the plus side,
the change brings the custom package case closer to the default behaviour,
which is a commen prefix, "go.", and a distinct java package for every
Go package bound.

Change-Id: Iadfaad56e101d1caf7e2a05006f4d384859a20fe
Reviewed-on: https://go-review.googlesource.com/27436
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-08-22 07:41:35 +00:00
Hana Kim 40167cfb81 example/ivy/android: fix a typo that caused a program bug
Additional '=' was added after '&',
but 0 != (a &= b) is still valid in java

Change-Id: I9c7b524941e0553c9fc5095adc5fc7819c4823b0
Reviewed-on: https://go-review.googlesource.com/23950
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-06-09 16:57:57 +00:00
Hana Kim ac3648cc3c example/ivy/android: upgrade gobind plugin to 0.2.6
For golang/go#15554

Also update app target sdk api to 23.

Change-Id: Id66b17b4388703e9806cc50def554b3c58606e24
Reviewed-on: https://go-review.googlesource.com/23690
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2016-06-02 20:00:16 +00:00
Hana Kim df6b37ba82 misc/androidstudio: release gradle plugin 0.2.6
Also
- include a properties file for org.golang.mobile.bind.canary
which is used to canary before release.
- update example/bind/android gradle config.

Change-Id: I1dd0ff94a772b287a2f9be1a915ea72b1c3b0d52
Reviewed-on: https://go-review.googlesource.com/23678
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-06-02 18:18:59 +00:00
Hyang-Ah Hana Kim 2e1e39e5a6 misc/androidstudio: release gobind gradle plugin 0.2.4
That supports GOARCH property.

Also this CL updates examples and upgrades the android gradle plugin
used in examples (from 1.2.3 to 1.5.0)

For golang/go#12819

Change-Id: Ibfed128eaf725775810aa539bd5c0e1ca88f1b85
Reviewed-on: https://go-review.googlesource.com/20331
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-03-08 02:06:34 +00:00
Hyang-Ah (Hana) Kim 04168c3bfb example/bind/android: update gradle version
from 0.2.2 to 0.2.3

Change-Id: I906200acf9615c8cc100b7d1ad5592e899e383fe
Reviewed-on: https://go-review.googlesource.com/19409
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-02-10 23:56:31 +00:00
David Crawshaw e27aacb64e example/sprite: delete
Andrew's new example/flappy does a better job of demoing off these
packages, and I would like to keep our example count under contorl.

Change-Id: I77f4da78815055ab91510ce0cb97bbd7ac1bac3b
Reviewed-on: https://go-review.googlesource.com/18381
Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-01-08 15:21:00 +00:00
Andrew Gerrand 441a9620b3 example/flappy: document texture issue, re-enable reset
Change-Id: I80ba6b4421e64c5470f7b88c92b89ca3686ebec4
Reviewed-on: https://go-review.googlesource.com/18352
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2016-01-07 03:28:10 +00:00
Andrew Gerrand 746653dcb3 example/flappy: add simple example game
This game was developed for and presented at GoCon Winter 2015 in Tokyo.

Change-Id: I08148e16a54355b79f634dce867b3c3c0a0153cb
Reviewed-on: https://go-review.googlesource.com/18245
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2016-01-07 03:14:55 +00:00
David Crawshaw 3abfce6c04 all: windows build tags
For golang/go#9306

Change-Id: Ia8778f5b371371d103c55c12606257ee7ca45fd4
Reviewed-on: https://go-review.googlesource.com/17778
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-12-14 17:43:10 +00:00
Daniel Skinner 3b97f7024e cmd/gomobile: synthesize minSdkVersion for manifest
Fixes golang/go#13172

Change-Id: I16cab3f74f668ce3522a1a14c979aca5c988347c
Reviewed-on: https://go-review.googlesource.com/16843
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-11-13 09:00:34 +00:00
David Crawshaw 7fe809f8e0 event/paint: mark paint events sent by the system
A paint.Event now has an External field. Whenever a paint event is
sent by the x/mobile/app package, it is marked as external so users
with an active paint loop can ignore them.

Implemented on OS X and Android, with examples updated.

Change-Id: Ibee8d65625c8818ff954936be48257ad30daa147
Reviewed-on: https://go-review.googlesource.com/15480
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-10-07 19:41:52 +00:00
Dan Caddigan ca60936f19 example/ivy/android: fix parens grouping example
The current example 2**(2+3) yields the same result as not using
parenthesis.  The "grouped differently" example should use (2**2)+3
so that it yields a different result.

Change-Id: If5f63ec03adba4402c51822d6c13646a26384730
Reviewed-on: https://go-review.googlesource.com/14960
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
2015-10-02 19:42:16 +00:00