gradle Flutter构建apk --Flutter3.3.10后释放不起作用

eh57zj3b  于 2023-01-13  发布在  Flutter
关注(0)|答案(2)|浏览(190)

flutter升级到3.3.09,然后升级到.10版本构建仅停止处理本地通知包中的问题,在Gradle和Kotlin中进行了许多许多编辑之后,我停止了包中的错误,并弹出了一个新的错误我尝试了每一种可能的Gradle。检查Here和这里和Here尝试获得一个可能的工作组合没有运气,没有修复发现堆栈溢出帮助。
安卓/Gradle

buildscript {
    ext.kotlin_version = '1.5.32'
    repositories {
        google()
        jcenter()
        google() 
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        google()
    }
}

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

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

应用程序/升级版

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 GradleException("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'
}

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

apply plugin: 'com.google.gms.google-services' //this line

android {
    compileSdkVersion 33

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

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.laamarRose.laamar_distribution"
        minSdkVersion 21
        targetSdkVersion 31
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            
            signingConfig signingConfigs.debug     

            minifyEnabled true
            

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 

        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation platform('com.google.firebase:firebase-bom:29.0.3')
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-analytics'
}

gradle-wrapper.properties 例如
错误

* What went wrong:
Execution failed for task ':app:compileReleaseKotlin'.
> 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 15m 52s
Running Gradle task 'assembleRelease'...                          955.0s

┌─ Flutter Fix ───────────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project requires a newer version of the Kotlin Gradle plugin.                              │
│ Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then update │
│ D:\LaamarRose\Projects\Trust-Fund\trustfundapp\android\build.gradle:                                │
│ ext.kotlin_version = '<latest-version>'                                                             │
└─────────────────────────────────────────────────────────────────────────────────────────────────────┘

我想让发布构建再次工作,而不删除任何更多的软件包尝试了多个Stackoverflow解决方案和谷歌和其他Scources没有运气

编辑#1当设置扩展Kotlin_version = '1.6.10'时得到这个

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lintVitalRelease'.
> Could not delete old build\app\reports\lint-results-release-fatal.html

尝试第二次显示此错误'

Could not resolve all artifacts for configuration ':flutter_local_notifications:debugUnitTestRuntimeClasspath'.
xwbd5t1u

xwbd5t1u1#

请尝试更改您的**Kotlin Version**希望它对您有帮助。并重新构建flutter build apk --release命令,我只是在我的机器上测试
形式

ext.kotlin_version = '1.5.32'

ext.kotlin_version = '1.6.10'

成功生成结果后

Running Gradle task 'assembleRelease'...                          122.9s
√  Built build\app\outputs\flutter-apk\app-release.apk (42.6MB).

6tdlim6h

6tdlim6h2#

尝试只执行flutter build apk,它也会生成app-release.apk。
位置:build/app/outputs/flutter-apk/app-release.apk
我也在使用flutter v3.3.10。对我很有效。
编辑:
我使用ext.kotlin_version 1.7.20,如下所述。也许您需要将您的build. gradle更新到一个较新的版本。另外,将jcenter()替换为mavenCentral(),因为JCenter Maven存储库不再接收更新。

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

    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.14' // this is for firebase
    }
}

在构建发布版apk之前,也要执行flutter clean并使IDE的缓存无效并清除缓存。

相关问题