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: build doesn't include libc++_shared.so to produced .aar file and app crashes #50157

Open
tangxuesong6 opened this issue Dec 14, 2021 · 6 comments
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@tangxuesong6
Copy link

tangxuesong6 commented Dec 14, 2021

What version of Go are you using (go version)?

go version go1.17.5 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GO111MODULE="on"
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOVERSION="go1.17.4"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
...

What did you do?

I use the open source project github.com/anacrolix, and want to build an Android aar for my project.
After gomobile bind -v -target=android ./android/ , successfully exported an .aar file for me. Then i import the aar to my project use
implementation files('libs/bt.aar') . The apk build successfully too. But when i launch the apk and cal the method in aar,like SDK.Start, my app crashed. Here is the error log

    java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
        at java.lang.System.loadLibrary(System.java:1667)
        at go.Seq.<clinit>(Seq.java:37)
        at go.Seq.touch(Seq.java:50)

What did you expect to see?

apk run successful

What did you see instead?

crashed

@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Dec 14, 2021
@gopherbot gopherbot added this to the Unreleased milestone Dec 14, 2021
@cherrymui
Copy link
Member

cherrymui commented Dec 14, 2021

What version of Android you are running on and what SDK version you're using? Thanks.

cc @hyangah @eliasnaur @changkun

@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 14, 2021
@tangxuesong6
Copy link
Author

tangxuesong6 commented Dec 15, 2021

What version of Android you are running on and what SDK version you're using? Thanks.

cc @hyangah @eliasnaur @changkun

Running on Android 10 (API 29). But i think the bug maybe because of my wrong use of gomobile bind cmd, or it's gomobile's bug.

@changkun
Copy link
Member

changkun commented Dec 15, 2021

@cherrymui The builders on Corellium are running Android 9 and the installed NDK version is 23b.

@tangxuesong6
Copy link
Author

tangxuesong6 commented Dec 15, 2021

@cherrymui The builders on Corellium are running Android 9 and the installed NDK version is 23b.

请问我是要换NDK版本吗? 当前是21.4.7075529

@changkun
Copy link
Member

changkun commented Dec 15, 2021

@cherrymui The builders on Corellium are running Android 9 and the installed NDK version is 23b.

请问我是要换NDK版本吗? 当前是21.4.7075529

Can you maybe provide a minimal example to show your build process? The previous description is not clear as the project that you claim to build is not clear to us too.

@tangxuesong6
Copy link
Author

tangxuesong6 commented Dec 16, 2021

@cherrymui The builders on Corellium are running Android 9 and the installed NDK version is 23b.

请问我是要换NDK版本吗? 当前是21.4.7075529

Can you maybe provide a minimal example to show your build process? The previous description is not clear as the project that you claim to build is not clear to us too.

OK

1

download some repositories(GO111MODULE="on")

go get -u github.com/anacrolix/torrent
go get -u github.com/dustin/go-humanize

2

here is my code(only 17 lines)

import (
	"fmt"
	"github.com/anacrolix/torrent"
	"github.com/dustin/go-humanize"
)

func GetBtInfo() {
	var t *torrent.Torrent
	cfg := torrent.NewDefaultClientConfig()
	cfg.DataDir = "./movie"
	c, err := torrent.NewClient(cfg)
	if err != nil {
		fmt.Printf("err: %v", err)
	}
	url := "magnet:?xt=urn:btih:38F07BE8BBBBE4F2C6CBEC909F5C7BFAB8114185&dn=Resident%20Evil%20Welcome%20to%20Raccoon%20City%202021%20x264%20AAC%20800MB%20SD%20HDC&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2780%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2730%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=http%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce&tr=udp%3A%2F%2Ftracker.tiny-vps.com%3A6969%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce"
	t, err = c.AddMagnet(url)
	if err != nil {
		fmt.Printf("add err: %v", err)
	}
	<-t.GotInfo()
	size := humanize.Bytes(uint64(t.Info().TotalLength()))
	fmt.Printf("totalSize: %s, name: %s", size, t.Info().Name)
}

3

use gomobile

 gomobile init   

 gomobile bind -v  -target=android ./android/ 

this step will output an .aar file(named android.aar)

4

copy the .aar file to Android studio, and implementation

    implementation files('libs/android.aar')

5

create a buttun in my Android app, when click, call the android.aar method GetBtInfo

Android.getBtInfo();

6

build and run the Android project. the app run successfully. But when i click the buttun which call a method Android.getBtInfo();, crashed. Here is the error log.

 java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
        at java.lang.System.loadLibrary(System.java:1667)
        at go.Seq.<clinit>(Seq.java:37)
        at go.Seq.touch(Seq.java:50)
        at android.Android.<clinit>(Android.java:12)
        at android.Android.getBtInfo(Native Method)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants