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: Gomobile is not compatible with modern Android SDKs and NDKs #52470

Closed
bemasc opened this issue Apr 21, 2022 · 22 comments
Closed

x/mobile: Gomobile is not compatible with modern Android SDKs and NDKs #52470

bemasc opened this issue Apr 21, 2022 · 22 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

@bemasc
Copy link
Contributor

bemasc commented Apr 21, 2022

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-bundle is 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.

@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Apr 21, 2022
@gopherbot gopherbot added this to the Unreleased milestone Apr 21, 2022
@bemasc
Copy link
Contributor Author

bemasc commented Apr 21, 2022

Proposed fix at https://go-review.googlesource.com/c/mobile/+/401574

@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 22, 2022
@thanm
Copy link
Contributor

thanm commented Apr 22, 2022

Thanks for the report.

@gopherbot
Copy link

Change https://go.dev/cl/401574 mentions this issue: x/mobile: modernize handling of Android SDK and NDK paths

@hyangah
Copy link
Contributor

hyangah commented May 4, 2022

Thanks for the report and change.

What is the alternative to ANDROID_HOME now? From the latest android doc, I see ANDROID_HOME is still listed as the primary environment variable to control the location of android SDK. (ANDROID_SDK_ROOT is deprecated)
https://developer.android.com/studio/command-line/variables
Screen Shot 2022-05-04 at 9 19 15 AM

@changkun
Copy link
Member

changkun commented May 4, 2022

What is the alternative to ANDROID_HOME now?

The CL 244057 is relevant to this question, which may help CL 401574 further improve in updating to the latest conventions.

@elevenfive
Copy link

Thank you, I had opened a PR to solve this a different way, but can close this now.

https://go-review.googlesource.com/c/mobile/+/395354

@yash10019coder
Copy link

yash10019coder commented Jun 30, 2022

Proposed fix at https://go-review.googlesource.com/c/mobile/+/401574

@bemasc I am unable to find the solution this is just a simple pull request along with some change logs

@davidrenne
Copy link

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/basic

And 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)"

  1. Shouldnt the home page of the wiki specify which version and how to install the NDK?
  2. Why did the go-review link above have the status of "abandoned". Shouldnt this be an effort to keep up with the toolchains of NDK so gomobile works on the latest stuff?

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?

@bemasc
Copy link
Contributor Author

bemasc commented Aug 3, 2022

@davidrenne If you don't need API 16 support, you can add -androidapi 19 and stick with the latest NDK.

@ncw
Copy link
Contributor

ncw commented Aug 3, 2022

I've come across this too recently because of this change in GitHub actions for the ubuntu image actions/runner-images#5930

Android NDK 21 will be replaced in favor of 25 on August, 1st

What is happening I think is that gomobile is now finding the newer SDK which it doesn't understand without -androidapi 19.

I added -androidapi 19 to the build and all was well so I think this is an acceptable fix.

@justinmichaelvieira
Copy link

justinmichaelvieira commented Aug 11, 2022

I added -androidapi 19 to 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.

image

@Duvio
Copy link

Duvio commented Mar 28, 2023

Any updates on this? This issue has now been there for one year, there is a proposed fix and it still is not resolved.

@Dorbmon
Copy link

Dorbmon commented Jun 10, 2023

Anything new?

@bemasc
Copy link
Contributor Author

bemasc commented Jun 12, 2023

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.

@yfwz100
Copy link

yfwz100 commented Aug 29, 2023

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.

@jimwei
Copy link

jimwei commented Aug 29, 2023 via email

@alirezaac
Copy link

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 1
so 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.

@SebastienMelki
Copy link

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

@emadpoursina
Copy link

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

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}"

@eferay93
Copy link

I executed "gomobile build -target=android -androidapi 24" which seems fixed the problem, but this time I have trouble during build as below

gomobile: go build -buildmode=c-shared -o C:\Users\eferay\AppData\Local\Temp\gomobile-work-1490098852\lib\armeabi-v7a\libbasic.so golang.org/x/mobile/example/basic failed: exit status 1

runtime/cgo

cgo: C compiler "C:\Program" not found: exec: "C:\Program": file does not exist

I have installed "TDM-GCC-64" and did many environment variable settings, but still I am missing something, any help would be appreciated.

@justinmichaelvieira
Copy link

justinmichaelvieira commented Jan 29, 2024

@eferay93 that's a windows platform issue - clearly you've put in a path somewhere that needs to be "quoted". Windows command line often needs paths with spaces included to be within double quotes, this is not an issue related to gomobile . See: https://learn.microsoft.com/en-us/troubleshoot/windows-server/deployment/filenames-with-spaces-require-quotation-mark

@igadmg
Copy link

igadmg commented Feb 28, 2024

Still having a problem with deprecated api version
I tried gomobile build -target=android -androidapi 26 golang.org/x/mobile/example/basic and other versions of -androidapi but the resulting apk is always targeted for version 16, at least that is how android emulator complains.
Have latest NDK 26.2.11394342 installed


APK Installer

The APK failed to install.
Error: INSTALL_FAILED_DEPRECATED_SDK_VERSION: App package must target at least SDK version 23, but found 16

OK

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