jpnurmi / flutter_libserialport

Serial Port for Flutter
https://pub.dev/packages/flutter_libserialport
MIT License
156 stars 96 forks source link

Support for Gradle 8.3.0: Define namespace #100

Open kay4ik opened 8 months ago

kay4ik commented 8 months ago

Hey, when running an android build using the latest gradle version, following error occurs:

A problem occurred configuring project ':flutter_libserialport'.
> 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.

To solve this problem following line needs to be defined (probably): In android/src/build.gradle

android {
    namespace "org.sigrok.flutter_libserialport"
    compileSdk 29

    kotlinOptions {
        jvmTarget = '1.8'
    }
...

Also the min SDK version should be increased to 19 according to this warning:

C/C++: Platform version 16 is unsupported by this NDK, using 19 instead. Please change minSdk to at least 19 to avoid this warning.

This should be everything the console is asking for :)

Recommendation


I have avoided all warnings and errors by making following changes:

Now there are no warnings and errors anymore and the android/src/build.gradle is looking like that:

group 'org.sigrok.flutter_libserialport'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.9.20'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

rootProject.allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
    namespace "org.sigrok.flutter_libserialport"
    compileSdkVersion 34

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    defaultConfig {
        minSdkVersion 19
    }
    lintOptions {
        disable 'InvalidPackage'
    }
    externalNativeBuild {
        cmake {
            path "libserialport/CMakeLists.txt"
        }
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
djensen47 commented 8 months ago

Any chance we can get this in a 0.5.0 or even a 1.0 release?

@kay4ik I don't supposed you forked the fix anywhere?

kay4ik commented 8 months ago

@djensen47 No I didn't forked the solution, but I can do that next week and create a merge request. Maybe @jpnurmi can than accept this MR