How to support devices 1.6 and up? - android

I've just started developing android apps and I am wondering about this right from the start.
Apparently it doesn't matter if you work with API 13 (3.2), you can still support Android 1.6. Is that true?
For AdMob to work, I had to start working with API 13 and have set
target=android-13
Someone please clarify this or point me somewhere to read it.

Apparently it doesn't matter if you work with API 13 (3.2), you can still support Android 1.6. Is that true?
That depends on what you mean by "work with API 13".
Having a build target of API Level 13, as you mention later in your question, simply means that is the version of the Android SDK you are compiling against. You will be able to reference classes and methods that exist on API Level 13 (and earlier). Your app can still run on any version of Android you want.
However:
You cannot call methods that do not exist in API Level 13 when you are not running on an API Level 13 device (and likewise for API Level 12, 11, 10, etc.).
If you wish to support Android 1.x, you cannot even reference classes or methods that do not exist on the device from a class that gets loaded by the VM.
In either of those cases, you will get a VerifyError, and your app will go "boom".
There are strategies for conditionally using newer-API stuff that allow you to avoid trying to use that stuff on older-API devices. Or, just stick to older-API stuff in the first place, even though you won't get compiler assistance to let you know when you are accidentally using newer-API stuff, given that you are using the newer build target.
Or, contact AdMob support and figure out why they need that build target.

In your Manifest file you can put the min sdk version you want to support and your target sdk version, they could be different, to support 1.6 specify android:minSdkVersion="4" as follows
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="13" />

Related

Firemonkey: can we update targetSdkVersion in AndroidManifest.template.xml?

I read that berlin is compatible with marshmallow, but i see that by default in the AndroidManifest.template.xml we have :
<uses-sdk android:minSdkVersion="%minSdkVersion%" android:targetSdkVersion="%targetSdkVersion%" />
i don't know where delphi took the variable to update %targetSdkVersion% but it's seam to be all the time 14 and i don't see any way to configure it
i would like to replace %targetSdkVersion% by 23 (marshmallow api level, to support the app permissions), but is it safe to do so or it's will introduce many other bug ?
FireMonkey was developed to work against a certain range of Android functionality. As you can see from the RAD Studio Platform Status page FireMonkey apps built with Delphi 10.1 Berlin have a lowest supported Android version of 4.0.3, which corresponds to Android API Level 15.
The minSdkVersion field is supposed to be set to the earliest Android version your apps will work with so in truth this should probably be set to 15 but actually is set to 14 (Android 4.0-4.0.2).
If you look back at an Android manifest file generated by Delphi XE7, which supported Android 2.3.3 (API Level 10) it specifies a min SDK version of 9 (Android 2.3-2.3.2), which is the version of Android that introduced the NativeActivity type underlying every Delphi FireMonkey Android app. Again, this seems a little bit out of kilter with what is documented as lowest supported version.
Anyway, minSdkVersion can be used by Google Play store to filter your app out of the listings for someone running a lower version of Android. It is also checked when you install an app on a device; Android won't let you install on a lower version of Android.
targetSdkVersion, on the other hand, indicates what version of Android your app has been tested with and works sensibly with. It can often be higher than minSdkVersion if your your app needs to use features introduced in Android versions later than minSdkVersion.
If you want to use a feature from API Level 23 then sure, you'll need to update that manifest part. Just remove the %targetSdkVersion% template from the Android manifest template file and replace it with the required version.
Problems that you might run into:
You'll either need to check the Android version and, if lower than your targetSdkVersion, not use those features that aren't available or set minSdkVersion to a suitably higher version to ensure the app can only run on devices that have the features you wish to use.
FireMonkey code not aware of differing behaviour in API Levels may
function adversely. In your case you may get issues because of the
different runtime permissions behaviour enabled in API Level 23.
Actually I can't currently think of any more issues, though a good amount of testing is recommended. You might have more to think about in a regular Android app using visual activities and so on, when different API levels may affect the theming or other UI elements. You can see the various things that change when you target target SDK versions on this Android documentation page.
By the way, the use of the SDK Manager in the Tools. Options... dialog is entirely irrelevant to the question of how to update the value in the generated manifest file. The only evident way to change it is to manually edit the Android manifest template file as per the documentation, and mentioned in a comment.
The only relevance of the SDK Manager is that the default Android SDK installation for Delphi 10.1 Berlin installs the Platform libraries for API Level 22. If you want to use a feature from API Level 23 you might think that updating those platform libraries might be necessary, but of course if you're doing the coding in Delphi then you're (presumably) actually just compiling against import definitions of the features in that higher API level, and so whether or not those features are contained in the android.jar file is of no consequence.**
** I'm happy to be proved wrong on this count, but I have never observed a connection between the manifest and what the SDK Manager is set up against.

I don't Understand Call or Class Requires API Level 3

