Gradle 构建无法生成 .apk 文件。很可能这个文件是在<app_root>下生成的,但是工具找不到它

问题描述 投票:0回答:1

当我尝试构建我的应用程序时,我收到此错误。

以下是一些文件,也许可以帮助您理解问题:

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip

android uild.gradle

buildscript {
    ext.kotlin_version = '1.9.10' // Version de Kotlin
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.1.4' // Version compatible avec Kotlin 1.9.10
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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

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

应用程序uild.gradle

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

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

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

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

android {
    namespace = "com.example.vertbaudet_webview"
    compileSdk = 34 // Mettez à jour cette valeur si nécessaire
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    defaultConfig {
        applicationId = "com.example.vertbaudet_webview"
        minSdk = 21 // Mettez à jour cette valeur si nécessaire
        targetSdk = 33 // Mettez à jour cette valeur si nécessaire
        versionCode = flutterVersionCode.toInteger()
        versionName = flutterVersionName
    }

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

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.13.1'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.8.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.0'
    // Ajoutez ou mettez à jour d'autres dépendances nécessaires
}

flutter {
    source = "../.."
}

设置.gradle

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/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.1.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.10" apply false
    id("org.gradle.toolchains.foojay-resolver-convention") version("0.5.0")
}

include ":app"

我尝试更改distributionURL,更改kotlin版本,com.android.tools.build:gradle版本 添加输出文件的路径

flutter build android-gradle-plugin apk
1个回答
0
投票

我相信如果您的

MainActivity.kt
文件的路径使用了错误的项目名称,就会发生这种情况。确保此路径在您的 android 文件夹中看起来正确,然后重试:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.