This is a creation in Article, where the information may have evolved or changed.
Golang Development Android Environment Construction Introduction
One install dependent software:
Git: Version Management
Go:go Development Environment (version >=1.5), you can download the Windows version of the go installation package directly.
Android Studio:android Development IDE
Two Go Tools Mobile installation:
1 mkdir-p $GOPATH/src/github.com/golang; CD $GOPATH/src/github.com/golang//$GOPATH Go Program working directory, refer to go environment building related knowledge
2 git clone https://github.com/golang/mobile.git//download Mobile tool code Refer to Git usage
3 mkdir-p $GOPATH/src/golang.org/x; Cp-r $GOPATH/src/github.com/golang/mobile $GOPATH/src/golang.org/x//Move the source to the golang.org/x directory, the code moved to GitHub due to the wall
4 CD $GOPATH/src/golang.org/x/mobile/cmd/gomobile; Go build//build Gomobile.exe executable, compile directly in github.com directory error
5 Gomobile.exe can be added to the environment variable directory for ease of use
Three use Gomobile to generate Android apk with the source code to bring the example to illustrate):
1 CD $GOPATH/src/golang.org/x/mobile/example/basic; Gomobile build//Use Gomobile build direct compile generates basic.apk, directly executes Gomobile to see its related usage instructions
2 Generate apk direct download simulator or mobile phone to run
IV using Gomobile to generate the Android SDK (with the source code to take the example to illustrate)
1 CD $GOPATH/src/golang.org/x/mobile/example/bind; Gomobile bind-target=android./hello//Generate Hello.aar Binary release package
2 Create a test project using Android Studio, copy the Hello.aar to the Libs directory of the Project module//refer to the Android Studio reference jar
3 Configure the module's Gradle.build file, add the following code in the Gradle.build (red Code):
1 repositories {//config Gradle dependent library (flat dependent mode) Reference Gradle dependent library related use 2 flatdir { 3 dirs 'libs' 4 } 5 } 6 7 Dependencies {//The node file will always exist, so only the last behavior new code8Compile Filetree (include: ['*.jar'], dir:'Libs')9Testcompile'junit:junit:4.12'TenCompile'com.android.support:appcompat-v7:23.1.0' One ACompile (name:'hello', ext:'aar ')) -}
4 Recompile the entire project, generate the Build/intermediates/exploded-aar/hello directory, where you can find the go file corresponding to the generated Java file
5 using the relevant interface in the Build/exploded-aar/hello directory directly in the project can implement the SDK related functions of calling go
Ps:go as an Android SDK use is limited, specific reference gobind related knowledge, such as: Https://godoc.org/golang.org/x/mobile/cmd/gobind
It's not perfect to use go to develop Android programs directly. Another liunx is basically similar to the construction
Gradle use: http://blog.jobbole.com/71999/
Gomobile use: Https://github.com/golang/go/wiki/Mobile
Gomobile Source Address: Https://github.com/golang/mobile