はじめてのAndroidアプリ開発(秀和システム)のサンプルプログラムのコンパイルエラーを修正
TECHNICAL MASTER はじめてのAndroidアプリ開発 第2版 Android Studio 2対応
この本は結構良いので、久しぶりにAndroidアプリ開発をするときに見なおそうとしたところ、
サンプルアプリhttps://www.shuwasystem.co.jp/support/7980html/4853.htmlが
最新のAndroid Studioではgradleのビルドエラーで動かないことが判明。
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Affected Modules: app
WARNING: Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Affected Modules: app
WARNING: The specified Android SDK Build Tools version (24.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.3.2.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '24.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
Remove Build Tools version and sync project
Affected Modules: app
どうしたものかと思ったが、gradleファイルを置き換えれば済むとわかったのでそのメモ。
プロジェクトのbuild.gradleを置き換え
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
アプリのbuild.gradleを置き換え
applicationId だけはそれぞれのプロジェクトに合わせて修正すること。
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "to.msn.wings.hello"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
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'
}
以上!