Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile: Calling net.InterfaceAddrs() fails on Android SDK 30 #40569

Open
halseth opened this issue Aug 4, 2020 · 104 comments
Open

x/mobile: Calling net.InterfaceAddrs() fails on Android SDK 30 #40569

halseth opened this issue Aug 4, 2020 · 104 comments
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@halseth
Copy link

halseth commented Aug 4, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.6 darwin/amd64

$gomobile version
gomobile version +973feb4 Sat Aug 1 11:21:45 2020 +0000 (android,ios); androidSDK=/sdk/platforms/android-30

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/user/Library/Caches/go-build"
GOENV="/Users/user/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/user/golang"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.6/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/user/golang/src/golang.org/x/mobile/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/kq/3436m_v11sg0l7zqtmv2r1gw0000gn/T/go-build713467523=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Calling net.InterfaceAddrs() fails on Android app targetting SDK version 30. With build.gradle looking like:

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.0"
    defaultConfig {
        applicationId "com.example.testapp"
        minSdkVersion 29
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

Building the exact same app targetting SDK 29 works, and returns no error:

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.0"
    defaultConfig {
        applicationId "com.example.testapp"
        minSdkVersion 29
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

What did you expect to see?

Targetting SDK 30 would behave no differently.

What did you see instead?

Calling net.InterfaceAddrs() results in error route ip+net: netlinkrib: permission denied when embedded in Android app targetting SDK 30 (R):

2020-08-04 15:10:21.386 15754-15754/? W/Thread-2: type=1400 audit(0.0:616): avc: denied { bind } for scontext=u:r:untrusted_app:s0:c158,c256,c512,c768 tcontext=u:r:untrusted_app:s0:c158,c256,c512,c768 tclass=netlink_route_socket permissive=0 b/155595000 app=com.example.testapp
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Aug 4, 2020
@gopherbot gopherbot added this to the Unreleased milestone Aug 4, 2020
@halseth halseth changed the title x/mobile: Calling net.InterfaceAddrs() fails on Android ADK 30 x/mobile: Calling net.InterfaceAddrs() fails on Android SDK 30 Aug 4, 2020
@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 4, 2020
@toothrot
Copy link
Contributor

toothrot commented Aug 4, 2020

/cc @hyangah

@hsjoberg
Copy link

hsjoberg commented Sep 8, 2020

Any more updates on this one? Android 11 was released today.

@vikulin
Copy link

vikulin commented Oct 23, 2020

Reproduced in Yggdrasil project for net.Interfaces():
https://github.com/yggdrasil-network/yggdrasil-go/blob/master/src/multicast/multicast.go#L192

@vikulin
Copy link

vikulin commented Nov 21, 2020

Any updates?

@rschulman
Copy link

I'd also love an update, if possible. This is blocking a project of mine right now.

@halseth
Copy link
Author

halseth commented Mar 9, 2021

Anybody looking into this?

@bt90
Copy link

bt90 commented Mar 24, 2021

Seems to be caused by these new restrictions in Android 11:

The following is a list of the ways that apps are affected by this change:

  • NetworkInterface.getHardwareAddress() returns null for every interface.
  • Apps cannot use the bind() function on NETLINK_ROUTE sockets.
  • The ip command does not return information about interfaces.
  • Apps cannot send RTM_GETLINK messages.

https://developer.android.com/training/articles/user-data-ids#mac-11-plus

@Catfriend1
Copy link

@DentonGentry
Copy link

https://developer.android.com/distribute/best-practices/develop/target-sdk

In August 2021, new apps in the Google Play Store will be required to target API level 30.
In November 2021, updates to existing apps in the Google Play Store will be required to target API level 30.

@uburoiubu
Copy link

Any updates on this one? This fix did not work for us: Catfriend1/syncthing-android#800

@simbadMarino
Copy link

Hello golang dev team, any update on this issue? This is blocking the Android 11 compatibility of my app :/. Thanks!

@DentonGentry
Copy link

We ended up developing an alternative using Android APIs, which we call instead of getInterfaceAddrs().
tailscale/tailscale-android#21

@simbadMarino
Copy link

simbadMarino commented Dec 10, 2021 via email

fengzie added a commit to mobazha/mobazha that referenced this issue Dec 12, 2021
@neilyoung
Copy link

neilyoung commented Dec 11, 2023

I'm having a question: This problem is open since 2020. There is no workaround. Basically it means, that all Android apps, relying on GO in some way and "doing network things", will not work if they are running Android 11 or higher (at least the latter is for sure not that exotic anymore as it was in 2020)

I'm wondering why this issue is not making bigger waves, but most likely the relevance of gomobile for Android is lower than expected (which is kind of a pity, since it is in some limited ways a perfect replacement of C++).

But at least network things should be working.

@invented-pro
Copy link

Same suffering here. 4 years old bug, unbelievable!

Findings, while using same gomobile arr in Android App,

  • If App built with targetSdkVersion 29, it can run flawlessly on Android 11 device, but fail on Android 13 device.
  • If App built with targetSdkVersion 30 and above, it fails on all devices, with err msg "netlinkrib: permission denied"

Is there any workaround available, even only with targetSdkVersion 29?

@neilyoung
Copy link

@invented-pro At least for me it is solved. Apply this PR to a source installation of GOLANG #61089

@invented-pro
Copy link

I'll take a try. Thanks @neilyoung

@bt90
Copy link

bt90 commented Jan 22, 2024

@wlynxg what's the current state of the PR?

@neilyoung
Copy link

Merging is blocked for some reasons.

@invented-pro
Copy link

I'll take a try. Thanks @neilyoung

image

src + PR build on macos failed due to some tests.
which platfrom did you manage? @neilyoung

@neilyoung
Copy link

@invented-pro I'm on macOS 14.2.1, M1

@invented-pro
Copy link

@invented-pro I'm on macOS 14.2.1, M1

cannot build on 14.2.1 M2

@neilyoung
Copy link

neilyoung commented Jan 22, 2024

I had a recent binary installation on disk, then followed this gist https://go.dev/doc/install/source. Applied the patch manually. Made the patched GOLANG default then.

EDIT: Aarggh.... Realized right now, that I did it on Ubuntu 20.04. Sorry for this...

@invented-pro
Copy link

I had a recent binary installation on disk, then followed this gist https://go.dev/doc/install/source. Applied the patch manually. Made the patched GOLANG default then.

EDIT: Aarggh.... Realized right now, that I did it on Ubuntu 20.04. Sorry for this...

Thanks. I'll try on linux.

@invented-pro
Copy link

I built golang from src patched with PR61089, then used it to build aar file, finally it works as expected now on Android11 & 13, no "netlinkrib: permission denied" anymore.

Sincerely thank @wlynxg for the PR !!! Thank @neilyoung for guidance!!!

Hints to whom it may concern:

  • Golang built from src failed on my Mac M2; it's done on a Debian11 host with no error.
  • If you see error "zipdata redeclared in this block" during build, that's only because you build src multi times, time/tzdata/zzipdata.go is generated automatically, just delete it.
  • For linux env, don't forget to config Android SDK, NDK, etc.
  • GOROOT is your new go bin directory, don't point GOPATH to this GOROOT.
  • New aar file from Go 1.21 makes my App crash on Android frequently, while Go 1.20 seams ok.

@neilyoung
Copy link

@invented-pro Thanks for letting me know. Yes, this PR is really worth to be merged finally.

Thanks also for the extra information, even though I cannot confirm your last issue.

@vikulin
Copy link

vikulin commented Jun 18, 2024

@invented-pro Thanks for letting me know. Yes, this PR is really worth to be merged finally.

Thanks also for the extra information, even though I cannot confirm your last issue.

Actually the PR is'nt ready yet

@vikulin
Copy link

vikulin commented Jun 19, 2024

Fix confirmed

@KellendF
Copy link

Yes, this problem exists since Android 11, if you need help, you can contact me. Yes, this problem exists since Android 11, if you need help, you can contact me.

Hi @wlynxg, thanks for the offer. Well, I see the changes linked above, but I wouldn't know how to apply them. I generally know how to apply a PR, but in this scenario I'm just a GOMOBILE user under Android, and my GOLANG is maybe three days old or so :) I basically don't know, where to apply the change. Hi, thanks for the quote. Ok, I see the changes linked above but I don't know how to apply them. I usually know how to apply a PR, but in this case I'm just a GOMOBILE user under Android, and my GOLANG is probably three days old or so :) I basically have no idea where to apply the changes.

The official has not accepted this change for the time being. My suggestion is to temporarily use a third-party library on the Android platform instead of the net package to obtain network card information. You can refer to my code: https:// github.com/wlynxg/anet. The official has not accepted this change for the time being. My suggestion is to temporarily use a third-party library on the Android platform instead of the net package to obtain network card information. You can refer to my code: https://github.com/wlynxg/anet.

He solved my problem thanks

bobrofon added a commit to bobrofon/yggdrasil-go that referenced this issue Aug 6, 2024
'github.com/wlynxg/anet' is a partial alternative implementation of
the 'golang.org/x/net' module. The goal of 'anet' module is to provide
workarounds of the issues golang/go#40569 and golang/go#68082 on
Android 11+.
bobrofon added a commit to bobrofon/yggdrasil-go that referenced this issue Aug 13, 2024
'github.com/wlynxg/anet' is a partial alternative implementation of
the 'golang.org/x/net' module. The goal of 'anet' module is to provide
workarounds of the issues golang/go#40569 and golang/go#68082 on
Android 11+.
neilalexander pushed a commit to yggdrasil-network/yggdrasil-go that referenced this issue Aug 16, 2024
This solution is bases on https://github.com/wlynxg/anet project.
`github.com/wlynxg/anet` is a partial alternative implementation of the
`golang.org/x/net` module. The goal of `anet` module is to provide
workarounds of the issues golang/go#40569 and
golang/go#68082 on Android 11+.

Tested on AOSP 13.

Resolves: #1149
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests