Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gradle - How to include assets from the root project?

I have the following project structure

MyProject
|-- build.gradle
|-- client.private
|-- server.public
|-- app
|   |-- build.gradle
|   |-- lint.xml
|   |-- proguard-project.txt
|   |-- project.properties
|   `-- src

and would like to include client.private and server.public files into the assets folder of the final apk but unfortunately not able to do so.

Have the following in my app/build.gradle

...
android {
    ...
    applicationVariants.all { variant ->
        variant.mergeAssets.doLast {
            copy {
              from(['../client.private', '../server.public'])
              into("${buildDir}/assets/${variant.dirName}")
            }
        }
    }
}

but it only copies the files to app/build/assets/debug, its not packaged with the apk.

like image 266
Krishnaraj Avatar asked Dec 10 '22 19:12

Krishnaraj


1 Answers

EDITED

Please try to use sourceSets. (Path edited)

android {
  sourceSets {
    main {
        assets.srcDirs = ['../client.private','../server.public']
    }
  }
}

You can check path each assets directories.

afterEvaluate {
    android.sourceSets.main.assets.srcDirs.each{println it}
}
like image 131
takahirom Avatar answered Dec 15 '22 00:12

takahirom