golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123k stars 17.54k forks source link

x/mobile: com.android.dex.DexException: Multiple dex files define Lgo/LoadJNI; #17278

Open joeblew99 opened 7 years ago

joeblew99 commented 7 years ago

Please answer these questions before submitting your issue. Thanks!

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

x-MacBook-Pro:mobile-sdk apple$ go version
go version go1.7.1 darwin/amd64

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

x-MacBook-Pro:mobile-sdk apple$ gomobile version
gomobile version +9640137 Tue Sep 27 16:37:51 2016 +0000 (android,ios); androidSDK=/Users/apple/Library/Android/sdk/platforms/android-24

x-MacBook-Pro:mobile-sdk apple$ go env
GOARCH="amd64"
GOBIN="/Users/apple/workspace/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/apple/workspace/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wp/ff6sz9qs6g71jnm12nj2kbyw0000gp/T/go-build085920980=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"

What did you do?

I was working in Android Studio, and had one aar from a go project referenced as a aar module. I added a 2nd aar as a module from a golang project. In the "Project Structure.." i made sure both aar modules were dependencies of the app module. and when building my APK got:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lgo/LoadJNI;

How to reproduce ?

Take 2 simple gomobile compiled projects, and build their .aar. Hello World & FooBar will do.. Add the first to an android project, reference it and build. All is good. Add the second aar to the same android project.
Make sure the app module has a dependency on both aar modules.. Now , all is bad :) Multiple dex files error occurs on build...

How to stop the bug ? Remove one of the aar modules from the Project Structure app module dependencies. But thats not fixing the problem, but thats how you can toggle the error happening easily..

Not sure whats going ok...

Why this sucks ? I can work around it by making sure all my code fits into a single golang project. Composition is easy with golang. But it makes me wonder what the bug is, and i also dont knwo if this is a deal breaker for others.

quentinmit commented 7 years ago

I think this is WAI; my understanding is that Go currently does not support linking two separately-built archives into a single program. This is true both on Android and on desktop OSes.

-> @crawshaw who is working on improving this; David, is this a dupe of an existing bug?