Android Gradle SourceSet Resources not copying base dir - android

I'm currently working on automating an android build via gradle but my build.gradle file isn't copying the entire res/ or assets/ dirs into my produced apk.
Clarification:
The contents of the needed res/ & assets/ dirs are copied into the apk, but the actual res/ and assets/ dirs are nowhere to be found. For this automation to match the manual process in place, I need a seemless transition from manual build process to automated build process. (no difference in produced apk)
I know it has to be how I'm addressing the sourceSets and resources, but I can't find any direction/advice on what I'm doing wrong.
Here's my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src','../res','../assets']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
defaultConfig {
applicationId "***************"
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
zipAlignEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
zipAlignEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
My directory structure(loosely represented):
AppBase/
+res/
+assets/
-gradle files
+AndroidApp
+src/
-gradle files

I think you should be doing something like this, though, I am not too sure about the relative paths.
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res','../res']
assets.srcDirs = ['assets', '../assets']
}
}

Related

Sourcesets causes: app/AndroidManifest.xml' specified for property 'manifest' does not exist error

I have 4 product flavours. I am looking to set the source sets in order to assign the correct app name string and launcher Icon..
here is my gradle:
defaultConfig {
applicationId "com.test.testing"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "0.0.4"
}
productFlavors{
flavour1{
applicationId "com.etlie.stockclient.flavour1"
}
flavour2{
applicationId "com.etlie.stockclient.flavour2"
}
flavour3{
applicationId "com.etlie.stockclient.flavour3"
}
flavour4{
applicationId "com.etlie.stockclient.flavour4"
}
}
sourceSets{
main{
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
flavour1{
res.srcDir 'variants/flavour1/res'
}
flavour2{
res.srcDir 'variants/flavour2/res'
}
flavour3{
res.srcDir 'variants/flavour3/res'
}
flavour4{
res.srcDir 'variants/flavour4/res'
}
}
Here is the product structure:
app
--java
--main
|__AndroidManifest
--variant
|__flavour1
|__drawable-hdpi
|__drawable-xhdpi
|__drawable-xxhdpi
|__values
|__flavour2
|__drawable-hdpi
|__drawable-xhdpi
|__drawable-xxhdpi
|__values
|__flavour3
|__drawable-hdpi
|__drawable-xhdpi
|__drawable-xxhdpi
|__values
|__flavour4
|__drawable-hdpi
|__drawable-xhdpi
|__drawable-xxhdpi
|__values
So the project structure has changed, but the location of the AndroidManifest.xml hasn't. If anyone knows how to fix this error I'd appreciate some help
Provide the full path (from your module's build.gradle file) to your manifest:
manifest.srcFile 'main/AndroidManifest.xml'
The default project structure is different though, so for me its src/main/AndroidManifest.xml.

gradle android plugin variant dependencies: DSL method not found

I have a multi-flavor project, with flavors called "qa" and "prod". I need to include different versions of a library depending on both the build type and the flavor.
The documentation at http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Type-Product-Flavor-Build-Variant suggests that build types and flavors can be combined, using a "flavorBuildCompile" notation. However when I do this I get this error:
Error:(88, 0) Gradle DSL method not found: 'qaDebugCompile()'
I'm pretty sure this used to work (in an older version of gradle). Currently using gradle 2.1. I haven't found an explanation if the way to do this has changed.
Note, it works fine if I use "flavorCompile" notation, it only fails when I include the build type as well.
Here is the outline of my build script:
android {
compileSdkVersion 17
buildToolsVersion "20"
...
productFlavors {
qa {
applicationId "com.myapp.qa"
}
prod {
applicationId "com.myapp.prod"
}
}
sourceSets {
main {
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
manifest.srcFile 'AndroidManifest.xml'
}
qa {
res.srcDirs = ['res_qa']
}
prod {
res.srcDirs = ['res_prod']
}
}
}
...
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
qaCompile 'com.myapp.integration:other_lib:3.0+#aar' //this is fine
qaDebugCompile 'com.myapp.integration:mylib_qa:3.0+#aar' //this fails!
prodDebugCompile 'com.myapp.integration:mylib_prod:3.0+#aar'
qaReleaseCompile 'com.myapp.release:mylib_qa:3.0+#aar'
prodReleaseCompile 'com.myapp.release:mylib_prod:3.0+#aar'
}

Gradle + Android, want to overwrite /assets with custom folder in buildFlavor

In my current build scripts I have special /res/ and /assets folders that I copy over the working versions of the files at build time. In /assets/ is bundled data (sql and a text file) while in /res/values/ I have a connection.xml values file.
There are already duplicates of these files in the working directory, however at build time I want to use the ones from the /config/ folder of my project and copy them over the ones in the /res and /assets for the current build.
In my verbose logging I get a
"com.android.ide.common.res2.DuplicateDataException" when it tries to copy the file.
Any idea's how to handle this? I can make the filename unique, but the key/value pairs inside it will not be? Would that solve the issue?
My Build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.0'
}
}
apply plugin: 'android'
android {
compileSdkVersion "Google Inc.:Google APIs:18"
buildToolsVersion "17"
signingConfigs {
release {
storeFile file("../../TioClient/keystore/android.keystore")
storePassword "REDACTED"
keyAlias "pge-android"
keyPassword "lightmaker"
}
}
buildTypes {
dev {
signingConfig signingConfigs.release
}
tps {
signingConfig signingConfigs.release
}
production {
signingConfig signingConfigs.release
}
}
defaultConfig {
minSdkVersion 8
targetSdkVersion 15
}
dependencies {
compile project(':TioClient');
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = []
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
tps {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = []
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res','config/tps/res']
assets.srcDirs = ['assets', 'config/tps/assets']
}
instrumentTest.setRoot('tests')
}
}
You can define assets at the buildtype level or product flavor level by including appropriate folders in your src.
Build type resources override flavor resources which override main resources.

