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

"Platform version 16 is unsupported by this NDK. Please change minSdk to at least 21 to avoid undefined behavior." #1119

Closed
lukehutch opened this issue May 4, 2024 · 5 comments · Fixed by #1146

Comments

@lukehutch
Copy link

I upgraded Flutter to the most recent beta, and now cronet_http, which depends upon jni ^0.7.3 as a transitive dependency, causes my project to no longer build:

   > A problem occurred configuring project ':jni'.
      > [CXX1110] Platform version 16 is unsupported by this NDK. Please change minSdk to at least 21 to avoid undefined behavior. To suppress this error, add android.ndk.suppressMinSdkVersionError=21 to the project's gradle.properties or set android.experimentalProperties["android.ndk.suppressMinSdkVersionError"]=21 in the Gradle build file.

These lines seem relevant:

https://github.com/dart-lang/native/blob/95d226d290d4d5c583c4e45b04048442f244c656/pkgs/jni/android/build.gradle#L59C1-L64C33

and

minSdkVersion 16

This needs to be bumped to 21 to solve the problem. (Also now minSdkVersion has become minSdk.)

@HosseinYousefi
Copy link
Member

I can't reproduce this error.

$ flutter --version
Flutter 3.22.0-0.3.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 87b652410d (13 days ago) • 2024-04-23 21:41:18 -0500
Engine • revision b4bfd45986
Tools • Dart 3.4.0 (build 3.4.0-282.3.beta) • DevTools 2.34.3

$ flutter create reproduce1119 --platform=android
$ cd reproduce1119
$ flutter pub add cronet_http
$ flutter run

At least for a new project minSdk and other parameters are set to match Flutter's gradle plugin located in $flutterSdkPath/packages/flutter_tools/gradle:

compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion

The default values are defined here.


I could change the minSdkVersion to 21 since it's the same as Flutter, but logically shouldn't it just be the maximum across all the dependencies including your application? So if your application is using current Flutter's default, then it should set it to 21 anyways?

Also, do you have ndkVersion = flutter.ndkVersion in your app/build.gradle? Maybe that downloads the correct NDK version automatically. Otherwise you could download an NDK from Android Studio and see if you still get this error.

@HosseinYousefi
Copy link
Member

HosseinYousefi commented May 7, 2024

Alternatively I could add ndkVersion = android.ndkVersion to package:jni's build.gradle. I'll try removing every NDK on my machine to see if this has an effect on auto downloading...

Prior design doc about this by @dcharkes: http://flutter.dev/go/android-ndk-version

@lukehutch
Copy link
Author

lukehutch commented May 7, 2024

The error is on Flutter beta and master channels, and the issue is they are now starting to warn that linking with NDK projects that are compatible with NDK versions lower than 21 may break things moving forward. It's an error, not a warning, and it stops the build unless you provide the specified override option to suppress it.

No, providing ndkVersion = android.ndkVersion and/or ndkVersion = flutter.ndkVersion does not solve the problem.

@vanyasem
Copy link

vanyasem commented May 7, 2024

In the meantime, a dirty hack to add in android/build.gradle:

subprojects {
    ...
    afterEvaluate { project ->
        if (project.name.equalsIgnoreCase('jni')
                && project.hasProperty('android')) {
            android {
                defaultConfig {
                    minSdkVersion 21
                }
            }
        }
    }
}

@HosseinYousefi
Copy link
Member

OK, I'll publish jni 0.9.2 with minSdk 21.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants