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

Getting rid of buildDir deprecation #146036

Closed
AbdeMohlbi opened this issue Mar 30, 2024 · 21 comments
Closed

Getting rid of buildDir deprecation #146036

AbdeMohlbi opened this issue Mar 30, 2024 · 21 comments
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter P2 Important issues not at the top of the work list platform-android Android applications specifically t: gradle "flutter build" and "flutter run" on Android team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@AbdeMohlbi
Copy link

AbdeMohlbi commented Mar 30, 2024

Use case

Currently, when using the flutter create command to initialize a new Flutter project, the generated Android build.gradle file looks something like that :

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
}

well now '.buildDir' is deprecated so an alternative solution may be using '.layout.buildDirectory' instead so it well be :

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

rootProject.layout.buildDirectory = '../build'
subprojects {
    rootProject.layout.buildDirectory= "${rootProject.layout.buildDirectory}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.layout.buildDirectory
}

Proposal

when trying to do that android studio doesn't say anything but gradle is yelling this :

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\bougara computer\StudioProjects\open_food_facts_api_flutter\android\build.gradle' line: 13

* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
   > Could not create service of type ProjectScopedCacheBuilderFactory using WorkerSharedProjectScopeServices.createProjectScopedCache().
      > Illegal char <:> at index 206: C:\Users\bougara computer\StudioProjects\open_food_facts_api_flutter\android\app\property(org.gradle.api.file.Directory, fixed(class org.gradle.api.internal.file.DefaultFilePropertyFactory$FixedDirectory, C:\Users\bougara computer\StudioProjects\open_food_facts_api_flutter\build))\app\tmp\.cache

* 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
@AbdeMohlbi
Copy link
Author

gradle docs refrences this issue here

@darshankawar darshankawar added in triage Presently being triaged by the triage team platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. t: gradle "flutter build" and "flutter run" on Android team-tool Owned by Flutter Tool team c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter and removed in triage Presently being triaged by the triage team labels Apr 1, 2024
@reidbaker
Copy link
Contributor

@bartekpacia fyi
Not sure if our gradle plugin work lets us avoid this, has no impact or makes this migration harder.

@reidbaker reidbaker added the P2 Important issues not at the top of the work list label Apr 1, 2024
@AbdeMohlbi
Copy link
Author

AbdeMohlbi commented Apr 1, 2024

@bartekpacia fyi Not sure if our gradle plugin work lets us avoid this, has no impact or makes this migration harder.

well i'm still tracking where is the issue but from what i see the buildDir will be removed soon in gradle 9 so it can cause other issues

@bartekpacia
Copy link
Member

bartekpacia commented Apr 1, 2024

@AbdeMohlbi I think you have a mistake in the second snippet. Please try this:

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

rootProject.layout.buildDirectory = '../build'
subprojects {
-    rootProject.layout.buildDirectory= "${rootProject.layout.buildDirectory}/${project.name}"
+    project.layout.buildDirectory= "${rootProject.layout.buildDirectory}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.layout.buildDirectory
}

Also I'd try flutter clean.

Not sure if our gradle plugin work lets us avoid this, has no impact or makes this migration harder.

I think it has no impact.

One problem is that the code mentioned is located in app's code, not in Flutter's code. It's quite simple though, so maybe we can add an automatic migration for it (similar to #122290 - see class TopLevelGradleBuildFileMigration).

@AbdeMohlbi
Copy link
Author

@AbdeMohlbi I think you have a mistake in the second snippet. Please try this:

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

rootProject.layout.buildDirectory = '../build'
subprojects {
-    rootProject.layout.buildDirectory= "${rootProject.layout.buildDirectory}/${project.name}"
+    project.layout.buildDirectory= "${rootProject.layout.buildDirectory}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.layout.buildDirectory
}

Also I'd try flutter clean.

Not sure if our gradle plugin work lets us avoid this, has no impact or makes this migration harder.

I think it has no impact.

One problem is that the code mentioned is located in app's code, not in Flutter's code. It's quite simple though, so maybe we can add an automatic migration for it (similar to https://github.com/flutter/flutter/pull/122290/files).

i'll try right away thank you

@AbdeMohlbi
Copy link
Author

@bartekpacia still the same :
FAILURE: Build failed with an exception.

  • Where:
    Build file 'C:\Users\bougara computer\StudioProjects\open_food_facts\android\build.gradle' line: 13

  • What went wrong:
    A problem occurred evaluating root project 'android'.

A problem occurred configuring project ':app'.
Could not create service of type ProjectScopedCacheBuilderFactory using WorkerSharedProjectScopeServices.createProjectScopedCache().
> Illegal char <:> at index 194: C:\Users\bougara computer\StudioProjects\open_food_facts\android\app\property(org.gradle.api.file.Directory, fixed(class org.gradle.api.internal.file.DefaultFilePropertyFactory$FixedDirectory, C:\Users\bougara computer\StudioProjects\open_food_facts\build))\app\tmp.cache

  • 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 22s
Error: Gradle task assembleDebug failed with exit code 1

@bartekpacia
Copy link
Member

