Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Go performed using iOS and Android programming     - How Mutt mail client to use cipher text password (Linux)

- The best known for archiving / compression tool under linux (Linux)

- Port Telnet command to detect the remote host is turned on (Linux)

- In-depth summary of the PHP core of object-oriented (Programming)

- FFmpeg compiled with only H264 decoding library (Programming)

- Java memory area Explanation (Programming)

- About Linux iptables firewall interview questions and answers (Linux)

- Linux file system (inode and block) (Linux)

- Traffic monitor Linux Python Version (Programming)

- Oracle 11g forget approach SYS and SYSTEM password (Database)

- Examples of Exploration Class File (Programming)

- Oracle database on the hit rate of query summary (Database)

- In-depth understanding of capture Node.js garbage collection and memory leaks (Programming)

- Linux basic introductory tutorial ---- Software Installation under Linux (Linux)

- mysqldump issue a note (Database)

- Use HttpClient remote interface testing (Programming)

- Python MySQL database connection (Database)

- pureftpd basis: Install, configure, implement, anonymous logon (Linux)

- Customize the 404 error page Nginx (Server)

- Postmodern systems programming language (Programming)

  Go performed using iOS and Android programming
  Add Date : 2018-11-21      
  Although Go is not a new language, but the last two years or Go adds a lot of interesting features, and the number of well-known use of the language of the project is also rapidly growing. I wrote an article about the SitePoint used programming language, which refers to the end of the mobile support, so I feel the need to look at the possibilities.

I am pleased to support the Android Go language, both of which are in this regard should be Google's technology, on the other hand I am afraid that the developer's desire to replace it with Go Java related.


You need to install Golang 1.5+.

Next, you need to install GoMobile tools for compiling and running the Android and iOS applications:

go get golang.org/x/mobile/cmd/gomobile
gomobile init

We will refer to the bag gomobile example, located GoLangInstalldir / src / golang.org / x / mobile / example /. If you do not have the following command to install these examples, refer to the installation:

go get -d golang.org/x/mobile/example/basic

Construction and installation of Go Native Applications

For many applications, when compiling the Go Native applications, libraries, and interfaces to ignore the platform related is acceptable. If this is the case, existing Go compiled code is very easy, we can choose to use a subset of the features, these features include:

App control and configuration
OpenGL ES 2
Resource Management
Event Management
Some experimental package, including OpenAL, audio, font, sprite and motion sensors
We will already gomobile project started in some examples, you can replace them with your own items in the file.


Construction of a Android APK package

gomobile build -target = android golang.org/x/mobile/example/basic

Deployed to the device

gomobile install golang.org/x/mobile/example/basic


Construction of a iOS IPA packages

gomobile build -target = ios golang.org/x/mobile/example/basic

Deployed to the device

Not the same with Android, for iOS is not a unified deployment commands, you need to use your well-known fashion package copied to the device or emulator, such as the use ios-deploy tool.

You can use the above steps, try golang.org/x/mobile/example/audio this example.

 Let's look further into this audio example (detailed code is not listed), you do not need to Go language is very proficient (and I'm not so familiar), we first look at what some are capable.

First, you can see some of the import statement:

import (...
    "Golang.org/x/mobile/asset" ...)

If you look at the import of these packages directory where GoLangInstalldir / src / golang.org / x / mobile / * file under, you can find those compiled into your code in those files Java and Objective-C.

Then take a closer look, you can find references to import these packages (such as app and glctx) in the code.

Going Native

We can use the Go write code, and then build a compact, optimized native applications, but this application is not currently fully native style, because these are all dependent libraries Java or Objective-C / Swift's. How do we improve this experience?

Go Mobile team gives us another option, you can go packages (ie your program) in a native application. In particular, share some common Go code, bind them to the native code is very easy to use. This way to get started quickly, but long term maintenance would be more some trouble.


If you are using Android Studio, you can import project GoLangInstalldir / src / golang.org / x / mobile / example / bind / android, open build.grade (hello module) file, and update the look GOPATH GO path, here is my file content (I used to install the Homebrew goLang)

After synchronization Gradle, applications can be deployed to the emulator or a real device.

Note: The current in this way supports only ARM-based devices and emulators.

Let Go and look at the Java code:


package org.golang.example.bind;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import go.hello.Hello;
public class MainActivity extends Activity {
    private TextView mTextView;
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.activity_main);
        mTextView = (TextView) findViewById (R.id.mytextview);
        // Call Go function.
        String greetings = Hello.Greetings ( "Android and Gopher");
        mTextView.setText (greetings);

src / golang.org / x / mobile / example / bind / hello / hello.go

package hello
import "fmt"
func Greetings (name string) string {
    return fmt.Sprintf ( "Hello,% s!", name)}

By import go.hello.Hello go to the corresponding import file, the file in the function can be called Greetings Hello.Greetings in Java code. It does not need too complicated steps between function and go native UI elements can be established on a binding relationship.


Go and put a iOS application program directly binding require different steps. First, run the following command:

cd GoLang_Install_dir / src / golang.org / x / mobile / example / bind
gomobile bind -target = ios golang.org/x/mobile/example/bind/hello

This will create a bundle called the Hello.framework in the current directory, you can use it in the project.

In the case of open Xcode iOS projects, located GoLangInstalldir / src / golang.org / x / mobile / example / bind / ios / bind.xcodeproj, Hello.framework onto the project, if necessary, select "Copy items".

Build and run the application (like Android applications), we can see a call Go function is carried out in Objective-C code.

Now look at the code:

#import "ViewController.h"
#import "hello / Hello.h" // Gomobile bind generated header file in hello.framework
@interface ViewController ()
@implementation ViewController
@synthesize textLabel;
- (Void) loadView {
    [Super loadView];
    textLabel.text = GoHelloGreetings (@ "iOS and Gopher");

#import "hello / Hello.h" introduced previously generated framework, textLabel.text = GoHelloGreetings (@ "iOS and Gopher"); it calls a function to set the value of exposing a label of.

You can also use the same based Swift project in the framework of Objective-C automatically generated, like this:

let msg = Hello.GoHelloGreetings ( "gopher")
- CentOS / Debian configuration Gitlab 7.1x to build self Git repository (Linux)
- Teach you to diagnose problems with strace (Linux)
- FPM quickly create packages with RPM (Linux)
- Grub2 Boots the openSUSE installation image (Linux)
- MySQL Statistics (Database)
- Linux operating process information (Linux)
- open V switch port mirror in OpenStack neutron (Server)
- Based kubernetes Construction Docker Cluster Management Comments (Server)
- MySQL Error Code Complete (Database)
- command-line tool for send e-mail (Linux)
- The Hill sorting algorithm (Programming)
- CentOS7 installation hardware monitoring for Zabbix enterprise applications (Server)
- Android studio multi-channel ultra-compact version of the package (Programming)
- Linux security configuration (Linux)
- Linux systems use logwatch log file monitoring (Linux)
- How to install Git on CentOS 7 (Linux)
- Hibernate Performance Optimization of EHCache cache (Programming)
- Solve the compatibility problem between Linux and Java at the source in bold font (Linux)
- Android Delete project useless resource file (Programming)
- How to limit network bandwidth usage in Linux (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.