@miyajima0630

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

flutterに関して環境構築中にエラー...助けてください

解決したいこと

flutterのビルドの際にエラーが出ていて先に進めません。
わかる方いらっしゃいますか?

発生している問題・エラー

PS C:\Users\miyajima\StudioProjects\app> fvm flutter run --flavor dev
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...

FAILURE: Build failed with an exception.

* Where:
Settings file 'C:\Users\miyajima\StudioProjects\yattoruyo_app\android\settings.gradle' line: 2

* What went wrong:
Plugin [id: 'dev.flutter.flutter-plugin-loader', version: '1.0.0'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Included Builds (No included builds contain this plugin)
- Plugin Repositories (could not resolve plugin artifact 'dev.flutter.flutter-plugin-loader:dev.flutter.flutter-plugin-loader.gradle.plugin:1.0.0')
  Searched in the following repositories:
    Gradle Central Plugin Repository

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 813ms
Running Gradle task 'assembleDevDebug'...                          994ms
Error: Gradle task assembleDevDebug failed with exit code 1



または、問題・エラーが起きている画像をここにドラッグアンドドロップ

### 該当するソースコード
```言語名
dart

発生している問題・エラー

Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
e: file:///C:/Users/miyajima/StudioProjects/yattoruyo_app/android/app/src/main/kotlin/cc/sysad/yattoruyo_app/MainActivity.kt:3:8 Unresolved reference: io
e: file:///C:/Users/miyajima/StudioProjects/yattoruyo_app/android/app/src/main/kotlin/cc/sysad/yattoruyo_app/MainActivity.kt:5:21 Unresolved reference: FlutterActivity

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDevDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 12s
Running Gradle task 'assembleDevDebug'...                          13.0s
Error: Gradle task assembleDevDebug failed with exit code 1

### 該当するソースコード
```言語名
dart

fvm flutter --version
Flutter 3.32.8 • channel stable • https://github.com/flutter/flutter.git
Tools • Dart 3.8.1 • DevTools 2.45.1

settings.gralle↓↓

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "com.google.gms.google-services" version "4.3.15" apply false
    id "org.jetbrains.kotlin.android" version "1.9.0" apply false
}

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
//apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
include ':app'

android/build.gralle↓↓


buildscript {
    ext.kotlin_version = '1.9.0'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.7.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.2'
//        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
    }
}


allprojects {
    repositories {
        google()
        mavenCentral()
    }
}



rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.layout.buildDirectory
}


android/app/build.gralle↓↓

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id "dev.flutter.flutter-gradle-plugin"
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'

}


def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

//apply plugin: 'com.android.application'
//apply plugin: 'kotlin-android'
//apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    namespace "cc.sysad.yattoruyo_app"
    compileSdkVersion 35

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        applicationId "cc.sysad.yattoruyo_app"
        minSdkVersion 24
        targetSdkVersion 35
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = "17"
    }


    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }

        develop {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']        }
    }

    flavorDimensions "default"

    productFlavors {
        dev {
            dimension "default"
            applicationIdSuffix ".dev"
            versionNameSuffix ".dev"
            // アプリケーション名を変更したい場合
            resValue "string", "app_name", "(dev)"
            resValue "string", "facebook_app_id", ""
            resValue "string", "fb_login_protocol_scheme", ""
            manifestPlaceholders = [ applicationName: "io.flutter.app.FlutterApplication" ]
        }
        prod {
            dimension "default"
            // アプリケーション名を変更したい場合
            resValue "string", "app_name", ""
            resValue "string", "facebook_app_id", ""
            resValue "string", "fb_login_protocol_scheme", ""
            manifestPlaceholders = [ applicationName: "io.flutter.app.FlutterApplication" ]
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
            signingConfig signingConfigs.debug
        }
    }
}

//flutter {
//    source '../..'
//}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics:21.1.0'
    implementation 'com.google.firebase:firebase-crashlytics:18.2.11'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation "com.android.installreferrer:installreferrer:2.2"
}
//apply plugin: 'com.google.gms.google-services'
//apply plugin: 'com.google.firebase.crashlytics'

gradle-wrapper.properties↓↓

#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip

自分で試したこと

もとのコードは前任から引き継いだのでどのように作っていたかはわかりませんがAPIレベル34までは更新していたようです。
今回やりたいこととしてはAPIレベル35にしたいです。
キャッシュクリアやバージョン変更、などは試してみました。
chatGPTが言うにはMainActivity.ktが壊れている可能性があるとのことですが
原因わかる方いらっしゃいますか?

0 likes

1Answer

上記エラー内容はFlutterActivityという基本的なパッケージの参照エラーですので、
ソースの不備やAPIレベルの差異ではなく環境構築が原因である可能性が高いと考えます。

動作できていた時点との差異がAPIレベルとのことですが、質問者様の環境でAPIレベル34で(前任者の方から全くソースを更新していない状況)の動作実績はありますでしょうか?
ここで動作できていないようであれば、APIレベルの差異ではなく環境構築の差異であると思われます。

