golang开发android应用(二) - go语言生成android动态库
16lz
2021-12-04
gomobile的两个有用参数,bind 生成动态库,build 生成apk
指定运行平台
生成android动态库
gomobile bind -target=android github.com/dearcode/candy/server/android
生成文件candy.aar,先查看下大小: du -sh candy.aar13M candy.aar
巨大,13MB,本来想压缩下,发现这aar本身就是压缩过的,生成后的文件大小本身与代码有关,我用的是项目中的代码,如果按官方的测试代码生成的文件只有2MB file candy.aarcandy.aar: Zip archive data, at least v2.0 to extract
指定运行平台
gomobile默认会生成四个平台arm, arm64, 386, amd64,你也可以指定平台,例:
gomobile bind -target=android/arm github.com/dearcode/candy/server/android
这样生成的文件就相当小了,,, du -sh candy.aar3.0M candy.aar
package与struct同名问题
目前gomobile版本,包名不能与类名相同,如相同,则先最生根据包名生成的类文件的会被覆盖: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
具体源码在这里:
https://github.com/golang/mobile/blob/master/cmd/gomobile/bind.go#L255
在GenJava时会生成包名对应的类,但在GenClass的时候,分根据golang里的struct名生成新的类,此时如果有相同,则会被struct生成的类覆盖。
更多相关文章
- NPM 和webpack 的基础使用
- 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
- Android(安卓)Log系统介绍 (基于Android(安卓)N)
- 在Android(安卓)java代码中如何改变文件的权限
- Android根文件系统分析
- 《Android学习指南》文件夹
- android下载编译以及文件系统提取总结
- Android(安卓)目前最稳定和高效的UI适配方案
- android 获取文件夹、文件的大小 以B、KB、MB、GB 为单位