sebastian nielsen
sebastian nielsen

Reputation: 505

How I do prohibit attempting to build for Marshmallow in Android Studio?

Im currently building a app that will, due to the depreciated isBoundKeyAlgorithm(String algorithm) function, that is replaced by the keyInfo.isInsideSecureHardware() function only available in API level 23 (Marshmallow), either work ONLY on API level 18 through 22, OR only on API level 23 and forwards.

I created the project in Android Studio. Then I told the gradle build files to build for a maximum SDK level of 22, and also uninstalled the level 23 API inside Android Studio.

The problem is that this makes the project unbuildable, with lots of errors about missing files that relate to the API level 23.

How can I tell Android Studio that the app Im currently building will not run above API level 22, and it should not try to include any files that are related to API level 23 (it was some "underlined spinner" or whatever was missing)

Upvotes: 0

Views: 300

Answers (2)

piotrek1543
piotrek1543

Reputation: 19361

It seems to be that you uninstalled API 23, but still using build-tools and platform-tools in newest version. Downgrade them also and try to Clean than Rebuild project.

This problem also might be caused that in build folders you have still files accorded to newest Android version. Delete from your project repository 'build' folders.

Hope it help

Upvotes: 0

ianhanniballake
ianhanniballake

Reputation: 200020

Just because a method is deprecated does not mean you cannot build an app with it. Simply guard your call with a check to Build.VERSION.SDK_INT:

boolean isHardwareSecured;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
    isHardwareSecured = KeyChain.isBoundKeyAlgorithm(algorithm);
} else {
    isHardwareSecured = keyInfo.isInsideSecureHardware();
}

You should always compile with the latest SDK as newer versions of the Support Library (i.e., the current version 23.1.1) rely on the newer SDK - that is probably why switching back to compiling with 22 failed.

Upvotes: 1

Related Questions