Querying the mapped value of map before task compileDebugJavaWithJavac has completed is not supported

I exported Unity project and then imported it into Android Studio, but following error occurred when building

Execution failed for task ':unityLibrary:unity-android-resources:compileDebugJavaWithJavac'.

Failed to calculate the value of task ':unityLibrary:unity-android-resources:compileDebugJavaWithJavac' property 'options.generatedSourceOutputDirectory'.
Querying the mapped value of map(java.io.File property(org.gradle.api.file.Directory, fixed(class org.gradle.api.internal.file.DefaultFilePropertyFactory$FixedDirectory, /home/gbstack/Unity/Projects/ads-test/android-export/unityLibrary/unity-android-resources/build/generated/ap_generated_sources/debug/out)) org.gradle.api.internal.file.DefaultFilePropertyFactory$ToFileTransformer@481ca56c) before task ':unityLibrary:unity-android-resources:compileDebugJavaWithJavac' has completed is not supported

  • Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':unityLibrary:unity-android-resources:compileDebugJavaWithJavac'.
    at org.gradle.api.internal.tasks.properties.DefaultTaskProperties.resolve(DefaultTaskProperties.java:82)
    at org.gradle.execution.plan.LocalTaskNode.resolveMutations(LocalTaskNode.java:200)
    ...

    Caused by: org.gradle.api.InvalidUserCodeException: Querying the mapped value of map(java.io.File property(org.gradle.api.file.Directory, fixed(class org.gradle.api.internal.file.DefaultFilePropertyFactory$FixedDirectory, /home/gbstack/Unity/Projects/ads-test/android-export/unityLibrary/unity-android-resources/build/generated/ap_generated_sources/debug/out)) org.gradle.api.internal.file.DefaultFilePropertyFactory$ToFileTransformer@481ca56c) before task ':unityLibrary:unity-android-resources:compileDebugJavaWithJavac' has completed is not supported
    at org.gradle.api.internal.provider.TransformBackedProvider.lambda$beforeRead$0(TransformBackedProvider.java:84)
    at org.gradle.api.internal.provider.ValueSupplier$TaskProducer.visitContentProducerTasks(ValueSupplier.java:136)
    at org.gradle.api.internal.provider.TransformBackedProvider.beforeRead(TransformBackedProvider.java:81)
    at org.gradle.api.internal.provider.TransformBackedProvider.calculateOwnValue(TransformBackedProvider.java:63)
    at org.gradle.api.internal.provider.AbstractMinimalProvider.calculateValue(AbstractMinimalProvider.java:103)
    ...

Solution

Changing gradle from 7.1 to version to 6.x will fix this problem. I tried both 6.1 and 6.9, and both works

rigidbody2D.velocity.y not working

I'm really new to Unity and want to add a sprite and move it by press "left" and "right" key.

First I add a RigidBody component to the sprite, then add a Script Component.

Following is the code of script file:

But after I pressed the left key, "left" string is outputted to the console, but the sprite never moved. After a lot of trying, I found it's because I used "RigidBody" component but not "RigidBody2D" component for the sprite. What a foolish mistake..