This is a creation in Article, where the information may have evolved or changed. Gomobile Two useful parameters, bind generates a dynamic library, build builds APK
Build Android Dynamic Library
Gomobile bind-target=android github.com/dearcode/candy/server/android
To generate the file Candy.aar, first look at the following size:
Du-sh candy.aar13m Candy.aar
Huge, 13MB, originally wanted to compress, found that the AAR itself is compressed, the resulting file size itself is related to the code, I use the code in the project, if the official test code generated by the file only 2MB
File Candy.aarcandy.aar:Zip archive data, at least v2.0 to extract
Specify the platform to run
Gomobile will generate four platforms by default arm, ARM64, 386, AMD64, you can also specify the platform, for example:
Gomobile Bind-target=android/arm github.com/dearcode/candy/server/android
The resulting file is quite small, and,
Du-sh candy.aar3.0m Candy.aar
The package and struct have the same name.
Currently the Gomobile version, the package name cannot be the same as the class name, if the same, the first class file generated based on the package name will be overwritten:
Gomobile bind-v-target=android github.com/dearcode/candy/server/androidgithub.com/dearcode/candy/server/ androidwrite/tmp/gomobile-work-063666765/fakegopath/pkg/android_arm64/github.com/dearcode/candy/server/ android.awrite/tmp/gomobile-work-063666765/gomobile_bind/go_candymain.gowrite/tmp/gomobile-work-063666765/ gomobile_bind/go_main.gowrite/tmp/gomobile-work-063666765/androidlib/main.gowrite/tmp/gomobile-work-063666765/ android/src/main/java/go/candy/candy.javawrite/tmp/gomobile-work-063666765/android/src/main/java/go/candy/ candy.javawrite/tmp/gomobile-work-063666765/gomobile_bind/java_candy.cwrite/tmp/gomobile-work-063666765/ gomobile_bind/candy.hwrite/tmp/gomobile-work-063666765/android/src/main/java/go/universe.javawrite/tmp/ gomobile-work-063666765/android/src/main/java/go/error.javawrite/tmp/gomobile-work-063666765/gomobile_bind/ java_universe.cwrite/tmp/gomobile-work-063666765/gomobile_bind/universe.hwrite/tmp/gomobile-work-063666765/ Gomobile_bind/seq_android.gowrite/tmp/gomobile-work-063666765/gomobile_bind/seq_android.cwrite/tmp/gomobile-work-063666765/gomobile_bind/ seq.hwrite/tmp/gomobile-work-063666765/gomobile_bind/seq.gowrite/tmp/gomobile-work-981501834/gomobile_bind/ Seq.go
The specific source code is here:
https://github.com/golang/mobile/blob/master/cmd/gomobile/bind.go#L255
The class that corresponds to the package name is generated when Genjava, but in Genclass , a new class is generated based on the struct name in the Golang, and if so, it is overwritten by the class generated by the struct.