go及gomobile的環(huán)境配置這里就不介紹了,直接說aar的生成和使用。
創(chuàng)新互聯(lián)是一家專業(yè)提供烏蘭察布企業(yè)網(wǎng)站建設,專注與成都網(wǎng)站設計、網(wǎng)站制作、html5、小程序制作等業(yè)務。10年已為烏蘭察布眾多企業(yè)、政府機構(gòu)等服務。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進行中。
1. 設置環(huán)境變量GOPATH
GOPATH的值可以有多個,用半角分號間隔,但不能以其結(jié)束,設置完成后需要重新做 gomobile init 。
2. 在GOPATH里創(chuàng)建src文件夾,用于存放go的包和源文件
3. 在src中創(chuàng)建hello文件夾(go文件的包名)
4. 在hello中創(chuàng)建hello.go文件,并輸入內(nèi)容
5. 編譯
執(zhí)行命令: gomobile bind -target=android hello
會生成一個hello.aar文件
6. 導入到android工程
將hello.aar文件放入工程的libs中,并配置build.gradle
在根結(jié)點加入:
在dependencies結(jié)點下加入依賴:
7. 在Java中測試
運行后,結(jié)果會輸出 Hello, Android and Gopher
go語言 一個主package包引入同級目錄下go文件包編譯出錯是設置錯誤造成的,解決方法為:
1、先使用import "strings"導入strings庫。
2、HasPrefix?判斷字符串?s?是否以?prefix?開頭。
3、HasSuffix?判斷字符串?s?是否以?suffix?結(jié)尾。
4、可以看看判斷的代碼。
5、在cmd下運行一下go run test.go,看看如下結(jié)果。
6、Contains?判斷字符串?s?是否包含?substr,也就是判斷一下S是否在strings中。
7、在cmd下運行go run test.go看看結(jié)果。
1、解壓壓縮包到go工作目錄,如解壓到E:\opensource\go\go,解壓后的目錄結(jié)構(gòu)如下:
E:\opensource\go\go
├─api
├─bin
│ ├─go.exe
│ ├─godoc.exe
│ └─gofmt.exe
├─doc
├─include
├─lib
├─misc
├─pkg
├─src
└─test
2、增加環(huán)境變量GOROOT,取值為上面的go工作目錄
3、Path環(huán)境變量中添加";%GOROOT%\bin",以便能夠直接調(diào)用go命令來編譯go代碼,至此go編譯環(huán)境就配置好了
注:如果不想手動設置系統(tǒng)環(huán)境變量,也可下載go啟動環(huán)境批處理附件,
修改goenv.bat文件中的GOROOT值為上面的go工作目錄后直接雙擊該bat文件,go編譯環(huán)境變量即設置完成。
4、測試go編譯環(huán)境,啟動一個cmd窗口,直接輸入go,看到下面的提示就是搭建成功了
E:\opensource\go\gogo
Go is a tool for managing Go source code.
Usage:
go command [arguments]
The commands are:
build compile packages and dependencies
clean remove object files
doc run godoc on package sources
env print Go environment information
fix run go tool fix on packages
fmt run gofmt on package sources
get download and install packages and dependencies
install compile and install packages and dependencies
list list packages
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet run go tool vet on packages
Use "go help [command]" for more information about a command.
Additional help topics:
gopath GOPATH environment variable
packages description of package lists
remote remote import path syntax
testflag description of testing flags
testfunc description of testing functions
Use "go help [topic]" for more information about that topic.
5、編譯helloworld測試程序,go語言包中test目錄帶有helloworld.go測試程序,源碼見"附一 helloworld.go",
直接調(diào)用"go build helloworld.go"就生成了"helloworld.exe"可執(zhí)行程序,運行一下這個程序看到了我們期望的hello,wolrd。
E:\opensource\go\go\testgo build helloworld.go
E:\opensource\go\go\testhelloworld.exe
hello, world
E:\opensource\go\go\test
附一 helloworld.go
// cmpout
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test that we can do page 1 of the C book.
package main
func main() {
print("hello, world\n")
}
新聞名稱:go語言多文件編譯 go語言編譯文件過大
轉(zhuǎn)載注明:http://chinadenli.net/article40/dogdeho.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、網(wǎng)站營銷、營銷型網(wǎng)站建設、靜態(tài)網(wǎng)站、網(wǎng)站設計公司、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)