Custom Task in Gradle (Android) - android

(gradle newbie question)
I am looking to run a custom task with code from this thread. This is to do with setting up build env for release/debug etc...
Since the code bloats the original boilerplate code, I would like to do following for readability and extensibility -
Move the code to separate file as a task/def(Gist of the Code
Run the task/def before assembleDebug/Release
Here are problems I face when task is appended at the end of build.gradle file:
a) If I run just the task ./gradlew buildCustom , I get error
Could not find method defaultConfig() for arguments
b) If I try to use doLast I get error
Could not find method doLast() for arguments [task ':app:assembleDebug'] on task ':app:buildCustom'.
There is something very obvious that I donot understand, appreciate any help.

Related

Android Detekt Build failed

I tried to generate code report using detekt and when execute the below command in terminal
gradle detekt
it showing build failed with below message.
* What went wrong:
Execution failed for task ':app:detekt'.
> Build failed with 395 weighted issues.
As others have said in the comments, this means you have 395 issues in your code (kind of like lint warnings).
Detekt has a maxissues: property that determines whether or not to fail the build if your issues surpass the allowed number of maxissues. What I did was search the whole project for maxissues, which will take you to your detekt-config.yml or default-detekt-config.yml. There, you can change your maxissues to whatever you want.
In our old code base, we had 900 some issues, so I changed mine from maxissues:0 to masissues:1000. As we clean up the code, I hope to bring that number down.

Rebuild .aidl file failed

I download the latest Android Studio, open my existing project then I changed one of the data type in a method's argument of my .aidl file.
I clean and rebuild the project like 20 times now, and still I cannot rebuild .aidl and keep throwing:
Error:Execution failed for task ':playscreen_lib:compileReleaseAidl'.
java.lang.RuntimeException: com.android.ide.common.process.ProcessException: Error while executing process C:\Users\ELDORA\AppData\Local\Android\Sdk\build-tools\25.0.0\aidl.exe with arguments {-pC:\Users\ELDORA\AppData\Local\Android\Sdk\platforms\android-25\framework.aidl -oC:\Users\ELDORA\Documents\Projects\Git\playscreen-v.4\playscreen_lib\build\generated\source\aidl\release -IC:\Users\ELDORA\Documents\Projects\Git\playscreen-v.4\playscreen_lib\src\main\aidl -IC:\Users\ELDORA\Documents\Projects\Git\playscreen-v.4\playscreen_lib\src\release\aidl -IC:\Users\ELDORA.android\build-cache\4492d2ed88e39db806ead472857b23dd46473c28\output\aidl -IC:\Users\ELDORA.android\build-cache\3503095fd81bf51424a6fea93fe733665b5c415d\output\aidl -IC:\Users\ELDORA.android\build-cache\99cfcf1b0afa3f6f8a1f5d9370f6652fdb2c5389\output\aidl -IC:\Users\ELDORA.android\build-cache\d1ed5c0d7925ed8a6207daac53ed47479f327d99\output\aidl -IC:\Users\ELDORA.android\build-cache\b9622378266364961621530394898c10ca07e005\output\aidl -IC:\Users\ELDORA.android\build-cache\ca13b86cac67c820cfadd74657b557d7be41708b\output\aidl -IC:\Users\ELDORA.android\build-cache\1f1034b41fe39b7f222731a1eca43fe985a0c5bf\output\aidl -IC:\Users\ELDORA.android\build-cache\20197f9cb41b0dcfa24d2af19b2f08410bafad05\output\aidl -IC:\Users\ELDORA.android\build-cache\8054d2ad3e9d7b18475122292b9a71c4fd97ce5d\output\aidl -dC:\Users\ELDORA\AppData\Local\Temp\aidl6443722849833229853.d C:\Users\ELDORA\Documents\Projects\Git\playscreen-v.4\playscreen_lib\src\main\aidl\com\playscreen\library\IPlayscreenAPI.aidl}
I never experience this before, it used to be one rebuilt and dependency problem upon changed .aidl will resolves.
Any idea?
Thanks.
I just found the answer, I guess I can't use java object such as Long as method argument, I changed back to long and all fine.
I don't know why but they let me pass String object but not Long. :P

Gradle fastest task for compilation check

