罠
- 一度、最新や新しめの AndroidStudio を入れると、ライブラリのバージョンが上がってしまう。そのため、後から古い AndroidStudio を入れても、最新のライブラリを使おうとして動かないプロジェクトを作成してしまう。
- 古い AndroidStudio で新規作成したプロジェクトでなければならない(という結論に私は至りました)
-
Suggestion: use tools:overrideLibrary="android.support.v7.appcompat" to force usage
とエラーメッセージに出るのですが、それを入れていっても最終的にクラスが定義されていないエラーが出てしまう。
関連エラー等メモ
FragmentManagerImpl が見つからないエラー
java.lang.NoClassDefFoundError: android.support.v4.app.FragmentManagerImpl
SDK Versino を落としすぎたときに出たエラー
Configuration on demand is an incubating feature.
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to C:\Users\xxxxx\AppData\Local\Android\Sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
対応方法
AndroidStudio 2.3.3 で新規作成したプロジェクトの build.gradle (Module app) を編集します。
ここに書かれているバージョン情報を下記のように変更します
私は、
* compileSdkVersion 25
* targetSdkVersion 25
* compile 'com.android.support:appcompat-v7:25.3.1'
が対象でした
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "31.0.0"
defaultConfig {
applicationId "xxx.xxxx.xxxxxxxxxx"
minSdkVersion 10
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}