2
0
mirror of synced 2025-02-22 22:38:18 +00:00

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>
This commit is contained in:
Elias Naur 2018-03-16 12:10:28 +01:00
parent 37c5126484
commit 2f2872eacd
6 changed files with 0 additions and 144 deletions

View File

@ -1 +0,0 @@
Go reverse bind android app in 100% Go.

View File

@ -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"
}

View File

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="reverse" >
<application
android:label="ReverseBindExample">
<activity
android:theme="@style/Theme.AppCompat.Light"
android:name=".MainActivity"
android:label="ReverseExample" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -1,20 +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. -->
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable name="act" type="reverse.MainActivity"/>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{act.label}"/>
</RelativeLayout>
</layout>

View File

@ -1,8 +0,0 @@
<!-- Copyright 2015 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. -->
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

View File

@ -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!"
}