I have two module, app and module1
app is not dependency module1
module1 assembleRelease task will change data in app
so,I want to run module1:assembleRelease automatically when I run app:assembleRelease.
apply plugin: 'com.android.application'
android {
....
afterEvaluate {
preBuild.dependsOn({
runModuleaR.execute()
})
}
}
task runModuleaR(type: Exec) {
println "runModuleaR start"
commandLine "cmd", "gradlew", ':module1:assembleRelease'
println "runModuleaR finish"
}
is my build.gradle
But it has no effect
How do I change it?Thanks
Related
i want to use checkstyle plugin in my gradle project, the gradle documentation says that it will add a few tasks:
https://docs.gradle.org/current/userguide/checkstyle_plugin.html
checkstyleMain, checkstyleTest, checkstyleSourceSet
I added this into my app build.gradle file:
apply plugin: 'checkstyle'
I want to run gradle task from cmd to perform code style check, but there are no one checkstyle task. I checked the whole list by typing:
./gradlew tasks
I also tried to add checkstyle jar as library dependency to app module.
Can anyone tell me what i am doing wrong and how can i get my checkstyle tasks?
Well, the checkstyle plugin adds its tasks in the Other tasks virtual task group. Those are really the tasks which have not been assigned to a task group. So, they are shown only when you run ./gradlew tasks --all (note the --all).
Complete working build.gradle:
apply plugin: 'java';
apply plugin: 'checkstyle';
Then run ./gradlew tasks --all, output:
<...snip...>
Other tasks
-----------
checkstyleMain - Run Checkstyle analysis for main classes
checkstyleTest - Run Checkstyle analysis for test classes
<...snip...>
If you want the Checkstyle tasks to appear without --all, then assign them to a task group, for example:
tasks.withType(Checkstyle).each {
it.group = 'verification'
}
Looking at other Android projects, built with Gradle, that run checkstyle (thanks Square) I found that I needed to do some setup for the task to appear. Without the task declaration I would still see my initial error.
build.gradle:
...
apply plugin: 'checkstyle'
...
checkstyle {
configFile rootProject.file('checkstyle.xml')
ignoreFailures false
showViolations true
toolVersion = "7.8.1"
}
task Checkstyle(type: Checkstyle) {
configFile rootProject.file('checkstyle.xml')
source 'src/main/java'
ignoreFailures false
showViolations true
include '**/*.java'
classpath = files()
}
// adds checkstyle task to existing check task
afterEvaluate {
if (project.tasks.getByName("check")) {
check.dependsOn('checkstyle')
}
}
You also need a checkstyle configuration file, either by placing one at the default location as documented or by configuring it explicitly.
For example:
checkstyle {
config = resources.text.fromFile('config/checkstyle.xml')
}
I want to run my custom task after assembleDebug task in Android Studio.My normal build.gradle is
apply plugin: 'com.android.application'
android {
...
}
dependencies {
...
}
task printName{
println 'Hello Guffy'
}
printName.shouldRunAfter(tasks.assembleDebug)
// or printName.shouldRunAfter(assembleDebug)
// or assembleDebug.shouldRunAfter(printName)
which is not compiling.The gradle error is
Error:(36, 0) Could not get unknown property 'assembleDebug' for task set
Is assembleDebug or other tasks not available to custom tasks ? Or is there any basic error I am doing ? Thanks
Suggested by Piotr Zawadzki, putting task in quotes worked .
So the code should be like
printName.shouldRunAfter("assembleDebug")
Is there any way to run gradle task from app/build.gradle file, so that when I build release APK task "firebaseUploadReleaseProguardMapping" will run automatically.
You can use dependsOn for example (your app/build.gradle):
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-crash'
android {
}
dependencies {
}
task release
task archiveRelease(type: Copy) {
from './build/outputs/apk', './build/outputs/'
into "../releases/${rootProject.ext.configuration.version_code}"
include('app-release.apk', 'mapping/release/mapping.txt')
rename('app-release.apk', "${rootProject.ext.configuration.package}_${rootProject.ext.configuration.version_name}_${rootProject.ext.configuration.version_code}.apk")
}
project.afterEvaluate {
dependencyUpdates.dependsOn clean
assembleRelease.dependsOn clean
def publishApkRelease = project.tasks.getByName("publishApkRelease")
publishApkRelease.dependsOn assembleRelease
release.dependsOn publishApkRelease, firebaseUploadReleaseProguardMapping, archiveRelease
}
I created a new task called release. It depends on publishApkRelease (comes from gradle-play-publisher), firebaseUploadReleaseProguardMapping and archiveRelease. And publishApkRelease depends on assembleRelease.
At the ned you just call ./gradlew release and it will build your release version, uploads the apk to Google play, the mapping file to Firebase and archive a copy of the apk and mapping file.
How to configure the "gradle DependencyReport"-task of the project-report plugin for android so that it only contains dependencies
for one task "_releaseApk" but not for all tasks like
releaseCompile, debugCompile, debugApk, ...
The result should be similar to the output of
gradle -q app:dependencies --configuration _releaseApk
I have this app/build.gradle
// app/build.gradle
apply plugin: 'com.android.application'
apply plugin: 'project-report'
android {...}
dependencies {
// dependencies to be listed by DependencyReport
compile '...'
}
// these config-s do not work with gradle-2.14
// DependencyReport.configurations ["_releaseApk"]
// reports.configurations ["_releaseApk"]
and call
gradle app:DependencyReport
the generated app/build/reports/project/dependencies.txt contains
dependencies for all tasks like
releaseApk, releaseCompile, debugCompile, debugApk, ...
I only want dependencies for releaseApk
After having read the android guide on testing with the android gradle plugin, I wanted to set up JUnit tests for my POJO's that don't run with the instrumented tests. The idea was that tests for code that doesn't depend on Android should be very fast (and facilitate TDD).
Is there a standard way to set up a source set and task in build.gradle to accomplish this? That is the main question, the secondary question is what's wrong with my attempt below...
I'm using Android Studio 0.4.2 and Gradle 1.9, experimenting with a simple JUnit test class in a new "test" folder. Here is what I have so far, but when I run "gradle testPojo" I get this result:
:android:assemble UP-TO-DATE
:android:compileUnitTestJava UP-TO-DATE
:android:processUnitTestResources UP-TO-DATE
:android:unitTestClasses UP-TO-DATE
:android:testPojo FAILED
* What went wrong:
Execution failed for task ':android:testPojo'.
> failed to read class file
/path/to/project/android-app/build/classes/unitTest/TestClass.class
I verified that the class is in fact there, so I'm confused as to why the task is not able to read the file.
Here is the build.gradle file:
...
sourceSets {
unitTest {
java.srcDir file('src/test/java')
resources.srcDir file('src/test/resources')
}
}
dependencies {
...
unitTestCompile 'junit:junit:4.11'
}
configurations {
unitTestCompile.extendsFrom instrumentTestCompile
unitTestRuntime.extendsFrom instrumentTestRuntime
}
task testPojo(type: Test, dependsOn: assemble){
description = "Run pojo unit tests (located in src/test/java...)."
testClassesDir = sourceSets.unitTest.output.classesDir
android.sourceSets.main.java.srcDirs.each { dir ->
def buildDir = dir.getAbsolutePath().split('/')
buildDir = (buildDir[0..(buildDir.length - 4)] + ['build', 'classes', 'debug']).join('/')
sourceSets.unitTest.compileClasspath += files(buildDir)
sourceSets.unitTest.runtimeClasspath += files(buildDir)
}
classpath = sourceSets.unitTest.runtimeClasspath
}
check.dependsOn testPojo
I'd suggest you to use robolectric, declare it like this:
classpath 'org.robolectric:robolectric-gradle-plugin:0.11.+'
And then apply the plugin:
apply plugin: 'robolectric'