Ah, I think I know! Gimme 5 minutes

@AbdeMohlbi
Copy link
Author

@bartekpacia
Copy link
Member

Yes, project.buildDir can be passed a string, but project.layout.buildDirectory expects a file/directory

@AbdeMohlbi
Copy link
Author

'''We know this is a big change and want to give time for authors of major plugins to move away from its usage first.

The switch from a File to a DirectoryProperty requires adaptations in build logic. The main impact is that you cannot use the property inside a String to expand it. Instead, you should leverage the dir and file methods to compute the location you want.'''

@AbdeMohlbi
Copy link
Author

based on :
gradle/gradle#20210 (comment)
i made :

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

rootProject.layout.buildDirectory.get().asFile = '../build'
subprojects {
    project.layout.buildDirectory= "${rootProject.layout.buildDirectory}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.layout.buildDirectory
}

now it's saying :
Build file 'C:\Users\bougara computer\StudioProjects\open_food_facts\android\build.gradle' line: 8

A problem occurred evaluating root project 'android'.

Cannot set readonly property: asFile for class: org.gradle.api.internal.file.DefaultFilePropertyFactory$FixedDirectory

@bartekpacia
Copy link
Member

bartekpacia commented Apr 1, 2024

I tried your sample above and got the same error.

The below works for me:

rootProject.layout.buildDirectory = file("../build")
subprojects {
    project.layout.buildDirectory = file("${rootProject.buildDir}/${project.name}")
    project.evaluationDependsOn(":app")
}

tasks.register("clean", Delete) {
    delete rootProject.layout.buildDirectory
}

@AbdeMohlbi
Copy link
Author

AbdeMohlbi commented Apr 1, 2024

@bartekpacia

${rootProject.buildDir}

ur still using buildDir in the third line ? i'm i right?
edit : when trying to take it one step futher by this :

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.layout.buildDirectory = file("../build")
subprojects {
    project.layout.buildDirectory = file("${rootProject.layout.buildDirectory}/${project.name}")
    project.evaluationDependsOn(":app")
}

tasks.register("clean", Delete) {
    delete rootProject.layout.buildDirectory
}

im getting that :

Illegal char <:> at index 194: C:\Users\bougara computer\StudioProjects\open_food_facts\android\app\property(org.gradle.api.file.Directory, fixed(class org.gradle.api.internal.file.DefaultFilePropertyFactory$FixedDirectory, C:\Users\bougara computer\StudioProjects\open_food_facts\build))\app\intermediates\flutter\debug\libs.jar

@bartekpacia
Copy link
Member

bartekpacia commented Apr 1, 2024

You're right, sorry. Ugh. Try this:

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

rootProject.layout.buildDirectory = file('../build')
subprojects {
    def directory = "${rootProject.layout.buildDirectory.get().asFile}/${project.name}"
    logger.quiet("directory is: $directory") // debugging
    project.layout.buildDirectory = file(directory)
}
subprojects {
  project.evaluationDependsOn(":app")
}

tasks.register("clean", Delete) {
    delete rootProject.layout.buildDirectory
}

See also:

@AbdeMohlbi
Copy link
Author

AbdeMohlbi commented Apr 1, 2024

@bartekpacia
first i was trying smth like that
gradle/gradle#25661 (comment)
thanks a lot brother it works fine
can u open a seperate issue if consider making this a small task in the upcoming migration ? smth i dunno , i've noticed it and just want to avoid any problems with gradle in the near future

@AbdeMohlbi
Copy link
Author

AbdeMohlbi commented Apr 1, 2024

@bartekpacia
i know i'm a bother but in the same context there is :
The Project.getConvention() method has been deprecated warning that i couldn't find any where in the files
i've seen this :
...
i'd be happy to know if this issue is related to the files generated by the flutter create command

@bartekpacia
Copy link
Member

Seems like it's another Gradle deprecation. I'd guess that some Gradle plugin you depend on is causing that.

Anyway the issue is resolved, so let me mark this issue as closed :-) Please create a new one if you have a reproducible example.

@AbdeMohlbi
Copy link
Author

AbdeMohlbi commented Apr 1, 2024

Seems like it's another Gradle deprecation. I'd guess that some Gradle plugin you depend on is causing that.

Anyway the issue is resolved, so let me mark this issue as closed :-) Please create a new one if you have a reproducible example.

Will this changes be applied in a future release of flutter ?

@bartekpacia
Copy link
Member

bartekpacia commented Apr 1, 2024

If you mean the automatic migration I was talking about, then no, it won't be in the next stable Flutter release. Someone has to develop it first.

However you can already use this code and not wait for any changes in Flutter.

@AbdeMohlbi
Copy link
Author

If you mean the automatic migration I was talking about, then no, it won't be in the next stable Flutter release. Someone has to develop it first.

However you can already use this code and not wait for any changes in Flutter.

Ty very much brother i really appreciate it

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter P2 Important issues not at the top of the work list platform-android Android applications specifically t: gradle "flutter build" and "flutter run" on Android team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

No branches or pull requests

4 participants