Custom Gradle tasks not being run under Android Studio? [duplicate] - android

I have just upgraded from Android Studio 0.6 to 0.8.3 (on Linux Mint 15) and now my build is not working as expected. In my gradle file I have lots of custom Tasks which do prebuild steps (copying files, resizing images, etc).
// lots of tasks snipped
task convertToOGG(type:Exec) {
ext.srcDir = 'bb/src/main/buildAssets/wavs/'
ext.destDir = 'bb/src/main/res/raw/'
workingDir '..'
commandLine 'python', 'scripts/convertToOGG.py', srcDir, destDir
}
gradle.projectsEvaluated {
copyRes.dependsOn resizeImageIcon
convertToOGG.dependsOn copyRes
preBuild.dependsOn copyRes, convertToOGG
}
These don't run by default in the IDE any more. They are dependencies of the preBuild step, but don't run if I manually run the preBuild step in the IDE:
Executing tasks: [preBuild]
Configuration on demand is an incubating feature.
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:Bb:preBuild
:libraries:bbengine:preBuild
:libraries:facebook:preBuild
BUILD SUCCESSFUL
Total time: 2.296 secs
Its like the gradle.projectsEvaluated block is no longer run. Strangely if I run it in a terminal it works:
pickles#sirius /workspace/bb/code/trunk/bb $ ./gradlew preBuild
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:Bb:resizeImageIcon
/workspace/babybot/code/trunk/BbProject
RESIZE IMAGE: Bb/src/main/buildAssets/oversize/image_icon.png
(1024, 1024) RGBA
Targets: 5
Bb/src/main/buildAssets/res/drawable-xxhdpi/ic_launcher.png (144, 144)
Saved a (144, 144) version to Bb/src/main/buildAssets/res/drawable-xxhdpi/ic_launcher.png
Bb/src/main/buildAssets/res/drawable-xhdpi/ic_launcher.png (96, 96)
Saved a (96, 96) version to Bb/src/main/buildAssets/res/drawable-xhdpi/ic_launcher.png
Bb/src/main/buildAssets/res/drawable-hdpi/ic_launcher.png (72, 72)
Saved a (72, 72) version to Bb/src/main/buildAssets/res/drawable-hdpi/ic_launcher.png
Bb/src/main/buildAssets/res/drawable-mdpi/ic_launcher.png (48, 48)
Saved a (48, 48) version to Bb/src/main/buildAssets/res/drawable-mdpi/ic_launcher.png
Bb/src/main/buildAssets/res/drawable-ldpi/ic_launcher.png (36, 36)
Saved a (36, 36) version to Bb/src/main/buildAssets/res/drawable-ldpi/ic_launcher.png
:Bb:copyRes UP-TO-DATE
:Bb:convertToOGG
Skipping chunk of type "LIST", length 106
Opening with wav module: WAV file reader
Encoding "audio_robot_jump.wav" to
"audio_robot_jump.ogg"
at quality 3.00
[ 79.6%] [ 0m00s remaining] /
Done encoding file "audio_robot_jump.ogg"
File length: 0m 02.0s
Elapsed time: 0m 00.1s
Rate: 39.5641
Average bitrate: 48.3 kb/s
:Bb:preBuild
:libraries:bbengine:preBuild
:libraries:facebook:preBuild
BUILD SUCCESSFUL
Total time: 15.619 secs
Can anyone help? Thanks

I fixed it by changing:
gradle.projectsEvaluated {
copyRes.dependsOn resizeImageIcon
convertToOGG.dependsOn copyRes
preBuild.dependsOn copyRes, convertToOGG
}
to
copyRes.dependsOn resizeImageIcon
convertToOGG.dependsOn copyRes
preBuild.dependsOn copyRes, convertToOGG

Related

Azure AppCenter: Android build succeeds but no APKs found