様々な原因が考えられるので現時点の情報では特定はできませんが、
settings.gradleの

//apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"

とFlutterプロジェクト旧方式のプラグインロードが消えている割には新方式のpluginManagement{}等の記載がないのが怪しそうな気がします。

下記サイトをご確認いただき
https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply

前任者の方とのFlutterバージョンの差異や
settings.gradleの
pluginManagement { includeBuild("$flutterSdk/packages/flutter_tools/gradle") ... }などをご確認いただければと思います。

0Like

Comments

  1. This comment has been deleted for violation of our Terms of Service.
  2. @miyajima0630

    Questioner

    質問者様の環境でAPIレベル34で(前任者の方から全くソースを更新していない状況)の動作実績はありますでしょうか?
    →こちらに関してはこのアプリに関しては行っていません。flutterのバージョンをfvmで管理していたようでどのバージョンで動作させていたかわからずそれなら最新のflutterのバージョンで修正してしまおうということになりました。
    前任者は

    apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
    

    これで描いていたため上記は非推奨となったそうなので

    plugins {
        id 'com.android.application'
        id 'org.jetbrains.kotlin.android'
        id "dev.flutter.flutter-gradle-plugin"←これ
    }
    

    に書き換えたところ下記のエラーが出てきました。

    FAILURE: Build failed with an exception.
    
    * Where:
    Build file 'C:\Users\miyajima\StudioProjects\app\android\app\build.gradle' line: 4
    
    * What went wrong:
    Plugin [id: 'dev.flutter.flutter-gradle-plugin'] was not found in any of the following sources:
    
    - Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
    - Included Builds (No included builds contain this plugin)
    - Plugin Repositories (plugin dependency must include a version number for this source)
    
    * Try:
    > Run with --stacktrace option to get the stack trace.
    > Run with --info or --debug option to get more log output.
    > Run with --scan to get full insights.
    > Get more help at https://help.gradle.org.
    
    BUILD FAILED in 976ms
    Running Gradle task 'assembleDevDebug'...                        1,229ms
    Error: Gradle task assembleDevDebug failed with exit code 1
    PS C:\Users\miyajima\StudioProjects\app> 
    
    pluginManagement {
        includeBuild("C:/Users/miyajima/flutter/packages/flutter_tools/gradle")
        repositories {
            google()
            mavenCentral()
            gradlePluginPortal()
        }
    }
    
    plugins {
        id "dev.flutter.flutter-plugin-loader" version "1.0.0"
        id "com.android.application" version "8.3.0" apply false
        id "org.jetbrains.kotlin.android" version "1.9.0" apply false
        id "com.google.gms.google-services" version "4.4.0" apply false
    }
    

    このようにも変更してみましたが includeBuildの部分にエラーが出るようで上記は削除しました。

    FAILURE: Build failed with an exception.
    
    * Where:
    Build file 'C:\Users\miyajima\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_plugin_android_lifecycle-2.0.30\android\build.gradle' line: 26
    
    * What went wrong:
    A problem occurred evaluating project ':flutter_plugin_android_lifecycle'.
    > Could not get unknown property 'flutter' for extension 'android' of type com.android.build.gradle.LibraryExtension.
    
    * Try:
    > Run with --stacktrace option to get the stack trace.
    > Run with --info or --debug option to get more log output.
    > Run with --scan to get full insights.
    > Get more help at https://help.gradle.org.
    
    BUILD FAILED in 1s
    Running Gradle task 'assembleDevDebug'...                        2,010ms
    Error: Gradle task assembleDevDebug failed with exit code 1
    
    
      flutter_plugin_android_lifecycle: ^2.0.30
    
    
  3. 環境によるので何とも言えませんが、includeBuildが
    includeBuild("C:/Users/miyajima/flutter/packages/flutter_tools/gradle")
    と固定パスで記載されています。

    C:\Users\miyajima\StudioProjects\app> fvm flutter run
    のパスで実行されているようですのでfvm useを使っているかグローバルで行っているかでまた変わりますが、パスが異なる可能性があるのではないかと思います。
    (どちらにせよgit管理時に固定パスでは他のPCで動作しなくなるので修正自体は必要と思います。)

    その他、状況によりいろいろ考えられますが
    fvm flutter doctor -vで調査頂いたり
    先ほどの公式ガイドを確認していただいたり
    https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply
    あるいは質問者様のPCでfullterバージョン最新の別アプリで動作しているならば、そのgradleと比較していただくのが良いと思います。

  4. @miyajima0630

    Questioner

    ありがとうございます。
    fvm flutter doctor -vで調査したところ
    fvmの方のflutterが壊れてたことが分かりました。
    fvmを使わずflutterの再インストールなど行ったところ解決しました。
    他にもいろいろ試してみたのでこれが効いたのかはわかりませんが...

    Qiita初めての質問でつたない所もあったかと思いますがありがとうございました。

Your answer might help someone💌