Gradle cannot handle generated code changes - android

My setup:
Android Gradle Plugin 3.5.0
Gradle to 5.5.1
100+ Gradle modules
lot of generated code (mostly Dagger + data binding)
When I checkout a branch which causes changes in generated code then usually I have to wipe out whole .gradle/caches directory to make the build succeed. Otherwise gradle build system tries to resolve some old generated code.
clean and cleanBuildCache don't help. Also a side note: so far I've been a happy user but since we updated tools to these versions then build caching stopped working properly. Any tips?
EDIT: Please note that not every change in generated code breaks the cache. It's nondeterministic for me so far.

Disclaimer: I'm a java developer and am not familiar with the Android plugin
The clean task won't remove entries from the build cache. The cache key is derived from the task inputs and outputs. If you haven't declared all of the task inputs correctly then the cache key won't be correct
If (for example) your "generate" task needs a template, some xml and a system property to generate the sources you will need to declare all three (template, xml and syspop) as task inputs to the "generate" task. Any output directory(s) will obviously need to be declared as a task output.
The last thing to consider is that the "generate" task is correctly wired into Gradle's DAG. Eg the "compileJava" task should "dependsOn" your "generate" task (or whatever the android equivalent task is)

Related

How to investigate why gradle build is using cached resource ids

If have a gradle (5.4.1) project (plugin 3.4.1) with two flavors (main and other) using the same sourceSets. I've come across an issue when renaming a resource id (in a layout XML). Here are the observations:
Android Studio 3.4.1 doesn't show any errors and works as expected, i.e. I can click through from kotlin code to the id in the layout xml.
Rebuilding the main flavor also works as expected (no compilation errors).
Rebuilding the other flavor gives a "unresolved reference" compilation error for the new ID. Gradle clean does not help. However, setting org.gradle.caching=false in the project-level gradle.properties does work (following Gradle sync, Clean, Rebuild). This explains why clean was not helping when caching was enabled.
On closer inspection of the R.java file, it seems to be using IDs from some rather old project state (presumably from the gradle cache stored in the user home directory). Now, I could just delete the gradle cache, but I'd rather find out why resource ID changes are not being processed properly. Whichever way Android Studio is running builds in the background, is working fine, just not when performing Build/Run etc.
All this investigation required a lot of trial and error: switching various gradle.properties settings one by one to see which one was leading to the problem, and I'm still no closer to finding the root cause of the problem.
What is the best approach to solving this type of problem, or is trial and error the only way?

gradle-play-publisher: Task 'bootstrap' or 'publishApk' not working

I am trying to integrate the gradle plugin https://github.com/Triple-T/gradle-play-publisher in version 2.0.0-beta1 to automatically upload a new version of an APK to the PlayStore.
I followed the instructions and created a service account and linked it to my PlayStore account.
Then I added my key document (JSON) in the app/build.gradle.
If I call ./gradlew tasks in my Android project, I now also see the task 'bootstrap', publishApk,... but when I call e.g. bootstrap or publishApk nothing happens.
No Taks does anythink right now :(
When I call ./gradlew -i bootstrap it says:
Task :app:bootstrap UP-TO-DATE Skipping task ':app:bootstrap' as it
has no actions.
Does anyone have any idea where my mistake is?
FYI:
I'm trying to do this in Android Studio 3.2.
Oh damn....
after reading the bug https://github.com/Triple-T/gradle-play-publisher/issues/81 and the corresponding answers until the end i noticed that my release-build has set the property debuggable true at the moment (due to tests). After removing this the plugin works as expected.
Sorry for the confusion ;)

JavaFXPorts built apk automatically deleted

When I build an apk with JavaFXPorts using gradle android, I find the apk under build\javafxports\android\MyApplication.apk. However, when I run any other gradle task after that, the apk is automatically and instantly getting DELETED.
I am clueless as to why this happens, since I'm not issuing a clean or anything like that.
Every time you run a task from the jfxmobile plugin, the Android, iOS and embedded extensions are added.
According to this, the folders javafxports/android and javafxports/tmp/android are deleted and created all over again. That means that any content there (your apk) will be removed.
If you think this is a bug, you can file an issue here.
You can also try to fix it, for instance by adding a task to do a backup of your apk every time you create it.
Something like this, added to the build.gradle file of your project, should work:
[android, androidInstall].each {task -> task.doLast() {
copy {
from 'build/javafxports/android'
into "build/apk"
}
}
}

