Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle complains "No such file or directory"

I am using Android Studio & Gradle build script.

Under the root of my Android project, there is a folder named 'other', inside 'other' folder, there is a properties file my.properties.

-MyApp/
     …
    -other/
         -my.properties  
    -build.gradle

In my build.gradle, I try to access my.properties :

task accessMyProperties {
    def folderName = 'other';

    //Gradle complains this line
    def file = new File("$folderName/my.properties");
    ...
}

But gradle complains that:

* What went wrong:
A problem occurred evaluating project ':MyApp'.
> other/my.properties (No such file or directory)

Why gradle arises the above error? How to get rid of it?

like image 650
user842225 Avatar asked Jan 14 '15 16:01

user842225


People also ask

Where is the gradlew file?

The Wrapper shell script and batch file reside in the root directory of a single or multi-project Gradle build. You will need to reference the correct path to those files in case you want to execute the build from a subproject directory e.g. ../../gradlew tasks .

How do you clean gradlew?

To clean cache in react native, open terminal, go to your project android folder, and run gradlew clean command it will clear react native cache.


1 Answers

Be careful about using pure relative paths in Gradle build scripts; those rely on the working directory at the time the build is invoked, which isn't something you should depend on. It's much better to ground your paths against $projectDir or $rootDir. Try something like this:

def file = new File("$projectDir/$folderName/my.properties");

See http://www.gradle.org/docs/current/dsl/org.gradle.api.Project.html for a list of variables you can use.

like image 64
Scott Barta Avatar answered Oct 18 '22 08:10

Scott Barta