I'm doing some Android work in IntelliJ 13. I've created an Android test application so I can start writing unit tests. IntelliJ is reporting an error I haven't seen before and this error does not prevent the code from working:
Call requires API level 3 (current min is 1)
It will also have an error at the class level that is:
Class requires API level 3 (current min is 1)
And sometimes it will say level 11.
You need to set min SDK version in AndroidManifest like
<uses-sdk android:targetSdkVersion="18" android:minSdkVersion="11"/>
As Josef said, you need to increase the minimum SDK version specified in your AndroidManifest.xml file - this is the minimum Android API version you support. The error messages you're getting ("requires API level 11") mean that the method or class you're trying to use was only introduced in API 11. There are ways around this - specifically, the support library is an official back-port of many newer features, included in your SDK.
Have a look at the Android Dashboards to choose a minimum API level (and hence your device/userbase coverage) - typically 8 or 10, if you plan on supporting "older" devices (Android 2.2 and 2.3 devices), and 14 or 15 if you plan on supporting only newer (Android 4.x) devices.
Generally you'd specify your targetSdkVersion to be the latest version of Android - at the moment, this is 19. You need your SDK up-to-date, though.
The developer documentation has an in-depth explanation of what these things mean - I'd recommend having a read.
If after making above changes you still have an issue, please use File > Invalidate Caches / Restart. Here it explains what it does. In case you don't read that, summary warning:
Cleaning system caches also results in clearing the local history. To
avoid losing data, check in the changes to your version control system
before invalidating caches.

Android and Eclipse: minSdk and compileWith

Well, I think that is not well explained and right now I'm a little bit confused. From this link:
Compile With is the platform version against which you will compile
your app. By default, this is set to the latest version of Android
available in your SDK. (It should be Android 4.1 or greater; if you
don't have such a version available, you must install one using the
SDK Manager). You can still build your app to support older versions,
but setting the build target to the latest version allows you to
enable new features and optimize your app for a great user experience
on the latest devices.
From this one instead:
When you are developing your application, you will need to choose the
platform version against which you will compile the application. In
general, you should compile your application against the lowest
possible version of the platform that your application can support.
Now, as they are contradicting themselves, here I'll explain what I've understood: let's say that we compile with api 5. It means that if I run from 1 to 5, my application works but it doesn't for versions > 5. So:
Why I need to set the minSdkVersion if compileWith is set to 5?
What is targetSdkVersion?
The point is: if compileWith is set to the latest version, is it possible to use latest APIs and still have backward compatibility? I'm sure that I'm wrong and I'm missing something. Thank you.
Edit 1
Now I understand more but anyway I'm missing something: let's say that minSdk is 9 and target is 18 (my current sdk). It means that I cannot use anything specific to api 18 unless there's some support package for older versions, right? I'm thinking different: I would compile with the lowest version possible to get forward compatibility. I mean, if you compile a Windows application on Win2000, it will run till Windows 8 but I'm limited to Win2000 apis. If I compile with Windows 8, the backward compatibility should be checked on runtime and I can use Windows 8 apis on Win2000 only with "support packages" (it's an example, obviously). Right?
Edit 2
This is what I'm asking about Android (not about the JVM). Android is mixing forward with backward and I've mixed it more using the Windows example. FIY, It seems that Windows is backward compatible, as explained in the examples here. So, what about Android? It seems that the minSdk version should be tested from the developer, I mean: I should compile with latest version and test my application behaviour till the minimum api level that doesn't change it. So it seems that I need to test the backward compatibility by testing on every api level lower than the one with wich is compiled and they assure the forward compatibility. Right?
I think that I'm mixing forward and backward compatibility definitions. Everytime I read them they seem different.
from the Documentation you can read the following:
android:minSdkVersion
An integer designating the minimum API Level required for the application to run. The Android system will prevent the user from installing the application if the system's API Level is lower than the value specified in this attribute. You should always declare this attribute.
and
android:targetSdkVersion
An integer designating the API Level that the application targets. If not set, the default value equals that given to minSdkVersion.
This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).
And to answer your last question, targeting the latest API will not allow you to execute any newer method or use any newer class on old phones, for that you need to use the support packages, with that you are able to obtain a close result to what you can do in newer APIs.
Hope this gives you a more clear idead of why you have those two values and the difference between them.
UPDATE:
Well about the example of something built for windows 2000 and working on windows 8, is not guarantee that it will work, that is why on windows you have the "run with compatibility" mode, and then you select according to what operating system you want to run it.
This is because maybe both OS (or APIs in this case) have the same method or option, they do it in a different ways or need other permissions. The same happens here, so the target SDK will be the reference frame against you tested and thus it will use that behavior if you run it on newer devides than the taget SDK.
For the APIs between the min and the target they will run as normally they do, and so you can always have a weird behavior and some patching might be need it, normally is most visible on the 2.x to 3.x jump.
UPDATE 2:
Well, let me try to explain it in a different way.
The minSDK will determine which methods and options you can use throughout the application, this means that if a method is only available after that API, you will not be able to use it and instead get an error message.
The targetSDK represents the lastest version of the API that you tested and so, if the phone has a newer API than the one you specified, it will try to behave as it was on the API version you specified, take for example this, in the section Important Behavior Changes:
This inexact batching behavior applies only to updated apps. If you've set the targetSdkVersion to "18" or lower, your alarms will continue behave as they have on previous versions when running on Android 4.4.
So, as you can see there, if you set the targetSDK to a previous API (before 19), it will behave as it use to, but if you target the newest API (at this moment API 19), then it will behave differently.
Hope i was clear enough, if not, please do not hesitate and ask.

