Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidStudio: add virtual folder in gradle

I use the build.gradle file to collect several folders on my computer in my app's asset folder:

sourceSets {
    main {
        assets.srcDirs = ['../someFolder/', 'src/main/assets']
    }
}

This leads to my asset folder having the files of someFolder and the "original" asset folder:

//The "physical" folders

../someFolder
  |- file1.txt
  |- file2.txt
  |- file3.txt
src/main/assets
  |- asset1.txt

//...become this:

assets
  |- file1.txt
  |- file2.txt
  |- file3.txt
  |- asset1.txt 

How can I redirect the paths in gradle so that my asset folder contains a folder "someFolder" with all the files from someFolder, e.g:

assets
  |- someFolder
  |--- file1.txt
  |--- file2.txt
  |--- file3.txt
  |- asset1.txt 
like image 670
PhilLab Avatar asked Aug 11 '15 14:08

PhilLab


People also ask

How do I change the gradle folder in Android Studio?

To change its path go to this path File > Settings... > Build, Execution, Deployment > Gradle In the Global Gradle settings Change Service directory path to what you want.

What is gradle folder in Android Studio?

gradle file, located in the root project directory, defines dependencies that apply to all modules in your project. By default, the top-level build file uses the plugins block to define the Gradle dependencies that are common to all modules in the project.


1 Answers

1) Create folder inside of the project as your external assets ./extAssets

sourceSets.main.assets.srcDirs = ['src/main/assets', './extAssets']

2) Link all your external directories inside this folder

$ cd extAssets/
$ ln -s ../../someFolder/ someFolder

As result you will see

assets
  |- someFolder
  |--- file1.txt
  |--- file2.txt
  |--- file3.txt
  |- asset1.txt 

without any file copying

like image 94
Stas Parshin Avatar answered Nov 15 '22 19:11

Stas Parshin