I've been setting up Azure App Center build pipelines and after some troubleshooting, I managed to make our debug build succeed. The issue is that, it seems to not be able to find any of the generated APKs in the expected directories. Any ideas on why that is?
Here's the specific part of the output log:
BUILD SUCCESSFUL in 4m 28s 130 actionable tasks: 124 executed, 6
up-to-date
##[section]Finishing: Gradle Task
##[section]Starting: Android Postprocess
============================================================================== Task : Shell script Description : Run a shell script using
Bash Version : 2.206.0 Author : Microsoft Corporation Help
:
https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/shell-script
============================================================================== [command]/bin/bash
/Users/runner/runners/2.206.1/scripts/android-postprocess.sh
/Users/runner/work/1/s/build/outputs/apk Removing all ABI or density
dependent APKsā€¦ find: /Users/runner/work/1/s/build/outputs/apk: No
such file or directory find: /Users/runner/work/1/s/build/outputs/apk:
No such file or directory find:
/Users/runner/work/1/s/build/outputs/apk: No such file or directory
Found 0 APK file(s) Found 0 unaligned APK file(s) find:
/Users/runner/work/1/s/build/outputs/apk: No such file or directory
/Users/runner/runners/2.206.1/scripts/android-postprocess.sh: line 36:
pushd: /Users/runner/work/1/s/build/outputs/apk/..: No such file or
directory
/Users/runner/runners/2.206.1/scripts/android-postprocess.sh: line 43:
popd: directory stack empty
##[error]The process '/bin/bash' failed with exit code 1
##[error]Bash failed with error: The process '/bin/bash' failed with exit code 1
##[section]Finishing: Android Postprocess
I also have a post-clone bash script for generating the local.properties file which contains some secrets, and it seems to work just fine since the build uses it and goes through with it.
Sadly, I can't infer much from the logs, I'm not a DevOps engineer and have practically 0 experience in this sector.

Unit test always passed even with false assertions values on Android Studio?

Unit test always passed even with false assertions values on Android Studio, for example when writing this method it passed
#Test
fun testAssert(){
assertEquals(1,2)
}
I don't know why this happens and I checked my test configuration if it has a problem but I think there is no problem
And here the full build print on running the test
"C:\Program Files\Android\Android Studio\jre\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\Android\Android Studio\lib\idea_rt.jar=53441:C:\Program Files\Android\Android Studio\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Amin\AppData\Local\Temp\classpath152820636.jar com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 (package.....).ApiServiceTest,testAssert
Process finished with exit code 0
on using gradle/app:test in terminal I got this
> Configure project :app
WARNING: API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'.
It will be removed in version 5.0 of the Android Gradle plugin.
For more information, see TBD.
To determine what is calling BaseVariant.getApplicationIdTextResource, use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.github.bumptech.glide:compiler:
4.12.0'.
BUILD SUCCESSFUL in 5s
90 actionable tasks: 90 up-to-date

Android Jitpack build library not working

I have a library which includes transitive libraries inside. I want to include this library to another project with JitPack.
First of all I prepared my code according JitPack's docs https://jitpack.io/docs/BUILDING/ and https://jitpack.io/docs/PRIVATE/
Then I created a private repository and uploaded there my library. Created release and installed gradle.
Then I get gradle dependency from JitPack, but it built with error:
BUILD SUCCESSFUL in 3m 16s
179 actionable tasks: 174 executed, 5 up-to-date
Build tool exit code: 0
Looking for artifacts...
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Looking for pom.xml in build directory and ~/.m2
Found artifact: https://github.com/ilyinp:app:1.0.4
2020-01-21T05:25:55.722858568Z
Exit code: 0
ERROR: No build artifacts found
Expected artifacts in: $HOME/.m2/repository//github.com/ilyinp/app
Also on my computer I have directory $HOME/.m2/repository/https:/github/com/ilyinp/app/unspecified which contains files: app-unspecified.aar, app-unspecified.pom, app-unspecifed-javadoc.jar, app-unspecified-sources.jar
File app-unspecified.pom contains info about all third-party libs and my own transitive libs.
How to make JitPack builds work?

Can't publish on jitpack

