Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile: crash in gobind with interface with ios 8.4 and xcode 7.0.1 #13578

Closed
bronze1man opened this issue Dec 11, 2015 · 6 comments

Comments

Projects
None yet
4 participants
@bronze1man
Copy link
Contributor

commented Dec 11, 2015

Environment:

 > ./bin/gomobile version
gomobile version +cd12613 Thu Dec 10 02:09:38 2015 +0000 (android,ios); androidSDK=
ios 8.4
xcode 7.0.1
 > go version
go version go1.5.1 darwin/amd64
Phone: iphone 5c
Development: mac os x 10.10.4

I have following code to bind into ios project.
golang:

package goIos
type CacheStorager interface {
    Set(key string,value string) (err error)
    Get(key string) (value string,err error)
}

func Init(storager CacheStorager){
}

func Hello() string{
    return "hello1"
}

oc:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    NSLog(@"application start %@",GoGoIosHello() );
    return YES;
}

It build success,but
It crash when the app is open in ios 8.4.

It will not crash for ios 9.1 and xcode 7.0.1, but it will crash for ios 8.4 and xcode 7.0.1

image

I found a way to prevent it from crash:

comment the file at src/golang.org/x/mobile/bind/genobjc.go:275
image

@bronze1man

This comment has been minimized.

Copy link
Contributor Author

commented Dec 14, 2015

I tried 3 ios8.4 iphone,only one iphone crash.
I think it may be a hardware bug.
Close for now.

@bronze1man bronze1man closed this Dec 14, 2015

@fernand

This comment has been minimized.

Copy link

commented Feb 4, 2016

I have the exact same error when using gobind on an iPhone 5 and iPhone 5C, both on iOS 8 and iOS 9. So it's probably tied to building on armv7.

@hermanschaaf

This comment has been minimized.

Copy link

commented Feb 22, 2016

I also have this (or a very similar-looking) problem, iPhone 5 and iOS 9. Here is a screenshot of my error log:

screen shot 2016-02-22 at 14 30 02

I noticed that the error in the original post by @bronze1man may be due to the Init() function, which conflicts with a method in iOS, as per this comment at the top of src/golang.org/x/mobile/bind/genobjc.go:

// TODO(hyangah): handle method name conflicts.
// - struct with SetF method and exported F field.
// - method names conflicting with NSObject methods. e.g. Init
// - interface type with InitWithRef.

My code, however, has only two functions, and I made sure they do not conflict with any other names. gobind-generated objective C file looks like this:

#ifndef __GoGotranslate_H__
#define __GoGotranslate_H__

#include <Foundation/Foundation.h>

@class GoGotranslateTranslation;

@interface GoGotranslateTranslation : NSObject {
}
@property(strong, readonly) id _ref;

- (id)initWithRef:(id)ref;
- (void)closeDatabase;
- (NSString*)translateFromString:(NSString*)src;
@end

FOUNDATION_EXPORT GoGotranslateTranslation* GoGotranslateNewTranslation(NSString* filepath);

#endif
@hermanschaaf

This comment has been minimized.

Copy link

commented Feb 22, 2016

@bronze1man I'd love to know how you figured out which part of the code to comment out to make it work!

@hermanschaaf

This comment has been minimized.

Copy link

commented Feb 22, 2016

This has been plaguing me for hours now, and I finally figured out that if I revert back to go1.5.3, it works without problems. Switch to 1.6.0, and it crashes with the error log I posted above. So it must be something that changed between these two versions?

@bronze1man

This comment has been minimized.

Copy link
Contributor Author

commented Feb 23, 2016

@hermanschaaf

  • I looked into the generated project of the gomobile code,
  • I tried to comment out some init code.and comment out that part of init code will work.
  • I found the code that generated that init code, and comment out them.

workaround

The real workaround is to use cgo with objective-c and golang and put your .h file into generated framework .h file ,and do not use gomobile rpc stuff.(only leave a empty Hello function in the gomobile rpc).

This workaround can use any objective-c ios api in cgo,
You can define objective-c class in cgo.
You can get a nice interface to ios and to golang in the framework.
You can have arc in objective-c in cgo.

@golang golang locked and limited conversation to collaborators Feb 28, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.