Build go library for Android using gomobile step by step
1. Supposed \src\gobindtemp is my go lib source file
2. Build arr file
gomobile bind [directory under gopath]
ie. gomobile bind -target=android gobindtemp
generate an aar file ie. gobindtemp.aar
I suggest go to the project directory use
gomobile bind -target=android
this will generate .aar file in the project directory
otherwise , .aar is generate in the same directory with /src
3. Establish an Android Project in AndroidStudio
I create a project called gobindtemplate4. Add a New Module into Project
Go to File -> New -> New ModuleSelect your arr file (here is gobindtemp.aar) and push finish button
5. Setup gradle file for module
Copy and modify from
\src\golang.org\x\mobile\example\bind\android\hello\build.gradle to module's build.gradle and modify gopath
6. Setup gradle for Android App
7. Test Build the project
I simply use gradlew assembleDebug in terminal to test build
8. Import go library
9. Using Class and Function
String greetings2 = Gobindtemp.Greetings("Android and Gopher");
沒有留言:
張貼留言