djdance
djdance

Reputation: 3209

NDK 15 breaks serial port library

I've faced with bad behavior of NDK trying to change and rebuild native serial port libs for COM-port. It is well-known old code, you can find it for example here (not mine) https://github.com/NanFengyang/AndroidSerialPort/blob/master/app/src/main/jni/SerialPort.c#L126

Pay attention to the string 126 - it is a point of the issue.

NDK15 surprises me twice:

First, this new warning.

Android NDK: Found platform level in ./project.properties. Setting APP_PLATFORM to android-10. Android NDK: android-10 is unsupported. Using minimum supported version android-14.

Android NDK: WARNING: APP_PLATFORM android-14 is higher than android:minSdkVersion 10 in ./AndroidManifest.xml. NDK binaries will not be co mptible with devices older than android-14. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md for more information.

Next, while opening COM it fails with this:

Configuring serial port

tcsetattr() failed (fd = 40, err = 22)

this is the output of my simple dummy code

    struct termios cfg;
    LOGD("Configuring serial port");
    if (tcgetattr(fd, &cfg)){
        LOGE("tcgetattr() failed (fd = %d, err = %d)", fd, errno);
    }
    if (tcsetattr(fd, TCSANOW, &cfg)){
        LOGE("tcsetattr() failed (fd = %d, err = %d)", fd, errno);
    }

This error occurs only with NDK 15. It succeed with revisions 14b, 13b, 12b ... for people faced with it too - just download old NDK.

Finally, the question. Error 22 is [EINVAL] - "The optional_actions argument is not a supported value, or an attempt was made to change an attribute represented in the termios structure to an unsupported value". Does someone know how to avoid it in new NDK?

Upvotes: 0

Views: 1173

Answers (2)

张俊雄
张俊雄

Reputation: 66

If you use CMake, you should add this code in your module build.gradle.

 externalNativeBuild {
            cmake {
                cppFlags ""
                arguments "-DANDROID_DEPRECATED_HEADERS=ON"
            }
        }

Upvotes: 0

Alex Cohn
Alex Cohn

Reputation: 57203

If you want to use NDK r15:

  1. You can force NDK_MIN_PLATFORM_LEVEL=9 (on ndk-build command line) to avoid the warning. But NDK does not have android-10, and with r15 you should explicitly choose APP_PLATFORM=android-9 on command line. FWIW, you can stay with android-14 unless other parts of your project are not compatible.

  2. You should set APP_DEPRECATED_HEADERS=true, then headers will be exactly same as r14, and you will avoid the bug in unified headers.

There is probably a bug in the unified headers of r15, they only set TCSANOW to TCSETS for MIPS, but not for other ABIs.

The deprecated headers platforms/android-14/arch-arm/usr/include etc. will be removed in r16 later this year, or, if in the worst case, in r17. The android-9—compatible libraries will also probably be gone.

Upvotes: 3

Related Questions