Compiling with Android 4.X but supporting API Level 9

I'm working on an application which uses ActionBarSherlock. As it's documentation points out:
[...] the library requires that both it and your project are
compiled with Android 4.0 or newer. The project also requires that
you are compiling with JDK 1.6 in both your editor and any build
systems that you may be using.
So, that means I'll compile my application (and the library) against Android 4.X but in my Manifest, I declare that I'm targeting (e.g.) API Level 9.
This all works fine and well but there is something that disturbs me. From the FAQ:
What API level should I target in my manifest when using the library?
Targetting API level 11 or newer is required as it will cause Android
to automatically add the native action bar when run on newer devices.
Since you will be compiling against new APIs but your app will likely
be run on devices with older versions of Android extra care must be
taken to either avoid using or properly check and call any methods
that were introduced after your minimum SDK version.
That means, that I'll have to manually check every method call, so I don't use any that are not available in my targeted API Level (9 in my case)? This sounds wrong to me.
Is there a way to tell my IDE (IntelliJ), that I'm only using the API Level 9 (so I don't get any auto-completion for non-existing methods/classes and don't use them by accident) and then choose to compile it against another Android version?
Or can I use some automated checks (which run at compile time) to check for that?
The ADT's lint feature should take care of this by warning when API calls are being made for the wrong API version.
You should be compiling both ABS and your project with the latest SDK available (at present, 4.1). Your manifest should have a targetSdkVersion as high as possible (ideally matching your compilation SDK) and your minSdkVersion should be set to the lowest version you support.
Lint is partially integrated with IntelliJ IDEA and is also available as a command line tool.
You temporarily set your target SDK to the various lower ones and debug with it. Your final build then is with the latest SDK.
Set a Build target similar to that you have mentioned in your manifest.
as always , you should set the targetSdk to the maximum available on both the manifest and the project.properties file (as recommended by google on one of their videos) , so that the ADT&SDK would be able to optimize the ADK accordingly.
set the minSdk to the one that you wish to support your app from , and let Lint to tell you if there are any problems in case you use too-new-features.

Relation between android:minSdkVersion, android:targetSdkVersion and "target"

So, I'm a little confused, I thought I understood the meaning of android:minSdkVersion, android:targetSdkVersion and target in project properties.
Right now I got these set to:
android:minSdkVersion="7"
android:targetSdkVersion="13"
And:
target=android-15
in project->properties->Android->Project Build Target.
When I try to run this application application on a device with Android 2.3.3 installed, I see a red cross against the device name but the application runs fine on it none the less.
What am I missing? If I'm building against 15, how is it running on android-7? This confusion stated after I integrated AdMob into my app which states it require minimum SDK level 13.
To describe one at a time:
android:minSdkVersion helps Google Play filter apps for the user based on their device. For instance, with minSdkVersion="7", someone browsing with a device that only supports 6 won't see your app on Google Play, and thus won't download it, find it doesn't work, and leave a bad review :)
android:targetSdkVersion is a signal to the device about which version of the API your app was tested against. New behaviors are often available by default with new versions of the platform, for applications that target at least that version of the platform. For instance, by setting your targetSdkVersion to 11 or higher, you get an overflow menu in the ActionBar (for Honeycomb and up devices) instead of the "legacy menu button of shame".
project.properties target is a signal to your local build system regarding which version of the platform you should be compiling your code against. Generally it's best to just set this to whatever you have set for the targetSdkVersion.
What am I missing? If I'm building against 15, how is it running on
android-7?
Android maintains backwards compatibility for just this reason. When you use API's that were added in version 15 of the platform, obviously they won't be there on a device running an an older device.
However, it's possible (and encouraged) to design your application in such a way as to take advantage of features added on new platforms, but "degrade gracefully" such that your application continues to run on older ones. There's an Android Training lesson on just this topic, called Supporting Different Platform Versions.
android:targetSdkVersion="13" Indicates that this application has been build by keeping the sdk 13 as target, to use its feature to full potential
android:minSdkVersion="7" indicates that it works on sdk 7 and above, but some of its features can be stripped down if certain features are not available in lower sdk. ie(less than sdk 13)
android:minSdkVersion="7" means you can't run this app in devices under 2.1(API-7). android:targetSdkVersion="13" the app is built targetting this API. the build target will be set to 13 and the methods and stuffs that are available till 13 will work.
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

Categories

Resources