李刚的《疯狂Android-Java版》,直到2020年1月,还是有非常多的小错误没有改正。其中很多错误很直接阻止你的程序运行。
比如其书中的例子:3.6,当你一旦运行,就会报出:
Cleartext HTTP traffic to www.crazyit.org not permitted错误。
由于时间紧迫,最简单的修改方式,是修改build.gradle文件如下:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "org.crazyit.event"
minSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
然后,就可以运行。