I have a problem with publishing multi-flavor library to jitpack.
The log says that build success but the status is error
I've followed instructions on jitpack site but their sample uses old gradle version and it did not work with gradle 4.4
Here is the log:
Build starting...
Start: Fri Apr 20 07:35:56 UTC 2018
Git:
1.28.1-1-g932f4d8
commit 932f4d88e13b1c8c52b4dbae8c203e7d52a0eadf
Author: yzheka
Date: Fri Apr 20 10:34:49 2018 +0300
jitpack config
Run gradle build
Gradle build script
Found gradle version: 4.4.
Using gradle wrapper
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Djavax.xml.accessExternalSchema=all
Downloading https://services.gradle.org/distributions/gradle-4.4-all.zip
..............................................................................................
Unzipping /home/jitpack/.gradle/wrapper/dists/gradle-4.4-all/9br9xq1tocpiv8o6njlyu5op1/gradle-4.4-all.zip to /home/jitpack/.gradle/wrapper/dists/gradle-4.4-all/9br9xq1tocpiv8o6njlyu5op1
Set executable permissions for: /home/jitpack/.gradle/wrapper/dists/gradle-4.4-all/9br9xq1tocpiv8o6njlyu5op1/gradle-4.4/bin/gradle
------------------------------------------------------------
Gradle 4.4
------------------------------------------------------------
Build time: 2017-12-06 09:05:06 UTC
Revision: cf7821a6f79f8e2a598df21780e3ff7ce8db2b82
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 1.8.0_131 (Oracle Corporation 25.131-b11)
OS: Linux 4.14.15-xxxx-std-ipv6-64 amd64
0m4.923s
Getting a list of gradle tasks
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Djavax.xml.accessExternalSchema=all
Running: ./gradlew clean -Pgroup=com.github.yzheka -Pversion=-1.28.1-g932f4d8-1 -xtest -xlint install
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Djavax.xml.accessExternalSchema=all
:clean
:app:clean UP-TO-DATE
:busybox:clean UP-TO-DATE
:busybox:install
BUILD SUCCESSFUL in 0s
4 actionable tasks: 2 executed, 2 up-to-date
Looking for artifacts...
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Djavax.xml.accessExternalSchema=all
EXIT_CODE=0
2018-04-20T07:36:32.030445377Z
Exit code: 0
No build artifacts found
In jitpack log you can see why jitpack can't publish your library. Just delete some part of your code because of jitpack error.
Cannot get the value of write-only property 'publishNonDefault' for object of type com.android.build.gradle.LibraryExtension.
if( android.publishNonDefault && variant.name == android.defaultPublishConfig ) {
def bundleTask = tasks["bundle${name.capitalize()}"]
artifacts {
archives(bundleTask.archivePath) {
classifier null
builtBy bundleTask
}
}
}
}
}
Then jitpack do not show the error when publishing your library. Works like a charm. To publish your library just realese once again then publish your libary.
I just made it for you as an example see the repository which I forked from you here https://github.com/markizdeviler/Busybox
This way is worked for me:
Add these line in the Module gradle after dependencies part :
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
groupId = 'com.github.yourgitid' //your git id
artifactId = 'Myket-Intent' //your-repository
version = '0.1.15' // same as Tag
}
}
}
}
after that you can see:
BUILD SUCCESSFUL in 41s
123 actionable tasks: 120 executed, 3 up-to-date
Build tool exit code: 0
Looking for artifacts...
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Looking for pom.xml in build directory and ~/.m2
Found artifact: com.github.Mori-hub:Myket-Intent:0.1.15
2022-01-22T09:38:10.889110195Z
Exit code: 0
Build artifacts:
com.github.Mori-hub:Myket-Intent:0.1.15

gradle: Error running 'Unnamed': No task to execute is specified

I got an Android app for further development as a zip file. I unzipped and opened this in Jetbrains IDEA File> Open (Folder Address).
IDEA immediately realized that it was an android app.
This did not start.
Later I copied the gradle to C: \ Gradle and added it to the path (works well, see gradle -v in the screenshot).
But I still get errors below. How you could help. Thanks.
10:21 Frameworks Detected
Android framework is detected.
Configure
10:22 All files are up-to-date
10:22 Error running 'build': Module 'monkey' is not backed by gradle
10:23 All files are up-to-date
10:23 Error running 'build (1)': No jdk for module 'monkey-tree-app'
10:23 All files are up-to-date
10:23 Error running 'build': Module 'monkey-tree-app' is not backed by gradle
10:24 All files are up-to-date
10:24 Error running 'build': No jdk for module 'monkey-tree-app'
10:30 Error running 'Unnamed': No task to execute is specified
10:56 Error running 'Unnamed (1)': No task to execute is specified

Categories

Resources