flutter_js icon indicating copy to clipboard operation
flutter_js copied to clipboard

Build failed with "Namepace not specified" error

Open prtkgrg opened this issue 1 year ago • 5 comments
trafficstars

image

prtkgrg avatar Oct 03 '24 16:10 prtkgrg

edit android/settings.gradle

plugins {
id "com.android.application" version "7.4.2" apply false
}

edit android/gradle/wrapper/gradle-wrapper.properties

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

My colleague told me to do so. I don't know why but it works.

Shinku1014 avatar Oct 11 '24 09:10 Shinku1014

i do have a same issue... any fix would be greate.

michalss avatar Oct 18 '24 19:10 michalss

edit android/settings.gradle

plugins {
id "com.android.application" version "7.4.2" apply false
}

edit android/gradle/wrapper/gradle-wrapper.properties

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

My colleague told me to do so. I don't know why but it works.

This fixes the issue for me too. Also it works because you are setting the version of gradle you use to be compatible with the one flutter_js uses. As for if any other issues will pop up because of it, I guess I'll find out eventually.

BrokenRepository avatar Oct 23 '24 20:10 BrokenRepository

that is the problem i dont want/ i cannot downgrade gradle.. :(

michalss avatar Oct 25 '24 06:10 michalss

that is the problem i dont want/ i cannot downgrade gradle.. :(

Oh, in that case, you'll have to set up the package as a local dependency and go into their gradle files and update them to match yours. If you need help doing it, chatgpt and google are your friends.

I ended up having to set up a local dependency anyway in order to get a proper release build, so you may as well.

evanhh191 avatar Oct 25 '24 06:10 evanhh191

If you run newest dart, flutter and gradle you probably have to edit the plugin

FAILURE: Build failed with an exception.

  • What went wrong: Could not open cp_settings generic class cache for settings file 'C:\Users\emile\Documents\Code\XXXXXX\wear\android\settings.gradle' (C:\Users\emile.gradle\caches\7.6.3\scripts\336uqv0bm2kn9xc0ul77aekqb).

BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 65

  • 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 2s

edit android/settings.gradle

plugins {
id "com.android.application" version "7.4.2" apply false
}

edit android/gradle/wrapper/gradle-wrapper.properties

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

My colleague told me to do so. I don't know why but it works.

HERE IS A FIX: Download this repo. Copy to root folder of your project (same place where your pubspec lies).

add

flutter_js:
   path: flutter_js

to your pubspec dependencies

Delete EXAMPLES subproject Go to android/gradle/wrapper/gradle-wrapper.properties and change distributionUrl version number to the one your are using in your project. You can check it in your gradle-wrapper.properties in the root app (ctrl+shift+f, distributionUrl).

Go to flutter_js/android/build.gradle and edit dependencies { classpath 'com.android.tools.build:gradle:X.X.X' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } so that X.X.X is the same version you used to modify previous file. Go to flutter_js/android/build.gradle and add namespace 'io.abner.flutter_js' to android{} section delete package property from in android/src/main/AndroidManifest.xml

You can leave a reaction if this helps <3

emilekm2142 avatar Nov 06 '24 20:11 emilekm2142

I am not quite sure if the gradle version conflict is actually the issue here.

The latest AGP just requires the namespace attribute to be present in the build.gradle.

I've only edited the build.gradle manually and added the namespace attribute. It compiles and runs without any issue.

image

denny99 avatar Nov 07 '24 09:11 denny99

edit android/settings.gradle

plugins {
id "com.android.application" version "7.4.2" apply false
}

edit android/gradle/wrapper/gradle-wrapper.properties

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

My colleague told me to do so. I don't know why but it works.

This is you downgrading the plugin version which isn't a viable long term solution.

freemansoft avatar Jan 08 '25 04:01 freemansoft

An alternative fix is to add all missing namespaces by adding this snippet to the project gradle.build just after the first "subprojects" statement. This avoids having to fork or clone the original library into your project.

subprojects {
    afterEvaluate { project ->
        if (project.hasProperty('android')) {
            project.android {
                if (namespace == null) {
                    namespace project.group
                }
            }
        }
    }
}

Kudos to this Stack Overflow answer by Dmytro Puzak.

Note that this solution might lead you to another known Flutter problem: "AAPT: error: resource android:attr/lStar not found." (See this GitHub issue)

A solution from that GitHub thread is this additional snippet:

subprojects {
    afterEvaluate { project ->
        if (project.extensions.findByName("android") != null) {
            Integer pluginCompileSdk = project.android.compileSdk
            if (pluginCompileSdk != null && pluginCompileSdk < 31) {
                project.logger.error(
                        "Warning: Overriding compileSdk version in Flutter plugin: "
                                + project.name
                                + " from "
                                + pluginCompileSdk
                                + " to 31 (to work around https://issuetracker.google.com/issues/199180389)."
                                + "\nIf there is not a new version of " + project.name + ", consider filing an issue against "
                                + project.name
                                + " to increase their compileSdk to the latest (otherwise try updating to the latest version)."
                )
                project.android {
                    compileSdk 31
                }
            }
        }
    }
    
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(":app")
}

Credits for this solution go to Gray Mackall and Dick Verweij.

timovandeput avatar Feb 18 '25 08:02 timovandeput