当前位置:   article > 正文

[Flutter]导入singular_flutter_sdk后运行到Android报错_namespace not specified. specify a namespace in th

namespace not specified. specify a namespace in the module's build file.

问题:

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

  1. dependencies:
  2. # Singular归因
  3. 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

  1. plugins {
  2. id "com.android.application"
  3. id "kotlin-android"
  4. id "dev.flutter.flutter-gradle-plugin"
  5. // 应用Google服务Gradle插件
  6. id 'com.google.gms.google-services'
  7. }
  8. def localProperties = new Properties()
  9. def localPropertiesFile = rootProject.file('local.properties')
  10. if (localPropertiesFile.exists()) {
  11. localPropertiesFile.withReader('UTF-8') { reader ->
  12. localProperties.load(reader)
  13. }
  14. }
  15. def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
  16. if (flutterVersionCode == null) {
  17. flutterVersionCode = '1'
  18. }
  19. def flutterVersionName = localProperties.getProperty('flutter.versionName')
  20. if (flutterVersionName == null) {
  21. flutterVersionName = '1.0'
  22. }
  23. android {
  24. namespace "com.teleprom.www"
  25. // compileSdkVersion是用来编译你的应用的API级别。它指定了编译时使用的Android API版本。你的代码将会使用这个版本的Android API进行编译。它应该是你打算使用的最新稳定版API版本。
  26. compileSdk flutter.compileSdkVersion
  27. // ndkVersion是指定项目要使用的Android NDK(Native Development Kit)的版本。NDK允许你使用C和C++代码来编译本地代码,通常用于性能敏感的部分。当你使用需要NDK的插件或直接编写本地代码时,这个版本就变得重要。
  28. //ndkVersion flutter.ndkVersion
  29. ndkVersion "25.1.8937393"
  30. compileOptions {
  31. sourceCompatibility JavaVersion.VERSION_1_8
  32. targetCompatibility JavaVersion.VERSION_1_8
  33. }
  34. kotlinOptions {
  35. jvmTarget = '1.8'
  36. }
  37. sourceSets {
  38. main.java.srcDirs += 'src/main/kotlin'
  39. }
  40. defaultConfig {
  41. applicationId "com.teleprom.www"
  42. // minSdkVersion指定了能够运行你的应用的最低Android API级别。如果一个设备的API级别低于这个值,该设备将无法在Google Play商店安装或运行你的应用。这个值应该尽可能低,以覆盖更广泛的用户,但同时要高到足以支持应用所需功能的API级别。
  43. //minSdkVersion flutter.minSdkVersion
  44. minSdkVersion 22
  45. targetSdkVersion flutter.targetSdkVersion
  46. versionCode flutterVersionCode.toInteger()
  47. versionName flutterVersionName
  48. }
  49. buildTypes {
  50. release {
  51. // TODO: Add your own signing config for the release build.
  52. // Signing with the debug keys for now, so `flutter run --release` works.
  53. signingConfig signingConfigs.debug
  54. }
  55. }
  56. }
  57. flutter {
  58. source '../..'
  59. }
  60. dependencies {
  61. // 添加Firebase Analytics依赖
  62. implementation platform('com.google.firebase:firebase-bom:32.7.4') // 使用适合你项目的最新BOM版本
  63. implementation 'com.google.firebase:firebase-analytics'
  64. // 依赖关系列表中添加 Singular 库
  65. implementation fileTree(dir: 'libs', include: ['*.jar'])
  66. implementation 'com.android.support:appcompat-v7:28.0.0'
  67. // 注意: 如果在构建时出现DuplicateClasses(重复类 )错误,则可能已经安装了 Google play-services,可以注释掉该依赖关系。
  68. implementation 'com.android.installreferrer:installreferrer:2.2'
  69. implementation 'com.google.android.gms:play-services-appset:16.0.2'
  70. }

android/build.gradle

  1. buildscript {
  2. ext.kotlin_version = ''1.9.23'
  3. repositories {
  4. google()
  5. mavenCentral()
  6. }
  7. dependencies {
  8. classpath 'com.android.tools.build:gradle:8.1.3'
  9. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  10. }
  11. }
  12. allprojects {
  13. repositories {
  14. google()
  15. mavenCentral()
  16. }
  17. }
  18. rootProject.buildDir = '../build'
  19. subprojects {
  20. project.buildDir = "${rootProject.buildDir}/${project.name}"
  21. }
  22. subprojects {
  23. project.evaluationDependsOn(':app')
  24. }
  25. tasks.register("clean", Delete) {
  26. delete rootProject.buildDir
  27. }

