This allows reuse of the code in custom gomobile bind tools. Change-Id: I4e013ca871d0fa64983e7efb5e1e9dad8ac723c0 Reviewed-on: https://go-review.googlesource.com/18581 Reviewed-by: David Crawshaw <crawshaw@golang.org>
38 lines
1.2 KiB
Java
38 lines
1.2 KiB
Java
// 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.
|
|
|
|
package go;
|
|
|
|
import android.app.Application;
|
|
import android.content.Context;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
// LoadJNI is a shim class used by 'gomobile bind' to auto-load the
|
|
// compiled go library and pass the android application context to
|
|
// Go side.
|
|
//
|
|
// TODO(hyangah): should this be in cmd/gomobile directory?
|
|
public class LoadJNI {
|
|
private static Logger log = Logger.getLogger("GoLoadJNI");
|
|
|
|
public static final Object ctx;
|
|
|
|
static {
|
|
System.loadLibrary("gojni");
|
|
|
|
Object androidCtx = null;
|
|
try {
|
|
// TODO(hyangah): check proguard rule.
|
|
Application appl = (Application)Class.forName("android.app.AppGlobals").getMethod("getInitialApplication").invoke(null);
|
|
androidCtx = appl.getApplicationContext();
|
|
} catch (Exception e) {
|
|
log.warning("Global context not found: " + e);
|
|
} finally {
|
|
ctx = androidCtx;
|
|
}
|
|
}
|
|
}
|
|
|