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

这篇具有很好参考价值的文章主要介绍了[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.ndkVersion
    ndkVersion "25.1.8937393"  

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility 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.minSdkVersion
        minSdkVersion 22  
        targetSdkVersion flutter.targetSdkVersion
        versionCode 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 1


Exited (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.H

FAILURE: 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.org

BUILD 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 1


Exited (1).

解决:

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

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

android/app/build.gradle:文章来源地址https://www.toymoban.com/news/detail-851523.html

android {
    defaultConfig {
        minSdkVersion 24
    }
}

到了这里,关于[Flutter]导入singular_flutter_sdk后运行到Android报错的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • mac 修改flutter sdk配置

    问题描述:我mac电脑上有高低2个版本的flutter sdk,我需要低版本sdk的项目在setting里设置了sdk版本,可是命令行还是提示我版本过高。 直接上解决办法: 打开mac终端,输入open -e .bash_profile,然后修改下方圈起来的flutter版本ok。

    2024年01月25日
    浏览(44)
  • Flutter项目的sdk版本管理工具

    flutter項目的sdk版本使用是一個很尴尬的问题,一个项目一个SDK,电脑系统还只能装一个SDK,这就使我们开发当中很尴尬,好几个项目分别使用不同的SDK就很难办了,不可能来回升级降级SDK,现在市面有SDK版本管理工具,虽然不是很友好,但是也算一个解决办法,下面说一下解

    2024年04月14日
    浏览(43)
  • Flutter集成UniMPSDK(Uni小程序SDK)

    SDK文件结构如下: 小程序打包基座: 提示:尽量与 UniMPSDK 版本一致 libs依赖库配置 查看Flutter项目中 android/app 目录中是否存在 libs 文件夹,没有就创建。 将 SDK-Android@3.98-20231127/SDK/libs 中相应的依赖复制到 项目 android/app/libs/ libs 文件夹依赖库可根据功能需要进行增加或删除,

    2024年04月16日
    浏览(39)
  • Flutter 版本更新 和 dart SDK版本跟新

    报错啦怎么办? 找到了我的电脑里面dart SDK的位置, D:Flutterflutterbincachedart-sdk 我认为是dart的版本不够的时候,我就去下载新的dart SDK(下载地址:Archive | Dart ),然后去替换我之前的dart-sdk,然后就出现问题了,官方的flutter sdk中已经自带了匹配版本的dart sdk。所以不要自

    2024年02月14日
    浏览(32)
  • flutter TARGET_SDK_VERSION和android 13

    config.gradle app/build.gradle里面的 有时候谷歌会让你发的app版本起码为android 13,那就要改上面的TARGET_SDK_VERSION

    2024年02月11日
    浏览(31)
  • flutter创建/导入区块链钱包,获取余额

    作为区块链行业小白刚接触区块链钱包几天,来开发钱包还是需要付出很多努力的.下面记录一下flutter框架下创建/导入区块链钱包,并获取余额 一、创建钱包: 钱包的创建分为三个步骤: 1、生成助记词 (1)、创建助记词: 需要用到bip39插件 (2)、创建方式: 2、助记词生成私钥 (1)、生

    2024年02月06日
    浏览(32)
  • Flutter 与第三方 Native-SDK 的交互代理方案

    场景 在使用 Flutter 进行功能模块或者整体项目的开发时,如果需要(阶段性)频繁地和某个第三方 Native-SDK 进行交互,而该 Native-SDK 没有实现 Flutter 插件版本的情况下,如果直接把这部分交互 API 加入到原有的 channel 类里面,会使得该 channel 类变得臃肿,造成代码维护及迭代

    2024年02月02日
    浏览(29)
  • 集成 Firebase 后,Flutter IM SDK 在 Android 端不触发回调

    描述 客户已集成 Firebase Messaging,Android 平台 Flutter IM SDK 的不触发任何回调。 分析(根因分析、需求分析) 可能原因是客户构建了一个 FlutterEngine instance,导致 SDK 的 FlutterEngine instance 失效了。 解决方案 找到以下 java 文件 packages/firebase_messaging/firebase_messaging/android/src/main/jav

    2024年02月01日
    浏览(30)
  • flutter_inappwebview包引入后总要求Android SDK 33版本的问题

    今天想使用flutter_inappwebview来显示网页,直接在pubspec.yaml中引入包文件:  

    2023年04月20日
    浏览(40)
  • flutter App如何跳转小程序如何调用微信sdk(ios/andriod)

            实不相瞒,这一块着实耗费了我很大的时间,因为没有太多ios和andriod原生开发的知识储备,在很多方面就会踩不少坑,这里总结几种app跳转微信小程序的方式 第一种方案:使用明文URL Scheme 这是最简单!不需要太多配置的方式!但是这里有一个坑就是对于ios是无痛拉

    2024年03月14日
    浏览(50)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包