gstory0404 / flutter_unionad

字节跳动 穿山甲广告SDK Bytedance-UnionAD flutter版本插件
Apache License 2.0
315 stars 63 forks source link

编译失败 #120

Closed zysc8313 closed 1 month ago

zysc8313 commented 1 month ago

项目里加了flutter_unionad后,没法编译运行

FAILURE: Build failed with an exception.

BUILD FAILED in 34s Error: Gradle task assembleDebug failed with exit code 1

gstory0404 commented 1 month ago

官方升级了android 14,低版本需要升级,如果不想升级使用2.0.7

zysc8313 commented 1 month ago

用2.0.7也是同样的结果。用最新版本的flutter建一个新项目,添加flutter_unionad也会有错

gstory0404 commented 1 month ago

本地使用java版本是多少

zysc8313 commented 1 month ago

Java 8 Update 421

gstory0404 commented 1 month ago

这边新建项目引入测试正常

 Flutter (Channel stable, 3.24.1, on macOS 14.6.1 23G93 darwin-x64, locale zh-Hans-CN)
 Android toolchain - develop for Android devices (Android SDK version 33.0.1)
zysc8313 commented 1 month ago

我的环境是

Flutter (Channel stable, 3.24.2, on macOS 12.7.6 21H1320 darwin-x64, locale en-CN)
Android toolchain - develop for Android devices (Android SDK version 35.0.0)

新项目的build.gradle,没改动过

plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
}

android {
    namespace = "com.example.test"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.example.test"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    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 = "../.."
}
gstory0404 commented 1 month ago

试一下demo能否运行

zysc8313 commented 1 month ago

demo是可以正常运行的

gstory0404 commented 1 month ago

https://github.com/gstory0404/flutter_unionad/blob/master/example/android/build.gradle https://github.com/gstory0404/flutter_unionad/blob/master/example/android/gradle/wrapper/gradle-wrapper.properties 对比一下这俩文件里面的版本号

zysc8313 commented 1 month ago

这是我settings.gradle的版本

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version '8.5.2' apply false
    id "org.jetbrains.kotlin.android" version "1.9.0" apply false
}

把你的example项目也升级到同样的版本,就没法运行了

gstory0404 commented 1 month ago

版本太高了,好像高版本强制java17,看看能不能降下来

zysc8313 commented 1 month ago

我的项目第三方几十个依赖,包括google_mobile_ads都没有问题。 有些依赖无法在release下编译,在build.gradle里临时加了这个配置最终也能正常编译

subprojects {
      afterEvaluate { project ->
          if (project.hasProperty('android')) {
              project.android {
                  if (project.plugins.hasPlugin("com.android.application") ||
                          project.plugins.hasPlugin("com.android.library")) {
                      project.android {
                          compileSdkVersion 34
                      }
                  }

                  if (namespace == null) {
                      namespace project.group
                  }
              }
          }
      }
  }

另外最新版本Flutter创建出来的项目,版本已经很高了

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.1.0" apply false
    id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}
gstory0404 commented 1 month ago

使用这个版本

    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.7.10" apply false
zysc8313 commented 1 month ago

项目里没法直接用这个低版本的,因为没法达到我项目里其他依赖的最低要求

gggitpl commented 1 month ago

确保您在此处拥有相同的版本:

compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 }

kotlinOptions { jvmTarget = "17" }

在您的 gralde.properties 中添加: kotlin.jvm.target.validation.mode = IGNORE

此解决方案可能无法解决问题,但可以绕过它直到有人修复它。 [Inconsistent JVM-target compatibility detected for tasks despite already defining jvm ver](https://stackoverflow.com/questions/77520506/inconsistent-jvm-target-compatibility-detected-for-tasks-despite-already-definin)

gstory0404 commented 1 month ago

为防止兼容问题,插件暂时不升级最新,如果本地版本无法降级 推荐fork插件库修改版本与本地一直并引入

zysc8313 commented 1 month ago

为了尽可能保证项目的兼容性,我暂时只能用JavaVersion.VERSION_1_8,没法升级到 JavaVersion.VERSION_17,那我还是fork修改吧