[Flutter]导入singular_flutter_sdk后运行到Android报错

2024-04-03 06:20

本文主要是介绍[Flutter]导入singular_flutter_sdk后运行到Android报错,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

问题:

接入归因之前,flutter项目一起正常。接入归因之后,iOS正常Android有问题。

dependencies:  # Singular归因singular_flutter_sdk: ^1.3.3

针对 Flutter 的 Singular SDK 集成指南

https://support.singular.net/hc/zh-cn/articles/4408894547227-%E9%92%88%E5%AF%B9-Flutter-%E7%9A%84-Singular-SDK-%E9%9B%86%E6%88%90%E6%8C%87%E5%8D%97

当前环境配置

android/app/build.gradle

plugins {id "com.android.application"id "kotlin-android"id "dev.flutter.flutter-gradle-plugin"// 应用Google服务Gradle插件id 'com.google.gms.google-services'
}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.teleprom.www"// compileSdkVersion是用来编译你的应用的API级别。它指定了编译时使用的Android API版本。你的代码将会使用这个版本的Android API进行编译。它应该是你打算使用的最新稳定版API版本。compileSdk flutter.compileSdkVersion// ndkVersion是指定项目要使用的Android NDK(Native Development Kit)的版本。NDK允许你使用C和C++代码来编译本地代码,通常用于性能敏感的部分。当你使用需要NDK的插件或直接编写本地代码时,这个版本就变得重要。//ndkVersion flutter.ndkVersionndkVersion "25.1.8937393"  compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}kotlinOptions {jvmTarget = '1.8'}sourceSets {main.java.srcDirs += 'src/main/kotlin'}defaultConfig {applicationId "com.teleprom.www"// minSdkVersion指定了能够运行你的应用的最低Android API级别。如果一个设备的API级别低于这个值,该设备将无法在Google Play商店安装或运行你的应用。这个值应该尽可能低,以覆盖更广泛的用户,但同时要高到足以支持应用所需功能的API级别。//minSdkVersion flutter.minSdkVersionminSdkVersion 22  targetSdkVersion flutter.targetSdkVersionversionCode flutterVersionCode.toInteger()versionName flutterVersionName}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}}
}flutter {source '../..'
}dependencies {// 添加Firebase Analytics依赖implementation platform('com.google.firebase:firebase-bom:32.7.4') // 使用适合你项目的最新BOM版本implementation 'com.google.firebase:firebase-analytics'// 依赖关系列表中添加 Singular 库implementation fileTree(dir: 'libs', include: ['*.jar'])implementation 'com.android.support:appcompat-v7:28.0.0'// 注意: 如果在构建时出现DuplicateClasses(重复类 )错误,则可能已经安装了 Google play-services,可以注释掉该依赖关系。implementation 'com.android.installreferrer:installreferrer:2.2'implementation 'com.google.android.gms:play-services-appset:16.0.2'
}

android/build.gradle

buildscript {ext.kotlin_version = ''1.9.23'repositories {google()mavenCentral()}dependencies {classpath 'com.android.tools.build:gradle:8.1.3'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
}

settings.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}settings.ext.flutterSdkPath = flutterSdkPath()includeBuild("${settings.ext.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.3" apply false id "org.jetbrains.kotlin.android" version "1.9.23" apply false// 添加Google服务插件. apply false 表示该插件不会立即应用到项目中,而是可以在子项目(模块)中单独应用。id 'com.google.gms.google-services' version '4.3.15' apply false
}include ":app"

gradle/wrapper/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-bin.zip

运行到Android报错1

报错日志:

Launching lib/main.dart on vivo X20 in debug mode...FAILURE: Build completed with 2 failures.1: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':singular_flutter_sdk'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.> Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.* 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.
==============================================================================2: Task failed with an exception.
-----------
* What went wrong:
Failed to query the value of property 'buildFlowServiceProperty'.
> Could not isolate value org.jetbrains.kotlin.gradle.plugin.statistics.BuildFlowService$Parameters_Decorated@7d79dba7 of type BuildFlowService.Parameters> A problem occurred configuring project ':singular_flutter_sdk'.> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.> Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.* 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 4s
Error: Gradle task assembleDebug failed with exit code 1Exited (1).

解决:

按照搜索到的办法,并非所有包都支持版本 8.xx,将 Android Gridle 插件版本 8.1.3 降级到 7.4.2 来解决这个问题。

flutter firebase app not running on Android: Namespace not specified - Stack Overflow

android/build.gradle:

buildscript {ext.kotlin_version = ''1.8.0'repositories {google()mavenCentral()}dependencies {classpath 'com.android.tools.build:gradle:7.4.2'classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"}
}
...

settings.gradle

...
plugins {id "com.android.application" version "7.4.2" apply false id "org.jetbrains.kotlin.android" version "1.8.0" apply false...
}

gradle/wrapper/gradle-wrapper.properties

...
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip

 

运行到Android报错ERROR:D8: com.android.tools.r8.kotlin.H

修复完第一个问题后,运行包这个错误。

报错日志:

