Run firebaseUploadReleaseProguardMapping task from app/build.gradle file - android

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.

Related

Android AAR artifactory publish executes before assemble

I have an Android library project and I am trying to publish the AAR files to JFrog artifactory using gradle.
Once I have the AAR files and when I execute the build task, the publish is working as expected, the problem is that I am not able to do it as part of my build process if the AAR files are not there.
I want to publish the AAR files when ever a new one is available. I tried to put assembleIntegrated.finalizedBy (artifactoryPublish), but that didn’t help.
The publish task gets triggered before the AARs are generated.
mygradle.gradle -->
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
File AARFile1 = file("$buildDir/outputs/aar/my_aar_file1.aar")
File AARFile2 = file("$buildDir/outputs/aar/my_aar_file2.aar")
publishing {
publications {
AAR1(MavenPublication) {
groupId repoFolder
version libVersion
// Tell maven to prepare the generated "*.aar" file for publishing
if (AARFile1.exists()) {
artifactId libRelease
artifact(AARFile1)
} else {
println 'AAR1 files not found in' + AARFile1.absolutePath
}
}
AAR2(MavenPublication) {
groupId repoFolder
version libVersion
// Tell maven to prepare the generated "*.aar" file for publishing
if (AARFile2.exists()) {
artifactId libDebug
artifact(AARFile2)
} else {
println 'AAR2 files not found in' + AARFile2.absolutePath
}
}
}
}
artifactory {
contextUrl = "https://bintray.com/jfrog/artifactory:8080"
publish {
repository {
// The Artifactory repository key to publish to
repoKey = 'my_key'
username = 'my_username'
password = 'my_encrypt_password'
}
defaults {
// Tell the Artifactory Plugin which artifacts should be published to Artifactory.
if (AARFile1.exists() || AARFile2.exists()) {
publications('AAR1', 'AAR2')
publishArtifacts = true
// Properties to be attached to the published artifacts.
properties = ['qa.level': 'basic', 'dev.team':'Me' ]
// Publish generated POM files to Artifactory (true by default)
publishPom = true
}
}
}
}
I see the gradle tasks list as below:
executing tasks: [assembleIntegrated]
AAR1 files not found in /myfolder/.../my_lib_project/app/build/outputs/aar/my_aar_file1.aar
AAR2 files not found in /myfolder/.../my_lib_project/app/build/outputs/aar/my_aar_file2.aar
.
.
.
> Task :app:preBuild UP-TO-DATE
> Task :app:test UP-TO-DATE
> Task :app:check
> Task :app:build
> Task :app:artifactoryPublish
> Task :artifactoryDeploy
It happens, because you add files manually to the maven publication. When maven publish runs, these files are not exists. So, you should configure task dependencies manually. When you add a publication to your project, Gradle will generate some tasks with combination of your publication names, and repo names. Something like that: publish{publicationName}PublicationTo{RepositoryName}Repository. Thus, you should setup these task to depends on assembleIntegration task.
Or you can use android-maven-publish plugin, which do this work automatically.

how to run other gradle command in the gradle

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

Checkstyle Plugin does not add gradle tasks

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')
}

Why the gradle war task is skipped?

