From 2f2872eacd7fc12c252096592f87e9b23bd5be8b Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 16 Mar 2018 12:10:28 +0100 Subject: [PATCH] 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 --- example/reverse/android/README | 1 - example/reverse/android/build.gradle | 55 ------------------- .../android/src/main/AndroidManifest.xml | 20 ------- .../src/main/res/layout/activity_main.xml | 20 ------- .../android/src/main/res/values/dimens.xml | 8 --- example/reverse/reverse/reverse.go | 40 -------------- 6 files changed, 144 deletions(-) delete mode 100644 example/reverse/android/README delete mode 100644 example/reverse/android/build.gradle delete mode 100644 example/reverse/android/src/main/AndroidManifest.xml delete mode 100644 example/reverse/android/src/main/res/layout/activity_main.xml delete mode 100644 example/reverse/android/src/main/res/values/dimens.xml delete mode 100644 example/reverse/reverse/reverse.go diff --git a/example/reverse/android/README b/example/reverse/android/README deleted file mode 100644 index 2543952..0000000 --- a/example/reverse/android/README +++ /dev/null @@ -1 +0,0 @@ -Go reverse bind android app in 100% Go. diff --git a/example/reverse/android/build.gradle b/example/reverse/android/build.gradle deleted file mode 100644 index 8166a30..0000000 --- a/example/reverse/android/build.gradle +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2016 The Go Authors. All rights reserved. - * Use of this source code is governed by a BSD-style - * license that can be found in the LICENSE file. - */ - -buildscript { - repositories { - jcenter() - maven { - url "https://plugins.gradle.org/m2/" - } - } - dependencies { - classpath 'com.android.tools.build:gradle:2.2+' - classpath "gradle.plugin.org.golang.mobile.bind:gobindPlugin:0.2.8" - } -} - -apply plugin: 'com.android.application' - -repositories { - jcenter() -} - -android { - compileSdkVersion 24 - buildToolsVersion "24.0.3" - - defaultConfig { - applicationId "org.golang.example.reverse" - minSdkVersion 15 - targetSdkVersion 24 - versionCode 1 - versionName "1.0" - } - buildTypes { - release { - minifyEnabled false - } - } - dataBinding { - enabled = true - } -} - -dependencies { - compile 'com.android.support:appcompat-v7:24+' -} - -apply plugin: "org.golang.mobile.bind" - -gobind { - pkg = "golang.org/x/mobile/example/reverse/reverse" -} diff --git a/example/reverse/android/src/main/AndroidManifest.xml b/example/reverse/android/src/main/AndroidManifest.xml deleted file mode 100644 index 21604d8..0000000 --- a/example/reverse/android/src/main/AndroidManifest.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - diff --git a/example/reverse/android/src/main/res/layout/activity_main.xml b/example/reverse/android/src/main/res/layout/activity_main.xml deleted file mode 100644 index ee94e47..0000000 --- a/example/reverse/android/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - diff --git a/example/reverse/android/src/main/res/values/dimens.xml b/example/reverse/android/src/main/res/values/dimens.xml deleted file mode 100644 index cc0636b..0000000 --- a/example/reverse/android/src/main/res/values/dimens.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - 16dp - 16dp - diff --git a/example/reverse/reverse/reverse.go b/example/reverse/reverse/reverse.go deleted file mode 100644 index f6ce404..0000000 --- a/example/reverse/reverse/reverse.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package reverse implements an Android app in 100% Go. - -// +build android - -package reverse - -import ( - "Java/android/databinding/DataBindingUtil" - "Java/android/os" - "Java/android/support/v7/app" - gopkg "Java/reverse" - rlayout "Java/reverse/R/layout" - "Java/reverse/databinding" - "Java/reverse/databinding/ActivityMainBinding" -) - -type MainActivity struct { - app.AppCompatActivity - binding databinding.ActivityMainBinding -} - -func (a *MainActivity) OnCreate(this gopkg.MainActivity, b os.Bundle) { - this.Super().OnCreate(b) - db := DataBindingUtil.SetContentView(this, rlayout.Activity_main) - a.binding = ActivityMainBinding.Cast(db) - a.binding.SetAct(this) -} - -func (a *MainActivity) OnDestroy(this gopkg.MainActivity) { - a.binding = nil // break reference cycle - this.Super().OnDestroy() -} - -func (a *MainActivity) GetLabel() string { - return "Hello from Go!" -}