Contribute a Ionic 3 App to F-Droid

I'd like to contribute to the F-Droid GitLab Repo.
I followed this guide: https://gitlab.com/fdroid/fdroiddata/blob/master/CONTRIBUTING.md
I have done this already, many times with a normal native app. That worked great. But with an Ionic app it seems to be different. I see, for example, no gradle data in my Ionic app. Do I need gradle? Because the build failed because he can not run gradle clean ..
Heres my stack:
==== detail begin ==== FAILURE: Build failed with an exception.
What went wrong: Task 'clean' not found in root project.
This is how my metadata file looks like:
Categories:System
License:GPL-3.0
[...]
Repo Type:git
Repo:<Repo Link>
Build:1.0,1
commit=<commit>
gradle=yes
Auto Update Mode:None
Update Check Mode:None
Everything in <> is filled out correctly.
You are forging new ground here! We (F-Droid) don't have solid support for Cordoba/Ionic/etc. but the only thing preventing it is someone doing the work! We're working on adding a new build field sudo= which will let you download and install whatever you need to run your build. I've never used Ionic, Cordoba, or any of these Javascript app things, so I don't know the details.
You can follow the progress of sudo= here:
https://gitlab.com/fdroid/fdroidserver/merge_requests/297
It'll still be a while yet before this is deployed on our infrastructure, but your testing it will speed up that process!

Failed to capture snapshot of output files for task

