1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AndroidStudio 新旧build:gradle設定(昔のアプリを何としても動かす)

Last updated at Posted at 2025-01-30

昔のProjectでbuildが通らない。
そんな解決。
難しい説明はなし、こうすればいいとだけ。誰か言語化してください。
(ClassicUIを使用していますがLadybug Feature Drop | 2024.2.2の最新Verです)
うまくIDEをアップデート出来ない場合、完全クリーンにした方が早いかもです(暴論)

昔のパッケージを開いてみる

フォルダが真っ赤。
これでは最新版AndroidStadioの恩恵がない。
(塗りつぶしはパッケージ名)
スクリーンショット 2025-01-30 102953.png

Buildでエラーを確認

スクリーンショット 2025-01-30 103632.png

Could not install Gradle distribution
Gradle ディストリビューションをインストールできませんでした

6.7.1が必要?本当??いやそうだけども他にも方法があるはず。

project structureを見てみる

間違いなく古い。

スクリーンショット 2025-01-30 104308.png

ならば現在の状態(最新)を目指すだけ

Android Gradle Plugin Version Gradle Version
以前 4.1.3 (4.1.0 以降) 6.7.1 (6.5以降?)
最新 8.8 8.10.2

解決法

Settingsの確認
デフォルトでいい

スクリーンショット 2025-01-30 105612 2.png

1.build.gradleを開く

スクリーンショット 2025-01-30 102953 2.png

kotlin_versionとbuild:gradleを現状と合わせる

build.gradle
buildscript {
    //ext.kotlin_version = "1.4.32"←以前
    ext.kotlin_version = "1.9.24"
    
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        //classpath 'com.android.tools.build:gradle:4.1.3'←以前
        classpath 'com.android.tools.build:gradle:8.8.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

2. gradle-wrapper.propertiesを開く

スクリーンショット 2025-01-30 110123 3.png

gradle-wrapper.properties
#Fri Oct 01 08:55:20 JST 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

#ここでエラーで見たdistributionUrlがいる

#下記がいけない
#distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
#現状に書き換える
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip

3.読み込み確認

これで一旦Sync Nowを押してみる。
AndroidのProjectフォルダと認識し赤みが消えている。
スクリーンショット 2025-01-30 112101 2.png

4.仕上げ

namespaceが変わったり、記述自体が変わったり、非推奨となる場所が赤く表示されるようになるので根気強く修正しよう。

build.gradle
android {
    //以前の書き方
     //compileSdkVersion 31
    //buildToolsVersion "30.0.3"
    compileSdk = 31
    //archivesBaseName ="com.example.アプリ名"
    namespace ="com.example.アプリ名"
     defaultConfig {
        applicationId "com.example.アプリ名"
        minSdk = 28
        targetSdk = 31
        versionCode = 1
        versionName = "1.1"
        //以前の書き方
//        minSdkVersion 28
//        targetSdkVersion 31
//        versionCode 1
//        versionName "1.1"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

成功すると綺麗に書き換わっているのが確認できる

スクリーンショット 2025-01-30 124603.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?