You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter应用编译为APK/AAB后部分功能失效问题求助

Flutter编译APK/AAB后部分功能失效问题

我开发了两个Flutter应用,在Android Studio中运行时一切正常,但将其编译为APK或AAB格式后,在模拟器及真机上测试时,应用的部分功能无法正常使用。我怀疑问题源于Gradle配置,以下是我的Gradle及pubspec配置代码:

Android\build.gradle

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

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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

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

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

app\build.gradle

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,请在local.properties文件中通过flutter.sdk指定其位置。")
}

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"

android {
    compileSdkVersion 33
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

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

    defaultConfig {
        // TODO: 指定你自己的唯一应用ID。
        // 你可以更新以下值以匹配你的应用需求。
        // 更多信息,请参考:https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration。
        applicationId "com.iakbas.welat.question_solver"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: 为发布版本添加你自己的签名配置。
            // 目前使用调试密钥签名,这样`flutter run --release`可以正常运行。
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    api 'com.google.firebase:firebase-ml-vision-image-label-model:17.0.2'
}

pubspec.yaml

name: text_extract_google_mi_kit
description: 一个新的Flutter项目。

publish_to: 'none' # 如果你想发布到pub.dev,请删除这一行。

# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# 产品版本和文件版本使用该字段,build-number用作构建后缀。
version: 1.0.0+1

environment:
  sdk: ">=2.12.0 <3.0.0"

# 查看可用版本,运行 `flutter pub outdated`。
dependencies:
  flutter:
    sdk: flutter

  # 配合CupertinoIcons类使用iOS风格图标。
  cupertino_icons: ^1.0.2
  google_ml_kit: ^0.7.2
  http: ^0.13.5
  camera: ^0.10.0
  permission_handler: ^8.2.2
  image_crop: ^0.4.1
  flutter_lints: ^2.0.0
  lottie: ^2.3.2
  google_mobile_ads: ^3.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter

  # 下面的"flutter_lints"包包含一组推荐的代码规范检查规则,
  # 用于鼓励良好的编码实践。该包提供的规则集在项目根目录的
  # `analysis_options.yaml`文件中启用。查看该文件了解如何禁用特定规则
  # 或启用额外规则。
  flutter_lints: ^2.0.0
# 关于该文件中通用Dart部分的信息,请参考:
# https://dart.dev/tools/pub/pubspec

# 以下部分是Flutter包特有的。
flutter:

  # Material图标类。
  uses-material-design: true

  # 要向应用添加资源,请添加assets部分,如下所示:
  assets:
    - assets/icons/keyboardicon.png
    - assets/icons/listicon.png
    - assets/icons/settings64.png
    - assets/animations/aiautomation.json

内容的提问来源于stack exchange,提问作者ibrahim akbas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 14:37:07