Coder Social home page Coder Social logo

ggdream / bindgo Goto Github PK

View Code? Open in Web Editor NEW
37.0 5.0 3.0 222 KB

Use Dart to call Shell, complete the work of compiling Golang CGO code into a so, dll, a, WASM, and etc. And place it in the corresponding source file directory of each Flutter platform.

License: MIT License

Dart 100.00%
flutter golang dartlang cgo ffi cross-platform android ios windows macos linux web fuchsia-os dynamic-link-library

bindgo's Introduction

BindGo

😭
😭 😭
Use Dart to call Shell, complete the work of compiling Golang CGO code into a so, dll, a, WASM, and etc. And place it in the corresponding source file directory of each Flutter platform.


Getting started

First, add bindgo as a dev dependency in your pubspec.yaml file. It belongs in dev_dependencies because it is a command line tool.

dev_dependencies:
  bindgo: any

Usage

  1. Adding your config to field bindgo in pubspec.yaml

e.g. :

bindgo:
  name: test # Dynamic library output name
  main: ./test # The directory where the main package of golang code is located
  platforms:
    windows:
      arch:
        - 'amd64'
    android:
      arch:
        - 'arm64'
      cc: '${NDK}/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android27-clang.cmd'
  1. Run the following command in the terminal
dart run bindgo

or

flutter pub run bindgo:run

Additional information

View the operating systems and architectures supported by the current version of golang:

go tool dist list

e.g. :

# golang v1.17.2

...
android/386
android/amd64
android/arm
android/arm64
---
darwin/amd64
darwin/arm64
...
ios/amd64
ios/arm64
---
js/wasm
---
linux/386
linux/amd64
linux/arm
linux/arm64
...
windows/386
windows/amd64
windows/arm
windows/arm64

bindgo's People

Contributors

ggdream avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bindgo's Issues

run build c lib, but get the exit code 255, and nothing generate

PS D:\hlp\src\myflutter\gommq> flutter pub run bindgo:run
BindGo: windows amd64 starting...
Unhandled exception:
ShellException(go build -buildmode=c-shared -ldflags "-s -w" -o D:\hlp\src\myflutter\gommq\windows\libgolbi.dll ./golib, exitCode 1, workingDirectory: D:\hlp\src\myflutter\gommq)
Instance of '_StringStackTrace'pub finished with exit code 255
PS D:\hlp\src\myflutter\gommq>

Invalid argument(s): Failed to load dynamic library

请问怎么加载编译好的.so给Andriod使用呢?

  • build.gradle
    android/app/build.gradle
    添加以下内容
    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
            // 调用.so
            ndk {
                abiFilters "arm64-v8a"
            }
        }
        //
        debug {
            signingConfig signingConfigs.debug
            ndk {
                abiFilters "armeabi","armeabi-v7a","arm64-v8a", "x86"
            }
        }
    }

flutter run -d ASUS\ Z012DE

The following ArgumentError was thrown building MyApp(dirty):
Invalid argument(s): Failed to load dynamic library
'./android/app/src/main/jniLibs/arm-v8a/libgets.so': dlopen failed: library
"./android/app/src/main/jniLibs/arm-v8a/libgets.so" not found
  • 项目根目录查找
    find . -name "libget*"
./linux/libgets.so
./linux/libgets.h
./linux/libgets.dll
./android/app/src/main/jniLibs/arm-v8a/libgets.so
./android/app/src/main/jniLibs/arm-v8a/libgets.h
./build/linux/x64/debug/bundle/libgets.dll
./build/app/intermediates/stripped_native_libs/debug/out/lib/arm-v8a/libgets.so
./build/app/intermediates/merged_native_libs/debug/out/lib/arm-v8a/libgets.so
./build/app/intermediates/merged_jni_libs/debug/out/arm-v8a/libgets.so
./build/app/intermediates/merged_jni_libs/debug/out/arm-v8a/libgets.h

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.