Golang Development Android App (ii)-Go language build Android Dynamic library

Source: Internet
Author: User
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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.