I am not fully certain that I am not making any mistakes when setting API level when developing under Eclipse so here are some examples which I am not 100% certain about.
When developing Android app in Eclipse I always set BuildProjectTarget under Eclipse and android:targetSdkVersion in the manifest to the latest available Android version. Is this practice correct? NOTE:I do set android:minSdkVersion according to the project (usually value is 10)
I know that doing the above will trigger Eclipse warning about unsupported API when using something not available in version under android:minSdkVersion (for example using fragments without support library) are there any examples when these shouldn't be trusted and what will happen if you build the project using Gradle/Ant script or manually?
What would happen if I set BuildProjectTarget and android:targetSdkVersion to for example 16 and then use some deprecated API like WebView setCertificate() (which was deprecated in API level 17). Will this method work on all devices or just those up to Android 4.1, will it crash the app or just be ignored?
I know that Eclipse uses Java library android.jar from SDK/platforms folder and that when on the device app links to that library stored on device but what I don't get is are there multiple versions of this library on android phones or just one (the latest for that android version) ? Also does a version of framework.jar play a role in this?
What happens with the libraries when you use something like google_play_services? Are these packed into the apk or reference the library that is already on the device? I know that when you use Facebook sdk the jar gets packed into apk but don't know are these google libraries different?
Yes this practice is correct and is done to ensure support for the latest android versions.
When you set a minSdkVersion, then that's thr lowest version of Android your app will support and compiling with ant/gradle will show errors ehen you will use methods introduced in newer api levels for an older one.
Deprecated means that another method has replaced this one and that this one will spon be removed from the Android source code, so developers are encouraged not to use them. But yes they will work until they remain in the source.
The android.jar is a dependency of the methods and stuff included in the android OS, stuff that you'd be able to call and no I don't think framework.jar plays a role in this.
All external libraries are referenced and added to the apk. BUT only some of the google ones, those that are not primary. (Take a look at the gapps packages, that'll give you some specifics. Link: http://goo.im/gapps)
I hope I got this right and helped you to understand.
When developing Android app in Eclipse I always set BuildProjectTarget under Eclipse and android:targetSdkVersion in the manifest to the latest available Android version. Is this practice correct? NOTE:I do set android:minSdkVersion according to the project (usually value is 10)
Yes. That way you ensure you're always using the latest build sdk.
I know that doing the above will trigger Eclipse warning about unsupported API when using something not available in version under android:minSdkVersion (for example using fragments without support library) are there any examples when these shouldn't be trusted and what will happen if you build the project using Gradle/Ant script or manually?
Just make sure that older devices will not get to that part of the code, using Build.Version.SDK_INT. This will give you the current SDK of the device.
What would happen if I set BuildProjectTarget and android:targetSdkVersion to for example 16 and then use some deprecated API like WebView setCertificate() (which was deprecated in API level 17). Will this method work on all devices or just those up to Android 4.1, will it crash the app or just be ignored?
Deprecated methods will continue to work, but better alternatives are available. When you have the option to use that better alternative, use it. When you're supporting devices that don't have this alternative yet due to older versions, continue using the deprecated method. You might have to do some if else branching based upon the Build.Version.SDK_INT value.
I know that Eclipse uses Java library android.jar from SDK/platforms folder and that when on the device app links to that library stored on device but what I don't get is are there multiple versions of this library on android phones or just one (the latest for that android version) ? Also does a version of framework.jar play a role in this?
The newer devices contain the code of the older devices. Therefore it is not necessary to keep references to other versions.
What happens with the libraries when you use something like google_play_services? Are these packed into the apk or reference the library that is already on the device? I know that when you use Facebook sdk the jar gets packed into apk but don't know are these google libraries different?
The class files in the jar will be packaged in the .apk. The Google Play Services on the device communicates with your app using those classes.
Related
I use the following play services library in my android project. play-services-location,play-services-auth and play-services-gcm. The library are in version 9.2.0.I have the minSdkVersion as 9.
I recently added the VerifyApps API into the project and in order to use that library properly I had to add a new dependency com.google.android.gms:play-services-safetynet:11.6.0. When I added it, android studio asked to enter some class paths in myAndroidManifest file or else I had to improve my minSdkVersion to 14. After adding it some of the functionalities provided by the authAPI started acting up throwing some runtime exceptions in devices running Android 5.0 and above.
I upgraded my Auth and GCM API to version 11.6.0. Android studio again asked me to enter some more class paths in AndroidManifest file. After this the app is working fine but I came across this doc. According to this doc if I am using a play-service version greater than 10.2, my app will not work on devices below 4.0 (Correct me if I am wrong, But a careful look at the wordings lead me to believe that only the support is stopped but existing API calls will work just fine). But I am not using the full play-service dependency in my project I am just the aforementioned 4 libraries, so by adding the suggested entries in the AndroidManifest files should let my app to work just fine in devices below version 4.0 right?
If the functionalities are not fully supported then, is there a list of functionalities that will be affected by upgrading to this version?
You can create a special flavor for older platforms, and use it with an older version of gms. You will deploy the two flavors as split APKs to Play Store.
When I create a Universal Blank App and attempt to upgrade my NuGet packages, it tells me
Could not install package 'Xamarin.Android.Support.v4 25.1.0'.
You are trying to install this package
into a project that targets 'MonoAndroid,Version=v6.0',
but the package does not contain any assembly references
or content files that are compatible with that framework.
For more information, contact the package author.
I understand that I need an older version of Xamarin.Android.Support.v4, but I couldn't find any reference guide on which is the latest version of the NuGet package works for my build. Is there a place I can look to find this information ?
You can look at NuGet.org.
This error message is telling you that it requires MonoAndroid 6.0 to install into. This means that you need to set your <TargetFrameworkVersion> to 6.0 or higher. This is also synonymous with setting your Android version to compile against 6.0.
https://developer.xamarin.com/guides/android/application_fundamentals/understanding_android_api_levels/#framework
Please note that you can support APIs all the way back to whatever your MinSdkVersion is set to. It is not dependent of your TargetFrameworkVersion, as this is a common misunderstanding.
https://developer.xamarin.com/guides/android/application_fundamentals/understanding_android_api_levels/#minimum
My advice is to compile against the latest API version and to set your minimum API version to the lowest level you need to consider. You can read more about that here.
https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#considerations
Finally to see a historical version history of this library, you can simply search on NuGet.org:
https://www.nuget.org/packages/Xamarin.Android.Support.v4/
Please note that you will most likely need to download the lib via the download button on the side, extract the nupkg and view inside the lib folder which will be named the respective target you need.
First some premises:
Android applications make use of Android SDK API classes.
A class definition is some code or parts of code, which gets compiled into machine code/bytecode.
I assume that all (or most of) the classes/packages that make up Android SDK API are listed under:https://developer.android.com/reference/packages.html
https://developer.android.com/reference/classes.htmlWhich is a lot!
Now the question:
Where do these codes/data reside? Are they compiled along with the application code into the APK file or do they exist inside the Android OS on a device, in which case the application should dynamic-link to them?
If they're present on the device, then what difference does it make to compile the application with newer Android SDK versions (per compileSdkVersion in Android Studio for example)?
Let's say the "Android SDK Build-Tools" (which is not the same as "SDK Platform" (according to "SDK Manager" window!) and has its own versioning) takes care of compiling your code and therefore newer version mean better bytecode optimization and faster JAVA -> DEX translation!?
Does "SDK Platform" which you compile your android application against and set it's version with compileSdkVersion keyword, contain solely class declarations and reference-symbols?!
What about Google APIs (e.g. Google Maps API)?
What about Android Support Library?
The Android SDK code is baked into the device, and is not part of your apk.
Stuff you need to include via gradle compile gets into your apk (e.g. Support Library)
The Android core SDK classes are provided by the Android runtime instance that runs per App, you might call it the Android virtual machine if you will. When your App needs to load a specific Android framework class, a Classloader will load it for you in a process similar to dynamic-link as you mentioned.
There is not much you can do to change the version of the framework running on the device. However, the reason you need to specify the different minimumSdk and targetSdk, is for the lint/compiler tools to indicate you what functions/apis might not be present at runtime in specific framework versions. Based on this information you provide wrappers/adapters or simply if/else logic to provide an alternative functionality or simply to avoid a ClassNotDefinedException or MethodNotFoundException at runtime. It is basically a dev tool to help you visualize what could be wrong with other versions different from the one you are compiling against.
Certainly when you compile it, it produces references-symbols in a similar way as if reference an included library. The VM Classloader will resolve the actual file to load at runtime. Not quite sure how Google Apis work but it might be provided as well, in the case of the support library it gets included as far as I know.
I want to create a Java library like SLF4J which can run since certain Android version (e.g. Froyo/2.2).
The thing is, I can't be sure if some methods I use are already available on that Android version. For example, "String".isEmpty() is not available in Froyo. How should I know this, unless I create the library project as Android Library project?
Making the project as an Android library project is not easy to test. Robolectric is also tricky with Gradle.
I'm expecting something like simple Java Maven project which uses subset of Java API available in certain Android version. Is it possible? Like, I create a new SLF4J library without involving non-existent methods in Android.
Thanks
It's possible that there are differences between the Android SDK and other Java APIs, so if you build and test your code as anything other than an Android library, you may miss problems. For example, just the other day I found a bug in API 19 (Android 4.4) where DecimalFormat produces BigDecimals differently than it does in J2SE SDKs.
But if you must do this, the easiest way is probably to create it as an Android library project and build it against the Froyo SDK to ensure all the methods are available. Then take the same code and create different build files to build it for your preferred test framework.
I'm really getting confused by the 3 things. Although i found some threads discussing about these things. But none of them can make it super clear for me to understand what's really going on.
what does it mean by setting android build target in eclipse?
there's some people saying "it means eclipse will build your application against the build target". Then what does it really mean by "build your application"?? does it mean eclipse will only compile my application with the android library of that build target, if it find some methods or classes which is not in that android library, it won't compile successfully???
in my project, I'm referencing the sherlock action bar open source project, in the manifest file of sherlock project, it specifies the minisdkversion = 11, But my application is supposed to support api level 8 ( android 2.2 ). Then what will happen? my application will still run correctly on device with api level 8? or won't be able to installed on those devices?
Even if it can run on device of api level 8, why it's allowed? My referencing project saying it'll can only run on device whose api level >= 11.
why I can use APIs not exists on the old device if i use the android-support-v4 package, like fragment ( introduced in api level 11 )??? I mean I know when I'm writing code, I imported the jar file, so it'll compile. But when it's on my real device, say, my HTC desire. the OS 2.2 doesn't know what's fragment class, how it's gonna work?
Somehow I guess the support-v4 package code is also compiled and "installed" on the old version device, so that when the application run, it'll automatically find the fragment class code and execute it correctly. If it's like that, please tell me what did i do in configuration makes the support-v4 package will be transported and installed on the real device.
4.what does the AVD target mean?? does it mean what OS version is installed on this emulator?