go: x/mobile: Gomobile is not compatible with modern Android SDKs and NDKs
Gomobile makes a number of assumptions about the Android SDK and NDK that are no longer correct:
- ANDROID_HOME provides the SDK location (soft-deprecated in favor of a default path)
- Android API 15 is supported. (All supported SDKs have a minimum API version of 16 or higher)
- There is only one possible NDK to use (false under the new “side by side” NDK system)
- ANDROID_NDK_HOME provides the NDK location (hard-deprecated due to “side by side” NDK)
$ANDROID_HOME/ndk-bundleis the default NDK location (it is now$ANDROID_HOME/ndk/<version>)- Android binary resource packages only contain “Type” and “TypeSpec” entries (they can now contain Staged Alias Headers as well)
These assumptions seem to make Gomobile incompatible with NDK 24, and somewhat inconvenient to use with other modern SDK and NDK versions.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 5
- Comments: 19 (7 by maintainers)
Commits related to this issue
- -androidapi 19 arg is now required for current ndk versions, see https://github.com/golang/go/issues/52470#issuecomment-1203874724 — committed to zchee/golang-wiki by justinmichaelvieira 2 years ago
I was trying to setup gomobile on my machine using this document wiki https://github.com/golang/go/wiki/Mobile and what I am kind of shocked on is that there is no information about NDK prerequisites to setting up an environment. So you just try to run
$ gomobile build -target=android golang.org/x/mobile/example/basicAnd get issues in regard to NDK not being installed. You install the latest via many different methods like Android Studio or brew on mac and they are too new for gomobile so it errors and says “ANDROID_NDK_HOME specifies /usr/local/share/android-ndk, which is unusable: unsupported API version 16 (not in 19…33)”
Currently I am playing with r19c I downloaded from the unsupported versions and it is kind of compiling the hello world example, but osx is saying the developer is not supported when its trying to run clang and Id and other commands and I keep “allowing anyway” in security, but it keeps staying in a loop not allowing it and the build failing. Can anyone help with this issue too?
I added
-androidapi 19to the wiki at https://github.com/golang/go/wiki/Mobile#building-and-deploying-to-android , as this is now necessary with current NDK versions. If someone wants to further specify which ndk versions need-androidapi 19, there, and which do not, I think that would also be helpful.I’ve come across this too recently because of this change in GitHub actions for the ubuntu image https://github.com/actions/virtual-environments/issues/5930
What is happening I think is that
gomobileis now finding the newer SDK which it doesn’t understand without-androidapi 19.I added
-androidapi 19to the build and all was well so I think this is an acceptable fix.@davidrenne If you don’t need API 16 support, you can add
-androidapi 19and stick with the latest NDK.Hello, I am still getting this error even though I have latest SDKs and NDKs installed from Android Studio. Any idea what I am doing wrong?
command: gomobile bind -o -androidapi 21 app/hello.aar -target=android
error: gomobile: no usable NDK in /Users/sebmelki/Library/Android/sdk: unsupported API version 16 (not in 21…34), open /Users/sebmelki/Library/Android/sdk/ndk-bundle/meta/platforms.json: no such file or directory
Proposed fix at https://go-review.googlesource.com/c/mobile/+/401574
still got problem building with stable release of sdk and ndk and after predicting which folder the dev was puting what ndk (i’m not a golang fan just want a aar file from it) still getting more errors like this:
/root/go/bin/gomobile: No compiler for arm was found in the NDK (tried /opt/android-sdk/ndk/prebuilt/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang). Make sure your NDK version is >= r19c. Use sdkmanager --update to update it.FATAL[0000] exit status 1so i know single handedly i need to test all version and some people suggest you might need to rename or symlink the arm compilers files what an experience this golang is WOW.in new version of android studio the sdk and ndk path are changed you should set your ANDROID_NDK_HOME env variable to “C:\Users\Emad\AppData\Local\Android\Sdk\ndk{latest version}”
[like] WeiYaPeng(Jim) reacted to your message:
From: Wang Zhi @.> Sent: Tuesday, August 29, 2023 4:58:33 AM To: golang/go @.> Cc: Subscribed @.***> Subject: Re: [golang/go] x/mobile: Gomobile is not compatible with modern Android SDKs and NDKs (Issue #52470)
It’s better to add description for -androidapi to gomobile help bind so people using API level greater than 16 won’t encounter incompatible problems.
— Reply to this email directly, view it on GitHubhttps://github.com/golang/go/issues/52470#issuecomment-1696766610, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAKTSGIJR4KH6Q4CUABGDFDXXVZHTANCNFSM5T76SGTQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>
I believe this is issue is fixed; gomobile now uses the modern environment variables and selects a compatible NDK and SDK based on your specified targets. If you are still encountering a problem please provide more details about your setup and invocation.