Search code examples
androidandroid-studioandroid-versionandroid-components

What is the significance of compileSdkVersion in selecting implementations and resources?


I am asking this to confirm my understanding about the use of compileSdkVersion in android.

Android sdk provides the implementation for each version under the path (Your sdk root)/Sdk/platforms/android-(sdk version) .So if you set the compileSdkVersion to say 20 and if you add a class extending Activity in your code , after building apk the apk will be packaged using Activity.class implementation taken from (Your sdk root)/Sdk/platforms/android-20/andriod.jar.

So suppose google adds a method say 'public void f1()' in the Activity implementation in android-22/android.jar and I compile my code with compileSdkVersion 22 and I am calling the method f1() from my code and I am going to run the app in a device with android version 20.

Question 1 : If the method f1() is a java layer method and not something which calls C/C++ implementations , will it run properly in the device?

When I opened the View.class file in my android studio with compileSdkVersion set as 23, I could see in the import list an item 'android.widget.ScrollBarDrawable'.But when I went inside (Your sdk root)/Sdk/platforms/android-23/android.jar I could never find the class 'ScrollBarDrawable' inside widget folder(and I came across many such implementations which are not present in android sdk like this)

Question 2 : So when apk is packaged from where does the apk builder get the implementation android.widget.ScrollBarDrawable.class?

Sorry for my bad english :(


Solution

  • after building apk the apk will be packaged using Activity.class implementation taken from (Your sdk root)/Sdk/platforms/android-20/andriod.jar

    I would phrase it as: your subclass of Activity will be compiled against the Activity.class in that JAR file. Nothing from that JAR is packaged with your APK, with the exception of final static int values and the like that are inlined into the bytecode.

    If the method f1() is a java layer method and not something which calls C/C++ implementations , will it run properly in the device?

    No, if that method does not exist on the older device.

    So when apk is packaged from where does the apk builder get the implementation android.widget.ScrollBarDrawable.class?

    The "apk builder" neither knows nor cares about such a class, as that class is not in the Android SDK.

    On the device, a different JAR is part of your app's classpath, that contains the actual implementations of Activity and so forth. Whether that JAR contains a hidden android.widget.ScrollBarDrawable will vary by OS release, presumably.