Compiled version vs. Minimum required version Android

不羁的心 提交于 2019-12-07 10:56:49

问题


In my custom view I'm using the method drawTextOnPath(...) which is not supported for hardware acceleration until 4.1.

So I wanted to add an if statement which checks the current Android version on runtime and turns the hardware acceleration on if this version is greater or equals to 4.1. My problem is that I compile my project with Android 4.0 SDK (which is my minimum version), so I don't have the Build.VERSION_CODES for Android 4.1.

Should I compile my project with 4.1 although my minimum version is 4.0 ?


回答1:


I wrote that up once: Android targeting system

Important parts:

When compiling a Java application with a Java 7 compiler, you can’t use it with a Java 6 interpreter. The interpreter will tell you, that it can’t interpret the produced byte-code, even thought you’re not using any Java 7 language features. If you want to compile with the latest compiler but make your byte-code runnable on older JVM instances, you’ll need to tell the compiler to do so (using the -target-flag).

In Android, you can declare what platform-versions you support in your manifest-file, using the <uses-sdk>-element and it’s android:minSdkVersion and android:targetSdkVersion-attributes. The difference between those “targeting mechanics” is, that Android does not care against which platform version the application was compiled.

If you declare your application to be compatible with API Level 4, Android will happily install it, even if you compiled it against Android 4.1 (API Level 16).

So in short:

  • If you want your application to work with the newest Android platform, build against it.
  • Use minSdkVersion to declare the lowest API Level which is supported by your application.
  • As your targetSdkVersion, use the API Level against which you compiled the application.
  • Use [Android] Lint to check for (possibly) unsupported API calls.
  • Use conditional execution and the @TargetApi-annotation to use newer APIs when available.

When you're building your application with the newest SDK, you'll have all the Build.VERSION_CODES available.




回答2:


Yes, you have to compile against 4.1 if you use 4.1's features, even if you do so conditionally, otherwise compiler will not be able to build your app because it will consider all 4.1 features as invalid (non-existing).



来源:https://stackoverflow.com/questions/15986462/compiled-version-vs-minimum-required-version-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!