Error:Failed to capture snapshot of output files for task 'transformClassesWithDexForDebug' property 'streamOutputFolder' during up-to-date check.
Failed to create MD5 hash for file 'C:\Users\GauravZone\AndroidStudioProjects\ZopporoStore\app\build\intermediates\transforms\dex\debug\folders\1000\10000\instant-run_83dbc65f4e3a4cd278807c089695c6b352698791\classes.dex'.
I am getting these errors don't know why, all application working fine earlier but suddenly getting this error in my all applications when try to run projects
Disable your antivirus, and it will work.
This is a Gradle issue and you can find it here.
So as of now just disable Instant Run.
It worked for me.
In android studio,
Open the Settings or Preferences dialog: On Windows or Linux, select File >
Settings from the menu bar. On Mac OSX, select Android Studio > Preferences from the menu bar.
Navigate to Build, Execution, Deployment > Instant Run.
Uncheck The box next to Restart activity on code changes.
I Solved this issue in my react-native project by removing all npm cache
1.npm cache clean --force
2.react-native run-android
Set multiDexEnabled true in your buildType release class in your build.gradle file
Error:Failed to capture snapshot of output files for task 'transformClassesWithDexForDebug' property 'streamOutputFolder' during up-to-date check ::
Solution: Just rebuild the project and then sync the project with Gradle files, as mention below.
1. Click on Build -> Rebuild Project
2. Click on Tools -> Android -> Sync Project with Gradle Files
I was also getting the same error.
But when i disabled Instant Run, Gradle started building.
But i agree with those who think this is a Gradle issue.
And until it gets resolve, disable Instant Run.
follows steps: instant run(file->setting->build,execution,deployment->uncheck instant run) then compile it work properly.
I've run into this issue after updating Android Plugin for Gradle to version 2.3.1. Rollback to version 2.3.0 helped for me, try setting
classpath 'com.android.tools.build:gradle:2.3.0' in your top level gradle.build file.
For me i had this error when i use my device as emulator . I did like that and it works :
1.adb reverse tcp:8081 tcp:8081
2.react-native start --reset-cache
3.react-native run-android
I faced the same issue and by disabling the QuickHeal Antivirus's virus protection, it worked for me fine.
Problem is gradle version. Update the gradle version to latest to resolve this kind of issues.
I have tried 'com.android.tools.build:gradle:3.3.2' is working for me. previously it was '3.1.0'
This issue comes when there are more than one process which is doing something with a file in your disk (whether it's your Jenkins job's workspace or Gradle's cache path or Gradle build folder that it creates) where these processes are trying to do something with a file and holds a lock.
If you have anti-virus, you may see this. Un-installing may resolve the issue but then you don't have anti-virus (it's better if you can set something in anti-virus to scan files periodically).
In my case, this issue only comes when I have a Jenkinsfile pipeline, where I'm running Gradle task for 3-5 projects in parallel (let's say Gradle is running an rpm task or build task) and when I'm running concurrent runs of this pipeline.
As you can see my pipeline code (Jenkinsfile Pipeline DSL: How to Show Multi-Columns in Jobs dashboard GUI - For all Dynamically created stages - When within PIPELINE section) is creating dynamic stage(s) and when I call it within pipeline section, I use parallel to run N no. of projects (that I can define in a hash/array) gradle tasks in parallel.
What I noticed is, all these runs (running in parallel) is running using my user-id (or some service account) and they are all using same Gradle version (4.3.1 in my case) and thus, they are using the same cache.
Running them in parallel alone --OR-- more realistic case would be running multiple pipeline runs of this pipeline job (running 5 project's gradle task in parallel) would probably land into this LOCK file condition.
You can probably solve this by setting a unique GRADLE_USER_HOME="~${WORKSPACE}/.cache"
(i.e. use Jenkins job's workspace which is dynamically created and is unique) or even better by setting Gradle user home as:
dt_stamp=`date +%s`; ## set and pass this dt_stamp variable for Gradle user home before calling Gradle.
GRADLE_USER_HOME="~${WORKSPACE}/${dt}/.cache"`
This way, at least in Gradle's cache, you won't see any issues due to lock files (NOTE: You'll not be able to efficiently use Gradle's cache concept of being lazy (or not fetching artifacts/library dependencies from a binary repository like Artifactory each time) while using Gradle among many projects if you set GRADLE_USER_HOME to a dynamic folder value as it'd be like running gradle after clearing it's cache each time (for some it's OK if your build doesn't take much time and it's more cleaner way to build as well)).
When I tried to run just one pipeline run (which runs all 5 project's gradle task in paralle), the pipeline succeeds all the time.
Running multiple instances of the pipeline job (running 5 parallel builds in each run) lands into this file LOCK issue.
Error mesg when I ran many concurrent pipeline runs (each pipeline run - runs Gradle tasks in parallel on 5 different projects).
FAILURE: Build failed with an exception.
* What went wrong:
Failed to capture snapshot of output files for task ':rpm' property 'archivePath' during up-to-date check.
> Timeout waiting to lock file hash cache (/view/user123456_Team_Tools/vobs/space/test/folder1/Project1of5/.gradle/4.3.1/fileHashes). It is currently in use by another Gradle instance.
Owner PID: 29003
Our PID: 903
Owner Operation:
Our operation:
Lock file: /view/user123456_Team_Tools/vobs/space/test/folder1/Project1of5/.gradle/4.3.1/fileHashes/fileHashes.lock
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
-- OR --
You may also get this kind of error where a process is not able to delete a directory (while Gradle is in progress as the target folder/file may be in use by some other process)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':clean'.
> Unable to delete directory: /view/user123456_Team_Tools/vobs/space/test/folder1/project2of5/build/classes/java/main/org/syntax/jedit
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
If you are really lucky (like me), then you'll probably hit this error as well:
Jenkins - java.lang.IllegalArgumentException: Last unit does not have enough valid bits &
Gradle error: Task 'null' not found in root project
See here for more details: Jenkins - java.lang.IllegalArgumentException: Last unit does not have enough valid bits & Gradle error: Task 'null' not found in root project
Clearing the cache does fix it. But only once, if you stop the project and re run it, you ll end up with same error again.
Doing following fixes it for me,
cd android
./gradlew clean
react-native start --reset-cache
npm clean cache --force
Next, open two different terminals,
Run react-native start
in one terminal and in second,
Run react-native run-android
Hope it'll work for you as well.

Categories

Resources