flutter-使用第三方库,编译和运行版本不一致问题

问题:

         使用了第三方库--barcode_scan  ^1.0.0出现了编译和运行不一致问题

         Android dependency 'androidx.XX:XX-runtime' has different version for the compile (1.0.0-rc01) and runtime (1.0.0) classpath.

(如:Android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) classpath. You should manually set the same version via DependencyResolution)

解决:

         在app下的gradle文件下,复制以下代码到你的项目中的gradle,重新运行。如果运行通过恭喜你,不过很可能又出现新的编译问题,如果还是不通过,请继续查阅我下一篇文章。

buildscript {
    ext.kotlin_version = '1.2.51'  //第三方库采用kotlin
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        //依赖kotlin版本
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.2.0'
    }

    subprojects {
        //根据提示使用对应的版本
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.android.support'
                        && !details.requested.name.contains('multidex') ) {
                    details.useVersion "27.1.1"
                }

                if (details.requested.group == 'androidx.core'
                        && !details.requested.name.contains('androidx') ) {
                    details.useVersion "1.0.1"
                }
            }
        }
    }

}

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

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

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

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Flutter 中引入第三方库是通过在 `pubspec.yaml` 文件中声明依赖来实现的。为了将 Flutter 应用程序构建为 Window 和 Mac 桌面应用程序,您需要使用 Flutter Desktop 插件。使用 Flutter Desktop 插件,您可以在 Flutter使用许多现有的桌面,例如 GTK、Qt、Electron 等。 以下是在 Flutter 中引入第三方库的一般步骤: 1. 打开 `pubspec.yaml` 文件。 2. 在 `dependencies` 部分中添加的名称和版本号。例如: ```yaml dependencies: http: ^0.13.3 ``` 3. 运行 `flutter pub get` 命令从网络下载并将其添加到您的项目中。 4. 使用 `import` 语句将导入到您的代码中。例如: ```dart import 'package:http/http.dart' as http; void main() { // 使用 http 的代码 } ``` 要将 Flutter 应用程序构建为 Window 和 Mac 桌面应用程序,请按照以下步骤操作: 1. 在 Flutter 安装目录中运行 `flutter config --enable-windows-desktop` 命令以启用 Window 桌面支持。 2. 在 Flutter 安装目录中运行 `flutter config --enable-macos-desktop` 命令以启用 Mac 桌面支持。 3. 在您的 Flutter 项目中,运行 `flutter create .` 命令以创建一个桌面项目。 4. 在您的 Flutter 项目中,按照 Flutter Desktop 插件的文档说明添加依赖项和插件。 5. 使用 Flutter Desktop 插件提供的 API 来访问桌面特定功能,例如文件系统、网络、窗口管理等。 6. 运行 `flutter run -d windows` 命令以运行 Window 应用程序,或运行 `flutter run -d macos` 命令以运行 Mac 应用程序。 注意,构建 Flutter 桌面应用程序需要一些常规的桌面软件开发知识,例如 C++、Qt、Cocoa 等。如果您不熟悉这些知识,则可能需要更多的学习和实践才能成功构建桌面应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值