jni: use the new Go 1.5 shared library; build for java & android
Change-Id: I8c94cd4080180a31ca173bd7ad560d171ab4949f
diff --git a/dummy.go b/dummy.go
index e62d793..53e27bb 100644
--- a/dummy.go
+++ b/dummy.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !android
+// +build !java,!android
package main
diff --git a/impl/google/channel/jni.go b/impl/google/channel/jni.go
index a29a5c5..324f3f4 100644
--- a/impl/google/channel/jni.go
+++ b/impl/google/channel/jni.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package channel
diff --git a/impl/google/channel/util.go b/impl/google/channel/util.go
index cc0b35d..a58cdb3 100644
--- a/impl/google/channel/util.go
+++ b/impl/google/channel/util.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package channel
diff --git a/impl/google/jni.go b/impl/google/jni.go
index 586fab9..da21aa5 100644
--- a/impl/google/jni.go
+++ b/impl/google/jni.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package google
diff --git a/impl/google/namespace/jni.go b/impl/google/namespace/jni.go
index 2ee6c9f..aa39aeb 100644
--- a/impl/google/namespace/jni.go
+++ b/impl/google/namespace/jni.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package namespace
diff --git a/impl/google/namespace/util.go b/impl/google/namespace/util.go
index 2abd02e..535cccb 100644
--- a/impl/google/namespace/util.go
+++ b/impl/google/namespace/util.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package namespace
diff --git a/impl/google/rpc/dispatcher.go b/impl/google/rpc/dispatcher.go
index ad9954b..913fdf8 100644
--- a/impl/google/rpc/dispatcher.go
+++ b/impl/google/rpc/dispatcher.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package rpc
diff --git a/impl/google/rpc/invoker.go b/impl/google/rpc/invoker.go
index 67e0d13..c9d4325 100644
--- a/impl/google/rpc/invoker.go
+++ b/impl/google/rpc/invoker.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package rpc
diff --git a/impl/google/rpc/jni.go b/impl/google/rpc/jni.go
index 7456437..a506f7e 100644
--- a/impl/google/rpc/jni.go
+++ b/impl/google/rpc/jni.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package rpc
diff --git a/impl/google/rpc/util.go b/impl/google/rpc/util.go
index ba0e4aa..000a6b4 100644
--- a/impl/google/rpc/util.go
+++ b/impl/google/rpc/util.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package rpc
diff --git a/impl/google/rt/jni.go b/impl/google/rt/jni.go
index 1f514b2..b184e9b 100644
--- a/impl/google/rt/jni.go
+++ b/impl/google/rt/jni.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package rt
diff --git a/jni.go b/jni.go
index a082d47..a128bec 100644
--- a/jni.go
+++ b/jni.go
@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package main
import (
- "flag"
+ "os"
- "golang.org/x/mobile/app"
+ "v.io/x/lib/vlog"
jgoogle "v.io/x/jni/impl/google"
jutil "v.io/x/jni/util"
@@ -21,6 +21,17 @@
//export Java_io_v_v23_V_nativeInit
func Java_io_v_v23_V_nativeInit(env *C.JNIEnv, jVRuntimeClass C.jclass) {
+ // Ignore all args except for the first one.
+ // NOTE(spetrovic): in the future, we could accept all arguments that are
+ // actually defined in Go. We'd have to manually check.
+ if len(os.Args) > 1 {
+ os.Args = os.Args[:1]
+ }
+ // Send all logging to stderr, so that the output is visible in android.
+ // Note that if this flag is removed, the process will likely crash on
+ // android as android requires that all logs are written into the app's
+ // local directory.
+ vlog.Log.Configure(vlog.LogToStderr(true))
if err := jutil.Init(env); err != nil {
jutil.JThrowV(env, err)
return
@@ -36,9 +47,4 @@
}
func main() {
- // Send all logging to stderr, so that the output is visible in Android. Note that if this
- // flag is removed, the process will likely crash as android requires that all logs are written
- // into a specific directory.
- flag.Set("logtostderr", "true")
- app.Run(app.Callbacks{})
}
diff --git a/util/call.go b/util/call.go
index cddd6ef..c9c73f2 100644
--- a/util/call.go
+++ b/util/call.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package util
diff --git a/util/coding.go b/util/coding.go
index ac70f0a..81b6bcc 100644
--- a/util/coding.go
+++ b/util/coding.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package util
diff --git a/util/jni_wrapper.c b/util/jni_wrapper.c
index a81f5e1..f7a72db 100644
--- a/util/jni_wrapper.c
+++ b/util/jni_wrapper.c
@@ -1,4 +1,4 @@
-// +build android
+// +build java android
#include "jni_wrapper.h"
@@ -159,7 +159,7 @@
}
jint AttachCurrentThread(JavaVM* jvm, JNIEnv** env, void* args) {
- return (*jvm)->AttachCurrentThread(jvm, env, args);
+ return (*jvm)->AttachCurrentThread(jvm, (void**) env, args);
}
jint DetachCurrentThread(JavaVM* jvm) {
diff --git a/util/jni_wrapper.h b/util/jni_wrapper.h
index fe355f6..449cf52 100644
--- a/util/jni_wrapper.h
+++ b/util/jni_wrapper.h
@@ -1,4 +1,4 @@
-// +build android
+// +build java android
// Stubs for invoking JNI (Java Native Interface) methods, which all use
// function pointers. These stubs are meant for languages such as GO
diff --git a/util/ref.go b/util/ref.go
index ae13507..65a4f0e 100644
--- a/util/ref.go
+++ b/util/ref.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package util
diff --git a/util/util.go b/util/util.go
index d6c8a3a..ff137f6 100644
--- a/util/util.go
+++ b/util/util.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
// Package util provides various JNI utilities shared across our JNI code.
package util
@@ -758,7 +758,7 @@
if err := JExceptionMsg(env); err != nil || class == nil {
return nil, fmt.Errorf("couldn't find class %s: %v", name, err)
}
- return unsafe.Pointer(C.NewGlobalRef(env, C.jobject(class))), nil
+ return NewGlobalRef(env, C.jobject(class)), nil
}
// GoTime converts the provided Java DateTime object into a Go time.Time value.
diff --git a/v23/android/jni.go b/v23/android/jni.go
deleted file mode 100644
index 38d9a1f..0000000
--- a/v23/android/jni.go
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build android
-
-package android
-
-import "syscall"
-
-// #include "jni.h"
-// #include <stdlib.h>
-import "C"
-
-// Init initializes the JNI code with the given Java environment. This method
-// must be invoked before any other method in this package and must be called
-// from the main Java thread (e.g., On_Load()).
-// NOTE: Because CGO creates package-local types and because this method may be
-// invoked from a different package, Java environment is passed in an empty
-// interface and then cast into the package-local environment type.
-func Init(jEnv interface{}) error {
- return nil
-}
-
-//export Java_io_v_v23_android_RedirectStderr_nativeStart
-func Java_io_v_v23_android_RedirectStderr_nativeStart(env *C.JNIEnv, jRuntime C.jclass, fileno C.jint) {
- syscall.Dup2(int(fileno), syscall.Stderr)
-}
diff --git a/v23/context/jni.go b/v23/context/jni.go
index 244686b..3a201d2 100644
--- a/v23/context/jni.go
+++ b/v23/context/jni.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package context
diff --git a/v23/context/util.go b/v23/context/util.go
index 35bd0b0..5098c81 100644
--- a/v23/context/util.go
+++ b/v23/context/util.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package context
diff --git a/v23/i18n/jni.go b/v23/i18n/jni.go
index 0a8279e..24af341 100644
--- a/v23/i18n/jni.go
+++ b/v23/i18n/jni.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package i18n
diff --git a/v23/jni.go b/v23/jni.go
index cdc3959..d55f056 100644
--- a/v23/jni.go
+++ b/v23/jni.go
@@ -2,12 +2,11 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
-package veyron2
+package v23
import (
- jandroid "v.io/x/jni/v23/android"
jcontext "v.io/x/jni/v23/context"
ji18n "v.io/x/jni/v23/i18n"
jsecurity "v.io/x/jni/v23/security"
@@ -33,9 +32,6 @@
if err := jsecurity.Init(jEnv); err != nil {
return err
}
- if err := jandroid.Init(jEnv); err != nil {
- return err
- }
if err := jaccess.Init(jEnv); err != nil {
return err
}
diff --git a/v23/jni_android.go b/v23/jni_android.go
new file mode 100644
index 0000000..9ae4b55
--- /dev/null
+++ b/v23/jni_android.go
@@ -0,0 +1,17 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build android
+
+package v23
+
+import "syscall"
+
+// #include "jni.h"
+import "C"
+
+//export Java_io_v_v23_android_RedirectStderr_nativeStart
+func Java_io_v_v23_android_RedirectStderr_nativeStart(env *C.JNIEnv, jRuntime C.jclass, fileno C.jint) {
+ syscall.Dup2(int(fileno), syscall.Stderr)
+}
diff --git a/v23/security/access/jni.go b/v23/security/access/jni.go
index 602344b..a7760b3 100644
--- a/v23/security/access/jni.go
+++ b/v23/security/access/jni.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package access
diff --git a/v23/security/access/util.go b/v23/security/access/util.go
index 535f9e9..c5b73fc 100644
--- a/v23/security/access/util.go
+++ b/v23/security/access/util.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package access
diff --git a/v23/security/authorizer.go b/v23/security/authorizer.go
index b4a4956..5b0eb78 100644
--- a/v23/security/authorizer.go
+++ b/v23/security/authorizer.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package security
diff --git a/v23/security/call.go b/v23/security/call.go
index 71e1acf..7bd44a3 100644
--- a/v23/security/call.go
+++ b/v23/security/call.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package security
diff --git a/v23/security/caveats.go b/v23/security/caveats.go
index 8ff02da..7740637 100644
--- a/v23/security/caveats.go
+++ b/v23/security/caveats.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package security
diff --git a/v23/security/jni.go b/v23/security/jni.go
index 46e3ced..33d5631 100644
--- a/v23/security/jni.go
+++ b/v23/security/jni.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package security
diff --git a/v23/security/principal.go b/v23/security/principal.go
index 938c61a..8d54d10 100644
--- a/v23/security/principal.go
+++ b/v23/security/principal.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package security
diff --git a/v23/security/roots.go b/v23/security/roots.go
index e524aaf..533eafa 100644
--- a/v23/security/roots.go
+++ b/v23/security/roots.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package security
diff --git a/v23/security/signer.go b/v23/security/signer.go
index 6ccbd17..7baf125 100644
--- a/v23/security/signer.go
+++ b/v23/security/signer.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package security
diff --git a/v23/security/store.go b/v23/security/store.go
index 06816cd..f61287e 100644
--- a/v23/security/store.go
+++ b/v23/security/store.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package security
diff --git a/v23/security/util.go b/v23/security/util.go
index e7e3c47..5c2c547 100644
--- a/v23/security/util.go
+++ b/v23/security/util.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build android
+// +build java android
package security