settings.gradle

  1. pluginManagement {
  2. def flutterSdkPath = {
  3. def properties = new Properties()
  4. file("local.properties").withInputStream { properties.load(it) }
  5. def flutterSdkPath = properties.getProperty("flutter.sdk")
  6. assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
  7. return flutterSdkPath
  8. }
  9. settings.ext.flutterSdkPath = flutterSdkPath()
  10. includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
  11. repositories {
  12. google()
  13. mavenCentral()
  14. gradlePluginPortal()
  15. }
  16. }
  17. plugins {
  18. id "dev.flutter.flutter-plugin-loader" version "1.0.0"
  19. id "com.android.application" version "8.1.3" apply false
  20. id "org.jetbrains.kotlin.android" version "1.9.23" apply false
  21. // 添加Google服务插件. apply false 表示该插件不会立即应用到项目中,而是可以在子项目(模块)中单独应用。
  22. id 'com.google.gms.google-services' version '4.3.15' apply false
  23. }
  24. include ":app"

gradle/wrapper/gradle-wrapper.properties

  1. distributionBase=GRADLE_USER_HOME
  2. distributionPath=wrapper/dists
  3. zipStoreBase=GRADLE_USER_HOME
  4. zipStorePath=wrapper/dists
  5. distributionUrl = https\://services.gradle.org/distributions/gradle-8.4-bin.zip

运行到Android报错1

报错日志:

  1. Launching lib/main.dart on vivo X20 in debug mode...
  2. FAILURE: Build completed with 2 failures.
  3. 1: Task failed with an exception.
  4. -----------
  5. * What went wrong:
  6. A problem occurred configuring project ':singular_flutter_sdk'.
  7. > Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
  8. > 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.
  9. 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.
  10. * Try:
  11. > Run with --stacktrace option to get the stack trace.
  12. > Run with --info or --debug option to get more log output.
  13. > Run with --scan to get full insights.
  14. > Get more help at https://help.gradle.org.
  15. ==============================================================================
  16. 2: Task failed with an exception.
  17. -----------
  18. * What went wrong:
  19. Failed to query the value of property 'buildFlowServiceProperty'.
  20. > Could not isolate value org.jetbrains.kotlin.gradle.plugin.statistics.BuildFlowService$Parameters_Decorated@7d79dba7 of type BuildFlowService.Parameters
  21. > A problem occurred configuring project ':singular_flutter_sdk'.
  22. > Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
  23. > 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.
  24. 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.
  25. * Try:
  26. > Run with --stacktrace option to get the stack trace.
  27. > Run with --info or --debug option to get more log output.
  28. > Run with --scan to get full insights.
  29. > Get more help at https://help.gradle.org.
  30. ==============================================================================
  31. BUILD FAILED in 4s
  32. Error: Gradle task assembleDebug failed with exit code 1
  33. 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:

  1. buildscript {
  2. ext.kotlin_version = ''1.8.0'
  3. repositories {
  4. google()
  5. mavenCentral()
  6. }
  7. dependencies {
  8. classpath 'com.android.tools.build:gradle:7.4.2'
  9. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  10. }
  11. }
  12. ...

settings.gradle

  1. ...
  2. plugins {
  3. id "com.android.application" version "7.4.2" apply false
  4. id "org.jetbrains.kotlin.android" version "1.8.0" apply false
  5. ...
  6. }

gradle/wrapper/gradle-wrapper.properties

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

 

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

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

报错日志:

  1. Launching lib/main.dart on vivo X20 in debug mode...
  2. 注: /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使用了未经检查或不安全的操作。
  3. 注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
  4. ERROR:D8: com.android.tools.r8.kotlin.H
  5. FAILURE: Build failed with an exception.
  6. * What went wrong:
  7. Execution failed for task ':app:mergeExtDexDebug'.
  8. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
  9. > 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}.
  10. > Execution failed for DexingWithClasspathTransform: /Users/gamin/.gradle/caches/transforms-3/4e42575ef433f9d8bb5373944a07a9ed/transformed/jetified-play-services-measurement-api-21.5.1-runtime.jar.
  11. > Error while dexing.
  12. * Try:
  13. > Run with --stacktrace option to get the stack trace.
  14. > Run with --info or --debug option to get more log output.
  15. > Run with --scan to get full insights.
  16. * Get more help at https://help.gradle.org
  17. BUILD FAILED in 3m 55s
  18. ┌─ Flutter Fix ──────────────────────────────────────────────────────────────┐
  19. │ [!] The shrinker may have failed to optimize the Java bytecode. │
  20. │ To disable the shrinker, pass the `--no-shrink` flag to this command. │
  21. │ To learn more, see: https://developer.android.com/studio/build/shrink-code │
  22. └────────────────────────────────────────────────────────────────────────────┘
  23. Error: Gradle task assembleDebug failed with exit code 1
  24. Exited (1).

解决:

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

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

android/app/build.gradle:

  1. android {
  2. defaultConfig {
  3. minSdkVersion 24
  4. }
  5. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/668932
推荐阅读
相关标签
  

闽ICP备14008679号