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/cmd/gomobile: No implementation found | Android #17359

Open
vrabeux opened this issue Oct 6, 2016 · 8 comments

Comments

@vrabeux
Copy link

commented Oct 6, 2016

Hi,

My environment :

  • go version go1.7.1 darwin/amd64
  • gomobile version +6ea0bb5 Wed Oct 5 13:16:13 2016 +0000 (android,ios); androidSDK=/Users/zoolonly/Library/Android/sdk/platforms/android-23
  • On mac os x

I made a .aar file with gomobile bind -target android, and imported it in my project.
When I run the app in a simulator or device I get the following error :

 No implementation found for void go.avcl_client_usage.Avcl_client_usage._init() (tried Java_go_avcl_1client_1usage_Avcl_1client_1usage__1init and Java_go_avcl_1client_1usage_Avcl_1client_1usage__1init__)

I tried to update go and gomobile but I am stuck.

Thanks for your help.

@quentinmit quentinmit added this to the Unreleased milestone Oct 6, 2016

@dballard

This comment has been minimized.

Copy link

commented Oct 22, 2016

+1
gomobile 6ea0bb537040ee2926a37608791a60803db71171 (sept 13 2016)
go 1.6.3
android 6 & 7
Fedora 23 Linux

import "fmt"

func Greetings(name string) string {
    return fmt.Sprintf("Hello, %s!", name)
}
ublic class contacts extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contacts);


        String greetings = Android_test.greetings("Android and Gopher");
        ((TextView)findViewById(R.id.testText)).setText(greetings);
        //((TextView)findViewById(R.id.testText)).setText("foo"); // works

    }
}

$ adb shell am start -n "im.ricochet.ricochet/im.ricochet.ricochet.contacts" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Waiting for process to come online
Connected to process 5278 on device lge-nexus_5x-00a20cec25be1659
I/art: Late-enabling -Xcheck:jni
I/art: Debugger is no longer active
I/art: Starting a blocking GC Instrumentation
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
E/art: No implementation found for void go.android_test.Android_test.init() (tried Java_go_android_1test_Android_1test__1init and Java_go_android_1test_Android_1test__1init_)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: im.ricochet.ricochet, PID: 5278
java.lang.UnsatisfiedLinkError: No implementation found for void go.android_test.Android_test.init() (tried Java_go_android_1test_Android_1test__1init and Java_go_android_1test_Android_1test__1init_)
at go.android_test.Android_test._init(Native Method)
at go.android_test.Android_test.(Android_test.java:12)
at go.android_test.Android_test.greetings(Native Method)
at im.ricochet.ricochet.contacts.onCreate(contacts.java:18)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Application terminated.


@crawshaw

This comment has been minimized.

Copy link
Contributor

commented Oct 22, 2016

It certainly looks like bind/genjava.go:GenC always generates that symbol, so the fact it's not being found suggests some other reason it is not being loaded. What kind of android device are you running on? What architecture?

(To double check the basics: if you run gomobile with the -work flag it will leave the intermediate files around. Take a look and see if bind generated code for the symbol Java_go_avcl_1client_1usage_Avcl_1client_1usage__1init. Or @dballard, in your case, Java_go_android_1test_Android_1test__1init.)

@sinlov

This comment has been minimized.

Copy link

commented Nov 1, 2016

just finding error of this bug
If your golang package name contains '_', it will let bind jni error like Java_go_xxx_1xxx_1_xxx

So move your golang package name _, or gobind fix this

@dballard

This comment has been minimized.

Copy link

commented Nov 2, 2016

Thank you @sinlov!

first, @crawshaw , I found

/gomobile_bind/java_android_test.c:Java_go_android_test_Android_test__1init(JNIEnv *env, jclass _unused) {

So it got that far...

But renaming the project camel case style to androidTest worked! It imports properly.
So this does seem like a bug in gomobile, that it can't handle go projects with '_' in their name.

Do you want to track that here or start a new fresh ticket?

I am unblocked and moving forward so thanks to everyone!

@dballard

This comment has been minimized.

Copy link

commented Nov 18, 2016

More notes:

package two_words
FATAL EXCEPTION: main
                                                                      Process: im.ricochet.ricochet, PID: 15439
                                                                      java.lang.UnsatisfiedLinkError: No implementation found for void go.two_words.Two_words._init() (tried Java_go_two_1words_Two_1words__1init and Java_go_two_1words_Two_1words__1init__)
                                                                          at go.two_words.Two_words._init(Native Method)
/tmp/gomobile-work-569296966 $ grep 1init ./* -r
./gomobile_bind/java_two_words.c:Java_go_two_words_Two_words__1init(JNIEnv *env, jclass _unused) {

It looks like what ever is doing the generation of package names based on splitting multi word go packages isn't following quite the same standard as the Java side is expecting

Java tried:
Java_go_two_1words_Two_1words__1init
Java_go_two_1words_Two_1words__1init__

C generated code had:
Java_go_two_words_Two_words__1init

@dballard

This comment has been minimized.

Copy link

commented Nov 24, 2016

So according to JNI documentation

https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/design.html#resolving_native_method_names

It says JNI expects '_' in resources like functions to be replaced with '_1'

this is backed by the above problem I'm having, and in your own code
in genjava.go in GenC() you manuually do it for the _init function on line 1298

	g.Printf("Java_%s_%s__1init(JNIEnv *env, jclass _unused) {\n", g.jniPkgName(), g.className())

So It looks like you need a small update to your name handling/translating code that swaps '_' for '_1'

@dballard

This comment has been minimized.

Copy link

commented Dec 22, 2016

@quentinmit I'm hoping I've provided enough data to move this from "Needs more investigation" to the next step. If you have more questions please reach out. I'm still trying to wrap my head around the not small code base of mobile/bind but I feel someone who's already up on it is going to be dramatically faster than me on this :)

@gopherbot gopherbot added the mobile label Jul 20, 2017

@willauld

This comment has been minimized.

Copy link

commented May 20, 2018

I just ran into what looks to me to be this same problem or very close. I was getting the same error message (that's how I found this thread). However, rather than having an '' in the package name I had an '' in the function name. After reading @sinlov's comment I removed the '_' rebuilt the lib with gomobile and then the program in android studio. This did the trick.

So it appears that this issue has not been fixed or at least missed my variant of the problem.
Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.