Problems with gradle android plugin and buildtype sourcesets

I am new to gradle and want to use the gradle android plugin with flavors, buildtypes and custom sourcesets. Building with flavors and buildtypes works find. Unfortunately I have a legacy project directory structure, so I have to customize the res directory for the buildtypes.
Somehow the additional resources (basically some string config values) for a buildtype do not seem to get merged into the build and do not replace resource keys from the main tree.
This was asked before, I know there is
Gradle productflavors sourcesets and old project structure
and
How can I specify per flavor buildType sourceSets?
I want to quote Xavier from the first post: "You need to first declare your flavors and then customize the sourceSets."
I understand that a flavor configuration automatically creates sourcesets and that they need to be modified afterwards. Thats what I tried in the following build.gradle, but my added "res.srcDirs" for each buildtype seem to get ignored and I cannot figure out why.
In the second post (last comment with the link to github), I see complicated sourceset modification in the build.gradle. Is there also a simpler way for this? (see here: https://github.com/shakalaca/learning_gradle_android/blob/master/07_tricks/app/build.gradle)
This is my build configuration for the gradle android plugin:
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
productFlavors {
normal {
}
proguard {
proguardFile file("proguard-project.txt")
}
}
buildTypes {
dev {
packageNameSuffix ".dev"
debuggable true
signingConfig android.signingConfigs.debug
}
beta {
packageNameSuffix ".beta"
debuggable true
signingConfig android.signingConfigs.debug
}
live {
packageNameSuffix ".live"
debuggable true
signingConfig android.signingConfigs.debug
}
}
sourceSets.dev.res.srcDirs = ['variations/dev']
sourceSets.beta.res.srcDirs = ['variations/staging']
sourceSets.live.res.srcDirs = ['variations/live']
}
If you change the order of your script you can have a much better structure and make it easier to read.
Say you have a release, beta and debug type and you want a different source dir you can do it like this:
buildTypes {
release {
debuggable false
jniDebugBuild false
runProguard true
proguardFile 'proguard-android.txt'
// Links to signing config above.
signingConfig signingConfigs.release
}
debug {
packageNameSuffix ".debug"
versionNameSuffix ".debug"
}
beta {
// Import release code - avoid having the same code twice!
initWith release
packageNameSuffix ".beta"
versionNameSuffix ".beta"
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
release {
res.srcDirs = ['res', 'res-release']
}
beta {
res.srcDirs = ['res', 'res-beta']
}
debug {
res.srcDirs = ['res', 'res-debug']
}
}
Notice the order of buildTypes and sourceSets!
Your build.gradle should be fine, check your variations directory, the dev/stagin/live folder structure should be the same with res directory.
app/AndroidManifest.xml
app/src/com/...
app/res/values/strings.xml
app/res/layout/main_activity.xml
app/variations/dev/values/strings.xml
app/variations/staging/values/strings.xml
app/variations/live/values/strings.xml
BTW you defined the proguardFile but there's no runProguard true

How to execute task in Gradle one by one

I have this gradle build file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
classpath 'com.eriwen:gradle-css-plugin:1.2.1'
classpath 'com.eriwen:gradle-js-plugin:1.5.1'
}
}
apply plugin: 'android'
apply plugin: 'js'
apply plugin: 'css'
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/cordova-2.7.0.jar')
compile files('libs/libGoogleAnalyticsV2.jar')
}
task MinifyJSForRelease {
tasks.add(name:"copyTask2", type:Copy){
from 'assets/'
into 'build/minifiedassets/assets'
}
it.dependsOn copyTask2
def tester = fileTree(dir:"build/minifiedassets/assets", include:"**/*.js");
println tester
tester.eachWithIndex {File file, idx ->
tasks.add(name: "makeMinifyJS${idx}", type: com.eriwen.gradle.js.tasks.MinifyJsTask) {
source = file
dest = "${file.path}"
closure {
compilerOptions.languageIn = "ECMASCRIPT5"
}
}
}
it.dependsOn tasks.matching { Task task -> task.name.startsWith("makeMinifyJS")}
}
build.dependsOn MinifyJSForRelease
android {
compileSdkVersion 17
buildToolsVersion "17"
signingConfigs {
release {
storeFile file('keystores/mobilecoe_android.keystore')
storePassword "mobilecoe"
keyAlias "MobileCoE"
keyPassword "mobilecoe"
}
}
defaultConfig {
minSdkVersion 10
targetSdkVersion 16
}
buildTypes {
debug {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
release {
signingConfig signingConfigs.release
zipAlign true
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['build/minifiedassets/assets']
}
instrumentTest.setRoot('tests')
}
}
}
}
I Want to run the task MinifyJSForRelease like the first thing would be to copy the assets folder to where I want and then when that is finished I want to minify the JS files.
Now when I run the task it copies the folder but not reaching the end the next function says it has nothing to minify but if I run the task the second time(when the folder is already copied) it fiends it and does everything.
What am I do in wrong?
I need to:
copy folder
Get the folder and minify its js files
Could some one help me out?
I'm a total virgen to Gradle, So I can only provide you with educated guess:
unify the way you declare the dependencies
taskB.dependsOn tasksA
force the order of the task (in add of the dependency)
taskB.mustRunAfter(taskA)
add logs, to see if the task is executed VS the tasks does not do what you expect.
Adding dependencies to a task / Ordering tasks
http://www.gradle.org/docs/current/userguide/more_about_tasks.html
please, provide us with the solution once you got it !

Categories

Resources