Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Go performed using iOS and Android programming     - Neo4j map data processing tab (Database)

- How to install Laravel PHP framework on CentOS 7 / Ubuntu 15.04 (Server)

- Questions about Linux compiler u-boot (Programming)

- MongoDB, Cassandra, HBase transaction design strategy (Database)

- The difference between equals and == in Java (Programming)

- Repair after installing Ubuntu no boot device error (Linux)

- Mybatis + binding Struts2: achieving user to insert and find (Programming)

- Ubuntu 14.04 How to set up an SSH without password (Linux)

- The OpenGL ES GLFW window structures (Programming)

- Programmer editor Vim (Linux)

- Java static code analysis tool Infer (Programming)

- C ++ handling text input (Programming)

- Copy files between two Linux hosts (Linux)

- Install RAID 6 (Striping double distributed parity) (Linux)

- Chromium Install Flash Official Guide (Linux)

- awk variables (Linux)

- Simple to use multi-threaded programming under Linux mutex and condition variable (Programming)

- How dependent on Fedora, CentOS, RHEL check RPM packages (Linux)

- Linux find command usage practices (Linux)

- Debian 7.6 install Nvidia graphics driver (Linux)

 
         
  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.

Start

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.

Android

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

iOS

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/app"
    "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.

Android

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:

MainActivity.java

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;
 
    @Override
    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.

iOS

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 ()
@end
 
@implementation ViewController
 
@synthesize textLabel;
 
- (Void) loadView {
    [Super loadView];
    textLabel.text = GoHelloGreetings (@ "iOS and Gopher");
}
 
@end

#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")
     
         
       
         
  More:      
 
- Connect to the Oracle Database Help class (Database)
- Java Foundation - Variables and data types (Programming)
- How to manage the time and date at systemd Linux systems (Linux)
- RabbitMQ user roles and access control (Linux)
- Linux unpack the tar file to a different directory (Linux)
- Changes in C # asynchronous programming model (Programming)
- Linux server data backup (Server)
- Based Corosync + Pacemaker + DRBD + LNMP Web server to achieve high availability cluster (Server)
- LNMP Note: Addressing mail function can not send mail (Server)
- xargs Detailed description (Linux)
- Linux raw socket (Programming)
- Linux virtual memory and physical memory (Linux)
- 6 common PHP security attacks (Linux)
- Use regular expressions to check whether the input box to enter a URL (Programming)
- Linux System Getting Started Tutorial: Using the Linux common commands (Linux)
- MySQL thread cache thread_cache_size parameter optimization (Database)
- On FreeBSD 10.2 Bugzilla how to install and configure Apache SSL (Server)
- Node.js installed on Ubuntu Upstream version (Linux)
- CentOS 7 How to connect to a wireless network (Linux)
- Use Vagrant build cross-platform development environment for Python (Server)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.