Neither the minSdkVersion
nor the targetSdkVersion
are used to determine the source code compatibility for compilation. The determinant for source compatibility and compilation is both the compileSdkVersion
and buildToolsVersion
.
I used a gradle file with the following values:
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
// Other settings
defaultConfig {
applicationId "com.example"
minSdkVersion 8
targetSdkVersion 23
// Other default settings
}
}
A snippet of the code specifically used for test is:
public void onCreate(Bundle bundle) {
...
List<String> strings = new ArrayList<>();
strings.add("John Doe");
strings.add("Jane Doe");
strings.add("Bill Gates");
strings.add("Mark Zuckerberg");
ListView listView = (ListView) findViewById(R.id.list);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_gallery_item, strings);
listView.setAdapter(adapter);
...
}
When you change the build tools to buildToolsVersion = '17'
you get an error message:
The SDK Build Tools revision (17.0.0) is too low for project ':app'. Minimum required is 19.1.0
When you change this to buildToolsVersion = '19.1.0'
, the build is successful.
When you set the compileSdkVersion
to any value less than the buildToolsVersion
major value, build fails, mainly due to missing resource dependencies.
Setting the minSdkVersion
and targetSdkVersion
to any version below the compileSdkVersion has no effect.
P.S. 1. Major value is the first integer before the first dot. e.g. buildToolsVersion '23.0.2'
has major value is 23.
P.S. 2. I tested the results of a successful build with a real device with Android API Level 10, (Gingerbread 2.3.6). I set source code compatibility to JDK 7, and used the Diamond Operator introduced in Java 7.