func (x *NativeActivity) Ref() *C.ANativeActivity {
	if x == nil {
		return nil
	}
	return x.ref2cc295bf
}
Ref returns the underlying reference to C object or nil if struct is nil.
package android
import "C"
import (
	"sync"
	"unsafe"
)
func (x *AssetManager) Ref() *C.AAssetManager {
	if x == nil {
		return nil
	}
	return (*C.AAssetManager)(unsafe.Pointer(x))
}
func (x *AssetManager) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewAssetManagerRef(ref unsafe.Pointer) *AssetManager {
	return (*AssetManager)(ref)
}
func NewAssetManager() *AssetManager {
	return (*AssetManager)(allocAssetManagerMemory(1))
}
func allocAssetManagerMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfAssetManagerValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfAssetManagerValue = unsafe.Sizeof([1]C.AAssetManager{})
type cgoAllocMap struct {
	mux sync.RWMutex
	m   map[unsafe.Pointer]struct{}
}
var cgoAllocsUnknown = new(cgoAllocMap)
func (a *cgoAllocMap) Add(ptr unsafe.Pointer) {
	a.mux.Lock()
	if a.m == nil {
		a.m = make(map[unsafe.Pointer]struct{})
	}
	a.m[ptr] = struct{}{}
	a.mux.Unlock()
}
func (a *cgoAllocMap) IsEmpty() bool {
	a.mux.RLock()
	isEmpty := len(a.m) == 0
	a.mux.RUnlock()
	return isEmpty
}
func (a *cgoAllocMap) Borrow(b *cgoAllocMap) {
	if b == nil || b.IsEmpty() {
		return
	}
	b.mux.Lock()
	a.mux.Lock()
	for ptr := range b.m {
		if a.m == nil {
			a.m = make(map[unsafe.Pointer]struct{})
		}
		a.m[ptr] = struct{}{}
		delete(b.m, ptr)
	}
	a.mux.Unlock()
	b.mux.Unlock()
}
func (a *cgoAllocMap) Free() {
	a.mux.Lock()
	for ptr := range a.m {
		C.free(ptr)
		delete(a.m, ptr)
	}
	a.mux.Unlock()
}
func (x *AssetManager) PassRef() *C.AAssetManager {
	if x == nil {
		x = (*AssetManager)(allocAssetManagerMemory(1))
	}
	return (*C.AAssetManager)(unsafe.Pointer(x))
}
func (x *AssetDir) Ref() *C.AAssetDir {
	if x == nil {
		return nil
	}
	return (*C.AAssetDir)(unsafe.Pointer(x))
}
func (x *AssetDir) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewAssetDirRef(ref unsafe.Pointer) *AssetDir {
	return (*AssetDir)(ref)
}
func NewAssetDir() *AssetDir {
	return (*AssetDir)(allocAssetDirMemory(1))
}
func allocAssetDirMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfAssetDirValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfAssetDirValue = unsafe.Sizeof([1]C.AAssetDir{})
func (x *AssetDir) PassRef() *C.AAssetDir {
	if x == nil {
		x = (*AssetDir)(allocAssetDirMemory(1))
	}
	return (*C.AAssetDir)(unsafe.Pointer(x))
}
func (x *Asset) Ref() *C.AAsset {
	if x == nil {
		return nil
	}
	return (*C.AAsset)(unsafe.Pointer(x))
}
func (x *Asset) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewAssetRef(ref unsafe.Pointer) *Asset {
	return (*Asset)(ref)
}
func NewAsset() *Asset {
	return (*Asset)(allocAssetMemory(1))
}
func allocAssetMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfAssetValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfAssetValue = unsafe.Sizeof([1]C.AAsset{})
func (x *Asset) PassRef() *C.AAsset {
	if x == nil {
		x = (*Asset)(allocAssetMemory(1))
	}
	return (*C.AAsset)(unsafe.Pointer(x))
}
func (x *JNINativeMethod) Ref() *C.JNINativeMethod {
	if x == nil {
		return nil
	}
	return (*C.JNINativeMethod)(unsafe.Pointer(x))
}
func (x *JNINativeMethod) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewJNINativeMethodRef(ref unsafe.Pointer) *JNINativeMethod {
	return (*JNINativeMethod)(ref)
}
func NewJNINativeMethod() *JNINativeMethod {
	return (*JNINativeMethod)(allocJNINativeMethodMemory(1))
}
func allocJNINativeMethodMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfJNINativeMethodValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfJNINativeMethodValue = unsafe.Sizeof([1]C.JNINativeMethod{})
func (x *JNINativeMethod) PassRef() *C.JNINativeMethod {
	if x == nil {
		x = (*JNINativeMethod)(allocJNINativeMethodMemory(1))
	}
	return (*C.JNINativeMethod)(unsafe.Pointer(x))
}
func allocJavaVMAttachArgsMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfJavaVMAttachArgsValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfJavaVMAttachArgsValue = unsafe.Sizeof([1]C.JavaVMAttachArgs{})
func unpackPCharString(str string) (*C.char, *cgoAllocMap) {
	h := (*stringHeader)(unsafe.Pointer(&str))
	return (*C.char)(unsafe.Pointer(h.Data)), cgoAllocsUnknown
}
type stringHeader struct {
	Data uintptr
	Len  int
}
func packPCharString(p *C.char) (raw string) {
	if p != nil && *p != 0 {
		h := (*stringHeader)(unsafe.Pointer(&raw))
		h.Data = uintptr(unsafe.Pointer(p))
		for *p != 0 {
			p = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(p)) + 1))  
		}
		h.Len = int(uintptr(unsafe.Pointer(p)) - h.Data)
	}
	return
}
type RawString string
func (raw RawString) Copy() string {
	if len(raw) == 0 {
		return ""
	}
	h := (*stringHeader)(unsafe.Pointer(&raw))
	return C.GoStringN((*C.char)(unsafe.Pointer(h.Data)), C.int(h.Len))
}
func (x *JavaVMAttachArgs) Ref() *C.JavaVMAttachArgs {
	if x == nil {
		return nil
	}
	return x.refab42f020
}
func (x *JavaVMAttachArgs) Free() {
	if x != nil && x.allocsab42f020 != nil {
		x.allocsab42f020.(*cgoAllocMap).Free()
		x.refab42f020 = nil
	}
}
func NewJavaVMAttachArgsRef(ref unsafe.Pointer) *JavaVMAttachArgs {
	if ref == nil {
		return nil
	}
	obj := new(JavaVMAttachArgs)
	obj.refab42f020 = (*C.JavaVMAttachArgs)(unsafe.Pointer(ref))
	return obj
}
func (x *JavaVMAttachArgs) PassRef() (*C.JavaVMAttachArgs, *cgoAllocMap) {
	if x == nil {
		return nil, nil
	} else if x.refab42f020 != nil {
		return x.refab42f020, nil
	}
	memab42f020 := allocJavaVMAttachArgsMemory(1)
	refab42f020 := (*C.JavaVMAttachArgs)(memab42f020)
	allocsab42f020 := new(cgoAllocMap)
	allocsab42f020.Add(memab42f020)
	var cversion_allocs *cgoAllocMap
	refab42f020.version, cversion_allocs = (C.jint)(x.Version), cgoAllocsUnknown
	allocsab42f020.Borrow(cversion_allocs)
	var cname_allocs *cgoAllocMap
	refab42f020.name, cname_allocs = unpackPCharString(x.Name)
	allocsab42f020.Borrow(cname_allocs)
	var cgroup_allocs *cgoAllocMap
	refab42f020.group, cgroup_allocs = (C.jobject)(x.Group), cgoAllocsUnknown
	allocsab42f020.Borrow(cgroup_allocs)
	x.refab42f020 = refab42f020
	x.allocsab42f020 = allocsab42f020
	return refab42f020, allocsab42f020
}
func (x JavaVMAttachArgs) PassValue() (C.JavaVMAttachArgs, *cgoAllocMap) {
	if x.refab42f020 != nil {
		return *x.refab42f020, nil
	}
	ref, allocs := x.PassRef()
	return *ref, allocs
}
func (x *JavaVMAttachArgs) Deref() {
	if x.refab42f020 == nil {
		return
	}
	x.Version = (Jint)(x.refab42f020.version)
	x.Name = packPCharString(x.refab42f020.name)
	x.Group = (Jobject)(x.refab42f020.group)
}
func (x *JavaVMOption) Ref() *C.JavaVMOption {
	if x == nil {
		return nil
	}
	return (*C.JavaVMOption)(unsafe.Pointer(x))
}
func (x *JavaVMOption) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewJavaVMOptionRef(ref unsafe.Pointer) *JavaVMOption {
	return (*JavaVMOption)(ref)
}
func NewJavaVMOption() *JavaVMOption {
	return (*JavaVMOption)(allocJavaVMOptionMemory(1))
}
func allocJavaVMOptionMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfJavaVMOptionValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfJavaVMOptionValue = unsafe.Sizeof([1]C.JavaVMOption{})
func (x *JavaVMOption) PassRef() *C.JavaVMOption {
	if x == nil {
		x = (*JavaVMOption)(allocJavaVMOptionMemory(1))
	}
	return (*C.JavaVMOption)(unsafe.Pointer(x))
}
func (x *JavaVMInitArgs) Ref() *C.JavaVMInitArgs {
	if x == nil {
		return nil
	}
	return (*C.JavaVMInitArgs)(unsafe.Pointer(x))
}
func (x *JavaVMInitArgs) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewJavaVMInitArgsRef(ref unsafe.Pointer) *JavaVMInitArgs {
	return (*JavaVMInitArgs)(ref)
}
func NewJavaVMInitArgs() *JavaVMInitArgs {
	return (*JavaVMInitArgs)(allocJavaVMInitArgsMemory(1))
}
func allocJavaVMInitArgsMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfJavaVMInitArgsValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfJavaVMInitArgsValue = unsafe.Sizeof([1]C.JavaVMInitArgs{})
func (x *JavaVMInitArgs) PassRef() *C.JavaVMInitArgs {
	if x == nil {
		x = (*JavaVMInitArgs)(allocJavaVMInitArgsMemory(1))
	}
	return (*C.JavaVMInitArgs)(unsafe.Pointer(x))
}
func (x *Configuration) Ref() *C.AConfiguration {
	if x == nil {
		return nil
	}
	return (*C.AConfiguration)(unsafe.Pointer(x))
}
func (x *Configuration) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewConfigurationRef(ref unsafe.Pointer) *Configuration {
	return (*Configuration)(ref)
}
func NewConfiguration() *Configuration {
	return (*Configuration)(allocConfigurationMemory(1))
}
func allocConfigurationMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfConfigurationValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfConfigurationValue = unsafe.Sizeof([1]C.AConfiguration{})
func (x *Configuration) PassRef() *C.AConfiguration {
	if x == nil {
		x = (*Configuration)(allocConfigurationMemory(1))
	}
	return (*C.AConfiguration)(unsafe.Pointer(x))
}
func (x *Looper) Ref() *C.ALooper {
	if x == nil {
		return nil
	}
	return (*C.ALooper)(unsafe.Pointer(x))
}
func (x *Looper) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewLooperRef(ref unsafe.Pointer) *Looper {
	return (*Looper)(ref)
}
func NewLooper() *Looper {
	return (*Looper)(allocLooperMemory(1))
}
func allocLooperMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfLooperValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfLooperValue = unsafe.Sizeof([1]C.ALooper{})
func (x *Looper) PassRef() *C.ALooper {
	if x == nil {
		x = (*Looper)(allocLooperMemory(1))
	}
	return (*C.ALooper)(unsafe.Pointer(x))
}
func (x LooperCallbackFunc) PassRef() (ref *C.ALooper_callbackFunc, allocs *cgoAllocMap) {
	if x == nil {
		return nil, nil
	}
	if looperCallbackFunc7E6B484CFunc == nil {
		looperCallbackFunc7E6B484CFunc = x
	}
	return (*C.ALooper_callbackFunc)(C.ALooper_callbackFunc_7e6b484c), nil
}
func (x LooperCallbackFunc) PassValue() (ref C.ALooper_callbackFunc, allocs *cgoAllocMap) {
	if x == nil {
		return nil, nil
	}
	if looperCallbackFunc7E6B484CFunc == nil {
		looperCallbackFunc7E6B484CFunc = x
	}
	return (C.ALooper_callbackFunc)(C.ALooper_callbackFunc_7e6b484c), nil
}
func NewLooperCallbackFuncRef(ref unsafe.Pointer) *LooperCallbackFunc {
	return (*LooperCallbackFunc)(ref)
}
func looperCallbackFunc7E6B484C(cfd C.int, cevents C.int, cdata unsafe.Pointer) C.int {
	if looperCallbackFunc7E6B484CFunc != nil {
		fd7e6b484c := (int32)(cfd)
		events7e6b484c := (int32)(cevents)
		data7e6b484c := (unsafe.Pointer)(unsafe.Pointer(cdata))
		ret7e6b484c := looperCallbackFunc7E6B484CFunc(fd7e6b484c, events7e6b484c, data7e6b484c)
		ret, _ := (C.int)(ret7e6b484c), cgoAllocsUnknown
		return ret
	}
	panic("callback func has not been set (race?)")
}
var looperCallbackFunc7E6B484CFunc LooperCallbackFunc
func allocNativeActivityMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfNativeActivityValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfNativeActivityValue = unsafe.Sizeof([1]C.ANativeActivity{})