cryptography icon indicating copy to clipboard operation
cryptography copied to clipboard

New flutter project fails with error

Open JohnGalt1717 opened this issue 1 year ago • 3 comments

Steps: flutter doctor - all green flutter create test cd test flutter build app_bundle (successful) flutter pub add cryptography_flutter flutter build app_bundle

error:


* What went wrong:
A problem occurred configuring project ':cryptography_flutter'.
> Could not resolve all files for configuration ':cryptography_flutter:classpath'.
   > Could not find com.android.tools.build:gradle:8.7.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/8.7/gradle-8.7.pom
       - https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/8.7/gradle-8.7.pom
     Required by:
         project :cryptography_flutter
> Failed to notify project evaluation listener.
   > Could not get unknown property 'android' for project ':cryptography_flutter' of type org.gradle.api.Project.
   > Could not get unknown property 'android' for project ':cryptography_flutter' of type org.gradle.api.Project.

There's nothing in the documentation that would indicate steps required to make this work with some changes. But I tried updating to gradle 8.7 in gradle-wrapper.properties and it still errors.

Also there is no such thing as android tools 8.7, 8.4 is the latest.

JohnGalt1717 avatar May 10 '24 17:05 JohnGalt1717

I was able to sort of get around this be going into the package cache for this library and adding this to the build.gradle:

namespace "dev.dint.cryptography_flutter"

That eliminated the error. There are TONS of depreciation warnings though from this library.

JohnGalt1717 avatar May 10 '24 21:05 JohnGalt1717

I was able to sort of get around this be going into the package cache for this library and adding this to the build.gradle:

namespace "dev.dint.cryptography_flutter"

That eliminated the error. There are TONS of depreciation warnings though from this library.

Also need to remove package property in AndroidManifest.xml

rewired-gh avatar May 30 '24 11:05 rewired-gh

Same warning here +1

ugran avatar Sep 19 '24 16:09 ugran

try adding this to your android/build.gradle

subprojects {
    afterEvaluate { project ->
            if (project.plugins.hasPlugin("com.android.application") ||
                project.plugins.hasPlugin("com.android.library")) {
            project.android {
                compileSdkVersion 34                
            }
        }
        if (project.hasProperty('android')) {
            project.android {
                if (namespace == null) {
                    namespace = project.group.toString()  // Set namespace as fallback
                }
                project.tasks.whenTaskAdded { task ->
                    if (task.name.contains('processDebugManifest') || task.name.contains('processReleaseManifest')) {
                        task.doFirst {
                            File manifestFile = file("${projectDir}/src/main/AndroidManifest.xml")
                            if (manifestFile.exists()) {
                                String manifestContent = manifestFile.text
                                if (manifestContent.contains('package=')) {
                                    manifestContent = manifestContent.replaceAll(/package="[^"]*"/, "")
                                    manifestFile.write(manifestContent)
                                    println "Removed 'package' attribute from ${manifestFile}"
                                }
                            }
                        }
                    }
                }
            }
        }
    }

This code will make the required changes in all packages' AndroidManifest.xml

sakinaboriwala avatar Apr 25 '25 07:04 sakinaboriwala