I am a new convert to Gradle. Most of the tasks work fine. However, I see that the war task is always skipped. When I run in the debug mode, I see the following logs -
09:12:34.889 [LIFECYCLE] [class
org.gradle.internal.buildevents.TaskExecutionLogger] :war 09:12:34.889
[DEBUG]
[org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter]
Starting to execute task ':war' 09:12:34.889 [INFO]
**[org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter] Skipping task ':war' as task onlyIf is false.** 09:12:34.889 [DEBUG]
[org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter]
Finished executing task ':war' 09:12:34.889 [LIFECYCLE] [class
org.gradle.internal.buildevents.TaskExecutionLogger] :war SKIPPED
I am not sure why onlyIf is false. I did search on internet. But I did not find anything related.
Here is my Gradle file -
buildscript {
ext {
springBootVersion = '2.0.0.M2'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'findbugs'
apply plugin: 'jacoco'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.retry:spring-retry:1.2.1.RELEASE")
compile("org.springframework.data:spring-data-cassandra:2.0.0.M4")
compile("io.reactivex.rxjava2:rxjava:2.1.1")
//compile("javax.persistence:persistence-api:1.0.2")
//compile("org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.zaxxer:HikariCP:2.6.0")
// Test Dependencies
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.powermock:powermock-mockito-release-full:1.6.4")
testCompile("org.mockito:mockito-core:2.0.3-beta")
testCompile("org.cassandraunit:cassandra-unit:3.1.3.2")
testCompile("org.cassandraunit:cassandra-unit-spring:2.2.2.1")
testCompile("com.h2database:h2:1.4.196")
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:21.0'
testImplementation 'junit:junit:4.12'
}
Here is the image of my project structure -
If you could help me with generating the war file that would be great.
try it
war {
enabled = true
}
I have also faced same issue with jar task, it is skipping the jar generation as it is taking the default value for enabled=false if you dont specify any external value.
Same solution works for jar as well based on #Alexander Servetnik
Enrironment:
SpringBoot 2.x and
gradle 4.4
jar {
baseName = <your-jar name>
enabled=true
}
Try upgrading gradle version
Spring Boot’s Gradle plugin requires Gradle 6 (6.3 or later). Gradle 5.6 is also supported but this support is deprecated and will be removed in a future release.
https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/
This is because the Springboot Gradle plugin will create a bootJar task and by default will disable jar and war task.
You can enable this, by adding the below code in projectName.gradle
jar {
baseName = 'projectName'
enabled=true
manifest {
....
}
}

"Task 'compile' is ambiguous in root project" - Android Studio

Every time I try to run my project, clean it or build it I get a gradle error:
Error:FAILURE: Build failed with an exception.
* What went wrong:
Task 'compile' is ambiguous in root project 'FifiFun2'. Candidates are: 'compileDebugAidl', 'compileDebugAndroidTestAidl', 'compileDebugAndroidTestJavaWithJavac', 'compileDebugAndroidTestNdk', 'compileDebugAndroidTestRenderscript', 'compileDebugAndroidTestSources', 'compileDebugJavaWithJavac', 'compileDebugNdk', 'compileDebugRenderscript', 'compileDebugSources', 'compileDebugUnitTestJavaWithJavac', 'compileDebugUnitTestSources', 'compileLint', 'compileReleaseAidl', 'compileReleaseJavaWithJavac', 'compileReleaseNdk', 'compileReleaseRenderscript', 'compileReleaseSources', 'compileReleaseUnitTestJavaWithJavac', 'compileReleaseUnitTestSources'.
* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
I have tried running gradle tasks with the options above (stacktrace,info,debug) but nothing helpful came up.
gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
main gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.user_pc.myapplication"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
}
settings.gradle file:
include ':app'
Screenshot of the problem:
The problem is, your gradlew file is in the root of your project and you are trying to run an ambiguous task compile from the root of the project, in which the compiler does not know the actual task to run, this will lead to TaskSelectionException. You can run a single task, this stackoverflow question will help you
Check the following :
Can you build and run another project? (New one for instance).
Try defining a debug buildType and resync gradle then build.
Check if you have a good proyect structure or set it in gradle.build if you don't.
If non of thoses work am out of ideas, sorry.
Remove the code
task clean(type: Delete) {
delete rootProject.buildDir
}
from your gradle file, then clean and rebuild your project.
None of the above worked for me. The solution I found was
Install latest version of Cordova.
Install latest version of gradle. You can do this Manually. Remember to updated GRADLE_HOME and PATH in System variables
Remove and reinstall android in your project. Remember to back up items such as Icons etc
Run cordova build android --prod --release. This will generate an App bundle instead of an APK file. This command will also hopefully download the latest version of gradle for your project.
Hope that helps some poor soul somewhere who is at their wits end.
You need to clean the project(Top level menu Build --> Clean Project) first and then run the command again.

Categories

Resources