我在api等级为16的Android模拟器上运行这样的代码:
package darklord.compilesdkversiontest;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.test);
int result = linearLayout.getPaddingEnd();
Log.e("Test", result+"");
}
}
getPaddingEnd是在api级别17中添加的,所以我希望这会在模拟器上崩溃。 Android Studio确实有一个警告,但它确实在模拟器上编译和运行。此外,它甚至可以打印出正确的填充值。那么为什么它不会抛出一些运行时期望呢?这是build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "darklord.compilesdkversiontest"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}