Whick gradle task is the fastest to check whether the code passes compilation without any syntax error on Android project
Based on the output of the command
./gradlew tasks --all
executed in a directory containing a small Android project, I'd suggest that your best bet is either the command
./gradlew compileReleaseSources
or the command
./gradlew compileReleaseJava
Here's the full list of tasks that compileReleaseSources depends on for my project (might vary slightly for your own):
app:compileReleaseSources
app:checkReleaseManifest
app:compileReleaseAidl
app:compileReleaseJava
app:compileReleaseNdk
app:compileReleaseRenderscript
app:generateReleaseAssets
app:generateReleaseBuildConfig
app:generateReleaseResValues
app:generateReleaseResources
app:generateReleaseSources
app:mergeReleaseAssets
app:mergeReleaseResources
app:preBuild
app:preDebugBuild
app:preReleaseBuild
app:prepareComAndroidSupportAppcompatV72210Library - Prepare com.android.support:appcompat-v7:22.1.0
app:prepareComAndroidSupportSupportV42210Library - Prepare com.android.support:support-v4:22.1.0
app:prepareReleaseDependencies
app:processReleaseManifest
app:processReleaseResources
Note that this includes the Java compilation step, as well as the compilation of other code sources and various resource processing. Depending on your exact needs, calling compileReleaseJava instead of compileReleaseSources may be enough and will be faster. (Unfortunately, I don't know of a way to view Gradle task dependencies in a tree-like structure, so it's not clear to me exactly how much faster the compileReleaseJava task would be).
If you also want to check that test code compiles, you'd need to add an analogous command: e.g. compileDebugTestSources.

TeamCity, Android, Gradle Script failure

I have been struggling to get TeamCity to build my Android Project. I have finally gotten the server to be able to compile the project with Gradlew (although I have to ignore lint errors, which I am not happy about - it will not tell me which lint errors are being violated EDIT: I found it in ..\build\outputs\lint-results.html)
But now I can see that it is trying to execute the following:
C:\TeamCity\buildAgent\work\284714bad9f1a533\MyProject>gradlew.bat --init-script C:\TeamCity\buildAgent\plugins\gradle-runner\scripts\init.gradle clean build
And I am getting the following error:
FAILURE: Build failed with an exception.
* Where:
Initialization script 'C:\TeamCity\buildAgent\plugins\gradlerunner\scripts\init.gradle' line: 31
* What went wrong:
A problem occurred evaluating initialization script.
> Cannot invoke method split() on null object
I have checked this line and it seems fairly standard:
initscript {
dependencies {
def teamCityInitLib = System.getenv("TEAMCITY_BUILD_INIT_PATH")
println "Init lib: ${teamCityInitLib}"
def classPathFiles = teamCityInitLib.split(File.pathSeparator) //line 31
classpath files(classPathFiles)
}
}
Can anyone help me? NOTE: the following command works without a problem:
gradlew.bat clean build
Seems that you don't have TEAMCITY_BUILD_INIT_PATH variable in your PATH on your build machine. You can add it either by standart ways, depending on OS, or by adding it to Build Parameters in Configuration Steps of your build.
It seems like the build file is not being found. At least, that is what support is telling me. To me this is a TeamCity bug and not on my side. When I find out more, I'll post it.
Found this post while looking for a way to emulate a TC build from the command line and trying to understand how to set TEAMCITY_BUILD_INIT_PATH.
In my environment I determined that it's set to:
/apps/teamcity-agent/agent/lib/serviceMessages.jar:/apps/teamcity-agent/agent/lib/runtime-util.jar:/apps/teamcity-agent/agent/plugins/gradle-runner/lib/gradle-runner-common.jar
Where /apps/teamcity-agent is the my TC install path.
Hope this helps.

Gradle in Android Studio 0.44 can't find process on path to run in an Exec Type task

I used to have the following gradle build task:
task buildWebApp(type: Exec) {
executable = Os.isFamily(Os.FAMILY_WINDOWS) ? "grunt.cmd" : "grunt"
args = ["build"]
}
This would pick the appropriate grunt command and run it with the argument "build".
This worked without any kind of issue
I've just tried this in Android Studio 0.4, using Gradle 1.9 and it's no longer working. Instead I get the following error:
Execution failed for task ':BrowserPages:buildWebApp'.
A problem occurred starting process 'command 'grunt''
Normally at this point I would debug with gradlew, but running the following command, throws no errors:
$ ./gradlew buildWebApp
I've also tried running the full task list to still not find any problems.
The way this is executed is from my main build.gradle file with this dependency
copyWebApplication.dependsOn ':BrowserPages:buildWebApp'
Anyone have any ideas?
I've tried to run executable = "node" with arg = ["-v"] and get the same error where it can't find node. Node is globally accessible on my terminal, so I can only assume that the command is being run in a different environment to the terminal. There is the option for setting the environment but I can't find any examples of how it should be used.
Try using a fully-qualified path to the grunt executable. Perhaps something in the path has changed between Android Studio/Gradle/Android Plugin versions.

Categories

Resources