Launching lib/main.dart on vivo X20 in debug mode...
注: /Users/gamin/.pub-cache/hosted/pub.flutter-io.cn/singular_flutter_sdk-1.3.3/android/src/main/java/com/singular/flutter_sdk/SingularSDK.java使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
ERROR:D8: com.android.tools.r8.kotlin.HFAILURE: Build failed with an exception.* What went wrong:
Execution failed for task ':app:mergeExtDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.> Failed to transform play-services-measurement-api-21.5.1.aar (com.google.android.gms:play-services-measurement-api:21.5.1) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=22, org.gradle.status=release, org.gradle.usage=java-runtime}.> Execution failed for DexingWithClasspathTransform: /Users/gamin/.gradle/caches/transforms-3/4e42575ef433f9d8bb5373944a07a9ed/transformed/jetified-play-services-measurement-api-21.5.1-runtime.jar.> Error while dexing.* 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.orgBUILD FAILED in 3m 55s┌─ Flutter Fix ──────────────────────────────────────────────────────────────┐
│ [!] The shrinker may have failed to optimize the Java bytecode.            │
│ To disable the shrinker, pass the `--no-shrink` flag to this command.      │
│ To learn more, see: https://developer.android.com/studio/build/shrink-code │
└────────────────────────────────────────────────────────────────────────────┘
Error: Gradle task assembleDebug failed with exit code 1Exited (1).

解决:

有个类似问题:https://github.com/flutter/flutter/issues/146038

将最低支持版本从22升级到24

android/app/build.gradle:

android {defaultConfig {minSdkVersion 24}
}

这篇关于[Flutter]导入singular_flutter_sdk后运行到Android报错的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/872127

相关文章

python: 多模块(.py)中全局变量的导入

文章目录 global关键字可变类型和不可变类型数据的内存地址单模块(单个py文件)的全局变量示例总结 多模块(多个py文件)的全局变量from x import x导入全局变量示例 import x导入全局变量示例 总结 global关键字 global 的作用范围是模块(.py)级别: 当你在一个模块(文件)中使用 global 声明变量时,这个变量只在该模块的全局命名空

如何用Docker运行Django项目

本章教程,介绍如何用Docker创建一个Django,并运行能够访问。 一、拉取镜像 这里我们使用python3.11版本的docker镜像 docker pull python:3.11 二、运行容器 这里我们将容器内部的8080端口,映射到宿主机的80端口上。 docker run -itd --name python311 -p

Android实现任意版本设置默认的锁屏壁纸和桌面壁纸(两张壁纸可不一致)

客户有些需求需要设置默认壁纸和锁屏壁纸  在默认情况下 这两个壁纸是相同的  如果需要默认的锁屏壁纸和桌面壁纸不一样 需要额外修改 Android13实现 替换默认桌面壁纸: 将图片文件替换frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.*  (注意不能是bmp格式) 替换默认锁屏壁纸: 将图片资源放入vendo

Android平台播放RTSP流的几种方案探究(VLC VS ExoPlayer VS SmartPlayer)

技术背景 好多开发者需要遴选Android平台RTSP直播播放器的时候,不知道如何选的好,本文针对常用的方案,做个大概的说明: 1. 使用VLC for Android VLC Media Player(VLC多媒体播放器),最初命名为VideoLAN客户端,是VideoLAN品牌产品,是VideoLAN计划的多媒体播放器。它支持众多音频与视频解码器及文件格式,并支持DVD影音光盘,VCD影

Flutter 进阶:绘制加载动画

绘制加载动画:由小圆组成的大圆 1. 定义 LoadingScreen 类2. 实现 _LoadingScreenState 类3. 定义 LoadingPainter 类4. 总结 实现加载动画 我们需要定义两个类:LoadingScreen 和 LoadingPainter。LoadingScreen 负责控制动画的状态,而 LoadingPainter 则负责绘制动画。

android-opencv-jni

//------------------start opencv--------------------@Override public void onResume(){ super.onResume(); //通过OpenCV引擎服务加载并初始化OpenCV类库,所谓OpenCV引擎服务即是 //OpenCV_2.4.3.2_Manager_2.4_*.apk程序包,存

跨系统环境下LabVIEW程序稳定运行

在LabVIEW开发中,不同电脑的配置和操作系统(如Win11与Win7)可能对程序的稳定运行产生影响。为了确保程序在不同平台上都能正常且稳定运行,需要从兼容性、驱动、以及性能优化等多个方面入手。本文将详细介绍如何在不同系统环境下,使LabVIEW开发的程序保持稳定运行的有效策略。 LabVIEW版本兼容性 LabVIEW各版本对不同操作系统的支持存在差异。因此,在开发程序时,尽量使用

从状态管理到性能优化:全面解析 Android Compose

文章目录 引言一、Android Compose基本概念1.1 什么是Android Compose?1.2 Compose的优势1.3 如何在项目中使用Compose 二、Compose中的状态管理2.1 状态管理的重要性2.2 Compose中的状态和数据流2.3 使用State和MutableState处理状态2.4 通过ViewModel进行状态管理 三、Compose中的列表和滚动

Android 10.0 mtk平板camera2横屏预览旋转90度横屏拍照图片旋转90度功能实现

1.前言 在10.0的系统rom定制化开发中,在进行一些平板等默认横屏的设备开发的过程中,需要在进入camera2的 时候,默认预览图像也是需要横屏显示的,在上一篇已经实现了横屏预览功能,然后发现横屏预览后,拍照保存的图片 依然是竖屏的,所以说同样需要将图片也保存为横屏图标了,所以就需要看下mtk的camera2的相关横屏保存图片功能, 如何实现实现横屏保存图片功能 如图所示: 2.mtk

android应用中res目录说明

Android应用的res目录是一个特殊的项目,该项目里存放了Android应用所用的全部资源,包括图片、字符串、颜色、尺寸、样式等,类似于web开发中的public目录,js、css、image、style。。。。 Android按照约定,将不同的资源放在不同的文件夹中,这样可以方便的让AAPT(即Android Asset Packaging Tool , 在SDK的build-tools目