Skip to content

x/mobile/cmd/gomobile: multiple packages binding #12245

@hyangah

Description

@hyangah

I need to gobind multiple packages for an app.

I considered running gomobile for each package and import multiple .so files, but that will fail due to various reasons:

  • gobind framework for java assumes a single 'gojni.so' file
  • duplicate code for go runtime in multiple .so files; conflicting symbols, storage, ...

Option 1:

gomobile bind -target=android -o=myapp.aar pkg1 pkg2 pkg3

The command will generate separate java classes for those packages, and gather all asset files under one asset directory. Conflicting package names and asset file names are error.

Option 1.a

gomobile bind -target=android -o=myapp.aar -pkg=com.example.foo,org.example.bar,net.example.baz pkg pkg2 pkg3

Option 1.b

gomobile bind -target=android -o=myapp.aar pkg1:com.example.foo pkg2:org.example.bar pkg3 ...

Option 2:

gomobile bind -target=android -o=myapp.aar -list=something.json

Make gomobile take an input file of a certain format that lists all packages for gobind.

   /* something.json */
   {
        Name: "pkg1",
        Android: "com.example.foo",
        IOS: "MyFoo"
   }

Option 3:

Fake main package file - so when gomobile bind sees the 'main' package, it runs gobind on all the imported packages, and process the command that specifies the custom package name for java and prefix for obj-c.

gomobile bind -target=android -o myapp.aar myapp.go

   /* myapp.go */
   package main
   import (
          _ "pkg1"  // android:com.example.foo ios:MyFoo
          ...
   )
   func main() {
   }

/cc @crawshaw @rakyll

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions