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

Problem: Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl #316

Open
sameermalikdev opened this issue Sep 15, 2024 · 7 comments

Comments

@sameermalikdev
Copy link

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

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.

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

@Connect-Suraj-Chaudhari

I am also getting the same error

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

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

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: /Users/devsurajchaudhari/.pub-cache/hosted/pub.dev/image_gallery_saver-2.0.3/android/build.gradle. 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@4e9966b7 of type BuildFlowService.Parameters
A problem occurred configuring project ':image_gallery_saver'.
> 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: /Users/devsurajchaudhari/.pub-cache/hosted/pub.dev/image_gallery_saver-2.0.3/android/build.gradle. 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.
==============================================================================

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

@Zambrella
Copy link

I had the same issue but moving over to https://pub.dev/packages/image_gallery_saver_plus fixed the problem for me. It has the same API so should be an easy switch.

@AlbertoBergerone
Copy link

AlbertoBergerone commented Sep 20, 2024

I'm having this problem with several libraries that haven't been updated for years. It's a trifle to resolve

Just find the plugin inside /External Libraries/Flutter Plugins. Open the build.gradle (inside android folder) and add this line:

android {
    namespace "com.example.imagegallerysaver" // Add this line
    ...
}

Then go to AndroidManifest (folder: image_gallery_saver/android/src.main) and remove package="com.example.imagegallerysaver"

@Zambrella he certainly said the right thing to do, but I still wanted to explain how to solve it because you may encounter the same problem with other libraries that however do not have valid or applicable alternatives

@ajee10x
Copy link

ajee10x commented Sep 21, 2024

I am still trying to find a logical solution for it... and i hope so :)
To resolve the issue for now, Just use image_gallery_saver_plus
I have done it before on one of my open source projects OpenQRCode and worked well after struggling with image_gallery_saver :(
Cheers!

@rogiervandenberg
Copy link

In order to make not fully up-to-date packages work in Android with all the latest requirements, you can add this additional subprojects-block to your android/build.gradle, above the other "subprojects" blocks:

subprojects {
    afterEvaluate {
        project ->
            if (project.hasProperty("android")) {
                android {
                    compileSdkVersion 34 

                    compileOptions {
                        targetCompatibility = JavaVersion.VERSION_1_8
                    }
                    
                    if (namespace == null) {
                        namespace project.group
                    }
                }
            }
    }
}

What it basically does is on compile time add the necessary compileSdkVersion, javaversion and namespace, that are in my experience things that might break your app. In this block, the namespace part is what would solve this specific github issue, without finding and changing the plugin inside /External Libraries. 🎉 (You could of course also cherry pick and just use the namespace part, to solve just this image_gallery_saver issue.

@knottx
Copy link

knottx commented Oct 4, 2024

Try this #295

@18582410063
Copy link

use image_gallery_saver_plus: '^3.0.5', flutter 3.24.3 was compiled sucess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants