go x/mobile:构建不包括libc++_shared.so以生成.aar文件,应用程序崩溃,

06odsfpq  于 5个月前  发布在  Go
关注(0)|答案(7)|浏览(53)

你正在使用的Go版本是什么( go version )?

go version go1.17.5 linux/amd64

这个问题在最新版本的发布中是否重现?

是的

你正在使用什么操作系统和处理器架构( 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"
...

你做了什么?

我使用了开源项目 github.com/anacrolix ,并想为我的项目构建一个Android aar。在 gomobile bind -v -target=android ./android/ 之后,成功地为我导出了一个.aar文件。然后我将aar导入到我的项目中使用 implementation files('libs/bt.aar') 。apk也成功构建了。但是当我启动apk并调用aar中的某个方法,比如 SDK.Start 时,我的应用程序崩溃了。这是错误日志:

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)

你期望看到什么?

apk运行成功

你实际上看到了什么?

崩溃

fkaflof6

fkaflof61#

你正在运行哪个版本的Android以及你使用的SDK版本是什么?谢谢。
cc @hyangah@eliasnaur@changkun

siv3szwd

siv3szwd2#

你正在运行哪个版本的Android以及使用的SDK版本是什么?谢谢。
cc @hyangah@eliasnaur@changkun
正在运行Android 10(API 29)。但我认为这个bug可能是因为我错误地使用了gomobile bind命令,或者是gomobile的bug。

wmtdaxz3

wmtdaxz33#

在Corellium上的构建者正在运行Android 9,安装的NDK版本是23b。

l7wslrjt

l7wslrjt4#

在Corellium上的构建者正在运行Android 9,已安装的NDK版本是23b。请问我需要更换NDK版本吗?当前是21.4.7075529

z4bn682m

z4bn682m5#

@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.

ia2d9nvy

ia2d9nvy6#

@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)
9vw9lbht

9vw9lbht7#

我也遇到了这个问题。相同的复现。anacrolix/torrent(可能是anacrolix/go-libutp)的一个依赖项使用了C++。

相关问题