Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Namespace issue with package: flutter_foreground_task #1736

Closed
Mind-Reaper opened this issue Mar 18, 2024 · 19 comments
Closed

🐛 Namespace issue with package: flutter_foreground_task #1736

Mind-Reaper opened this issue Mar 18, 2024 · 19 comments

Comments

@Mind-Reaper
Copy link

Description

Trying to build for Android results in a namespace compile error caused by the version of flutter_foreground_task being used by the package.

100ms Flutter Version

3.19.3

Steps to reproduce

  1. Add hms_room_kit and hmssdk_flutter to pubspec.yaml
  2. Follow 100ms.live prebuilt integration documentation for android
  3. Try to build app
  4. You get a namespace error from flutter_foreground_task

Expected results

Build app and run successfully

Code example, screenshot, or link to a repository

.

Logs

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':flutter_foreground_task'.

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@80551c of type BuildFlowService.Parameters
A problem occurred configuring project ':flutter_foreground_task'.
> 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.

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.3, on macOS 14.4 23E214 darwin-arm64, locale en-NG)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
[✓] Chrome - develop for the web
[!] Android Studio (version unknown)
    ✗ Unable to determine Android Studio version.
[✓] IntelliJ IDEA Ultimate Edition (version 2023.3)
[✓] VS Code (version 1.87.2)
[✓] Connected device (3 available)
    ! Error: Browsing on the local area network for My iPhone (2). Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources

! Doctor found issues in 1 category.
Copy link

Hello! Thank you for filing an issue.

Please include relevant logs or detailed description for faster resolutions.

We really appreciate your contribution!

@ygit
Copy link
Member

ygit commented Mar 18, 2024

hey @Mind-Reaper
Whats the Android Gradle Plugin version used in your app?

@Mind-Reaper
Copy link
Author

@ygit
8.2.1

@ygit
Copy link
Member

ygit commented Mar 18, 2024

@Mind-Reaper Can you try a version in the 7.x.x series, say 7.3.1?

@Mind-Reaper
Copy link
Author

Trying that now

@Mind-Reaper
Copy link
Author

Mind-Reaper commented Mar 18, 2024

@ygit That works.
But I get another JVM error now

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':hmssdk_flutter:compileDebugKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (17).

  Consider using JVM Toolchain: https://kotl.in/gradle/jvm/toolchain
  Learn more about JVM-target validation: https://kotl.in/gradle/jvm/target-validation 

@Decoder07
Copy link
Contributor

Hi @Mind-Reaper can you try adding below code in the android section android/app/build.gradle

compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = '17'
 }

@Mind-Reaper
Copy link
Author

@ygit

Not working

I tried adding this

kotlin {
    jvmToolchain(17)
}

Still getting the same error related to this package

@Decoder07
Copy link
Contributor

@Mind-Reaper have you set the gradle JDK to 17 in android studio ?

@Mind-Reaper
Copy link
Author

Hi @ygit. I tried this too. Still no solution. I noticed some of the sample projects use jvm 1.8.

Do you think it could be the Kotlin version cause I have a more recent one on my project?

@ygit
Copy link
Member

ygit commented Mar 21, 2024

hey @Mind-Reaper

Try setting -

  1. ext.kotlin_version as 1.9.0 in your build.gradle file's buildscript { ... }
  2. Set com.android.tools.build:gradle version as 7.2.2

Refer to the attached screenshot.

Alternatively, can you share your Android project's build.gradle files?

Screenshot 2024-03-21 at 12 56 02 PM

@Mind-Reaper
Copy link
Author

@ygit

Just to make things clear. Do you want me to make these changes in my project android directory or in a forked repository of hmssdk ?

@Mind-Reaper
Copy link
Author

app/build.gradle

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services"
    id "com.google.firebase.crashlytics"
}



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'
}


apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

def keystoreProperties = new Properties()
   def keystorePropertiesFile = rootProject.file('key.properties')
   if (keystorePropertiesFile.exists()) {
       keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
   }

android {
    compileSdkVersion 34
    ndkVersion "25.1.8937393"
    namespace "com.theginigroup.giniapp"

    compileOptions {
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = '17'
    }

    kotlin {
        jvmToolchain(17)
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
    flavorDimensions "env"
    productFlavors {
    dev {
        dimension "env"
        applicationId "com.theginigroup.giniapp.dev"
        minSdkVersion 21
        targetSdkVersion 34
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        manifestPlaceholders = [appName: "GINI_DEV"]
        

    }
    prod {
        dimension "env"
        applicationId "com.theginigroup.giniapp"
        minSdkVersion 21
        targetSdkVersion 34
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        manifestPlaceholders = [appName: "GINI"]
    }
    }
    }

     signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }
   buildTypes {
       release {
           signingConfig signingConfigs.release
           minifyEnabled true
           shrinkResources true
           proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
           ndk {
               abiFilters 'armeabi-v7a','arm64-v8a','x86_64'
           }
       }
   }
    namespace 'com.theginigroup.giniapp'
}

flutter {
    source '../..'
}

dependencies {
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'

//    implementation ("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"){
//        exclude group: 'com.google.android.play', module: 'core'
//    }

    implementation platform('com.google.firebase:firebase-bom:30.2.0') {
        exclude group: 'com.google.android.play', module: 'core'
    }
    
    implementation 'com.facebook.android:facebook-android-sdk:latest.release'
    implementation("io.intercom.android:intercom-sdk:14.0.0")
    implementation("com.google.firebase:firebase-messaging:23.1.+")

    // Add the dependency for the Firebase SDK for Google Analytics
    // When using the BoM, don't specify versions in Firebase dependencies
    implementation ('com.google.firebase:firebase-analytics') {
        exclude group: 'com.google.android.play', module: 'core'
    }

    implementation ('com.google.firebase:firebase-crashlytics') {
        exclude group: 'com.google.android.play', module: 'core'
    }

}

android/build.gradle

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
    }()

    includeBuild("$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 "7.4.1" apply false
    id "org.jetbrains.kotlin.android" version "1.9.22" apply false
    id "com.google.gms.google-services" version "4.4.0" apply false
    id "com.google.firebase.crashlytics" version "2.9.9" apply false
}

include ":app"

@ygit
Copy link
Member

ygit commented Mar 22, 2024

hey @Mind-Reaper
Let's get on a call to debug this.
Please book a convenient time here: https://calendly.com/yogesh-singh-100ms/30min

@Mind-Reaper
Copy link
Author

Mind-Reaper commented Mar 22, 2024

@ygit Done, Thanks

@Decoder07
Copy link
Contributor

@Mind-Reaper closing the issue as this is solved.

@rlee1990
Copy link

I am having the same issue.
Kotlin version is 2.0.0
com.android.application version is 8.2.2
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
jvmTarget = '17'

@Decoder07
Copy link
Contributor

@rlee1990 hms_room_kit no longer uses flutter_foreground_task can you try with latest room kit version

@Decoder07 Decoder07 reopened this Jul 1, 2024
@rlee1990
Copy link

rlee1990 commented Jul 1, 2024

@Decoder07 I have it working this can be closed.

@ygit ygit closed this as completed Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants