I am fairly new to Golang and IPFS world. I am trying to run kubo with the help of gomobile in an Android app. The process of creating a node is failing with long error saying
constructing the node: could not build arguments for function "github.com/ipfs/kubo/core/node".PeerWith.func1 (/Users/apple/go/pkg/mod/github.com/ipfs/kubo@v0.27.0/core/node/peering.go:30):
failed to build *peering.PeeringService: could not build arguments for function "github.com/ipfs/kubo/core/node".Peering (/Users/apple/go/pkg/mod/github.com/ipfs/kubo@v0.27.0/core/node/peering.go:14):
failed to build host.Host: could not build arguments for function "github.com/ipfs/kubo/core/node/libp2p".Host (/Users/apple/go/pkg/mod/github.com/ipfs/kubo@v0.27.0/core/node/libp2p/host.go:40):
could not build value group []config.Option[group="libp2p"]: received non-nil error from function "github.com/ipfs/kubo/core/node".LibP2P.ResourceManager.func9 (/Users/apple/go/pkg/mod/github.com/ipfs/kubo@v0.27.0/core/node/libp2p/rcmgr.go:32)
: opening IPFS_PATH: exec: "getent": executable file not found in $PATH
Here is my ipfs.go file
package ipfs
import (
"context"
"fmt"
"io"
"os"
"path/filepath"
"github.com/ipfs/kubo/config"
core "github.com/ipfs/kubo/core"
"github.com/ipfs/kubo/core/node/libp2p"
"github.com/ipfs/kubo/plugin/loader"
"github.com/ipfs/kubo/repo/fsrepo"
)
//Android path "/data/user/0/com.dreamcatcher.android/files/ipfs"
//macos Path "/Users/apple/.ipfs"
func InitIPFS() {
// Create a context with cancellation capability
ctx, _ := context.WithCancel(context.Background())
// defer cancel()
// Set up the IPFS repository
repoPath := "/data/user/0/com.dreamcatcher.android/files/ipfs" // Set your desired repo path. For now it's hardcoded
err := os.MkdirAll(repoPath, 0777)
if err != nil {
fmt.Printf("Failed to create repo directory: %s\n", err)
return
}
plugins, err := loader.NewPluginLoader(filepath.Join(repoPath, "plugins"))
if err != nil {
panic(fmt.Errorf("error loading plugins: %s", err))
}
if err := plugins.Initialize(); err != nil {
panic(fmt.Errorf("error initializing plugins: %s", err))
}
if err := plugins.Inject(); err != nil {
panic(fmt.Errorf("error initializing plugins: %s", err))
}
repoConfig, err := config.Init(io.Discard, 2048)
if err != nil {
fmt.Printf("Failed to initialize repo config: %s\n", err)
return
}
// Add plugins to the config
fsrepo.Init(repoPath, repoConfig)
fmt.Printf("Repo initialized? ", fsrepo.IsInitialized(repoPath))
// Initialize the IPFS repo
r, err := fsrepo.Open(repoPath)
if err != nil {
fmt.Printf("Failed to open repo: %s\n", err)
return
}
//defer r.Close()
fmt.Printf("Repo Data==>",r)
// Construct the IPFS node
cfg := &core.BuildCfg{
Repo: r,
Online: true,
Permanent: true,
}
fmt.Println("Creating IPFS node...")
node, err := core.NewNode(ctx, cfg)
if err != nil {
fmt.Printf("Failed to create IPFS node: %s\n", err)
return
}
fmt.Println(node)
//Start the IPFS node
fmt.Println("IPFS node is created...")
}
I really don’t know what’s causing the issue. Can anybody help me?
What i understood from the error is that the ipfs core package is trying to access GETENT program from the underlying linux arch which is restricted on non-rooted devices. But i am struggling to solve this.
I have created a minimal reproducible example in this repo GitHub - athulantonynp/ipfs-android-golang with the build instructions.