issue with Jenkins and the build cache for Android - android

I'm using Jenkins to build an Android project.
The problem I have is that unless I disable the cache Jenkins gives me several errors like for example:
12:31:15 AAPT: \?\C:\Windows\System32\config\systemprofile.android\build-cache\34562456245625\output\res\drawable-mdpi-v4\abc_text_select_handle_left_mtrl_dark.png ERROR: Unable to open PNG file
I can't disable the cache because I would have to do it in the gradle.properties file that is shared on git.
I do not want to use the cache on Jenkins because I want to be sure that the builds always run from scratch.
What's the best practice in this case? Should I leave the cache on or off?
If I need to turn it off how can I do it without stopping the cache while building on the developers' machines?
If I should keep it on, what should I do to avoid the error and to be sure that the build won't be affected by any weird issue with the cache?

I would recommend to disable the build cache.
If you can't do it because it is under source control and shared on several environments, I'd go with a little batch script that creates a copy of gradle.properties before the build, modify the original to disable the cache while building and in a post build step copy the unmodified original back to the location.
If everything is done right, this gradle.properties file will not be recognized as modified and will therefore not cause any pull/checkout conflicts.
I do this in several builds with more than one file (in c# we replace version numbers in the AssemblyInfo.cs file while building and then restore them, and we also do some file-hiphop with android builds)
hope this helps,
cheers, Gris

I decided to keep the cache. Now I'm:
1) setting the build cache dir in the gradle.property
2) cleaning the cache every time by calling gradlew cleanBuildCache

Related

How to use a jar file obtained from apk conversion using dex2jar in another Android project?

I have an apk file of an android app, which I convert to a jar file using dex2jar. Now, I would like to use this jar file in another Android project.
To do so, I use provided files('libs/filename.jar') in my build.gradle file. However, when trying to build my Android project I keep getting the following error.
Failed to create MD5 hash for file 'pathToJar'
I am wondering if anyone has any idea why I am getting this error?
The most probable reason for this might be your instant run feature is enabled. You might consider checking if the instant run is enabled. If it is enabled, please disable the instant run and try to build the project again.
File -> Settings -> Build, Execution & Deplyment -> Disable Instant Run
Now clean your project and rebuild. Hope that helps!
The jar file you got is from another application. To prevent reverse engineering and fraud usage, the developers of this jar file probably used MAC or simple hash check. IMO this is checking the package name in which the jar is placed.
You can try changing the package name similar to that from which you got this jar (reverse engineered). I honestly do not recommend you do such practices.

Android build error using NativeScript Sidekick: app:mergeDebugResources

I'm building an app with NativeScript using TypeScript and Angular. This has happened twice while building the app.
In order to add resources (like images), I add them to my_app_folder\app\App_Resources\Android\src\main\res. I accidentally added a folder called "video" with a file called "sample_video.mp4" into the res folder. When I tried to run my app on my Android emulator using the cloud build, I received this error in my NativeScript Sidekick console:
/mnt/storage/builds/_/b10d99b4991d936c4896cd72f0628901fa996d4c/4.2.4/saintstanreal/platforms/android/app/src/main/res/video/sample_video.mp4: Error: The file name must end with .xml
I realized I had placed the file in the wrong place, deleted the video and the video folder, and tried to build the app again, but now I am consistently getting the above error, even though the offending file is long gone.
This has happened to me before (with a .png file with a capital letter in the name, which android does not like) and I would love to know why. Last time I had to delete my whole project, revert to my previous commit, and rebuild the app, which is frustrating.
My app ran perfectly fine before I added that file, so I know that the problem is not being caused by my code. I tried deleting the android platform and reinstalling it, to no avail.
Any help would be amazing as I am very confused as to why the file, which is no longer in my project, would continue to cause this problem.
Try a clean build to reset the data that was cached.
In Sidekick go to Build and from the menu options check Clean Build
When you enable the Clean Build option, any previously cached data
will be ignored and the application will undergo a complete rebuild.
This type of build will not take advantage of certain optimizations
and may take longer to finish.
As of the resolution of this issue in NativeScript Sidekick, using File -> Clean Cloud Workspace fixes this problem.
If I add an incorrect resource file to Android's "res" folder, try to build (and fail), remove the incorrect file, and use the "Clean Cloud Build" command, the Android cloud build will then work as intended (without having to use the "Clean Build" checkbox when building).

Gradle sync prevents app from running

I am trying to move a project folder from one location to another and change the folder name.
For various reasons version control was not possible so I have the following structure: MyApp\Version 1.xx\ and in this folder I have more folders named 1.0.1, 1.0.2 etc.
I also have another folder called MyApp that I want to copy into MyApp\Version 1.xx\ and rename it to 1.0.5.
Unfortunately, I am stuck with the following message: "Gradle files have changed since last project sync".
If I try to sync, the message pops up again in a few seconds. If I try to build/debug the project, I get this:
I also tried to create a new empty project with the same name into the desired folder and add the layouts and classes there but if I try to run the app I get these:
I tried Clean, Invalidate Cache and Restart, deleting and recreating Gradle files as well as most of the solutions provided around here, without any luck.
Any ideas on how to fix this issue?
(Posted on behalf of CommonsWare, from the comments).
If I try to sync, the message pops up again in a few seconds. If I try to build/debug the project, I get this"
Try a command-line build, and see if that gives you anything more to go on. Otherwise, for that project (module? whatever), delete your .gradle/, .idea/, and build/ directories, plus .iml files, and try re-importing into Android Studio.

Random fail to build due to a 10.jar file not being deleted

Error:
Error:java.lang.RuntimeException:
com.android.build.api.transform.TransformException:
java.io.IOException: Could not delete path 'C:\Users\Roudy
Kanaan\Documents\synkers-android\app\build\intermediates\transforms\desugar\development\debug\10.jar'.
A fix would be to clean the project or manually killing the "Java platform SE binary" process that's actually using that file. I don't want to clean project/manually delete file every other build and I can't find a permanent fix for this problem.
What I tried:
Invalidate cache/restart: temporarily fixes the problem
Clean build: temporarily fixes the problem
Deleting the file manually: temporarily fixes the problem
This issue, if I remember correctly (Not so sure), started to happen when I updated android studio to some version (3.0 maybe) I'm not exactly sure but just trying to back trace this problem.
people have faced random issues after upgrading to 3.0. Mine was that i was extending with Application instead of MultiDexApplication. I would suggest you to make a new sample application via studio 3.0 and compare the changes in the Gradle scripts files.
Also, you should :
use implementation instead of compile.
update the build tools.
for once, manually remove build, .gradle, .idea folder and file and the build folder from the app folder.
upgrade your gradle.
Try these things, It will eventually get things sorted. Let me know what resolved it, even if nothing from the above.

Android Gradle Sync Failed to Sync project

Android Gradle Sync Failed to Sync project:
Unable to find method 'org.gradle.api.internal.project.ProjectInternal.getPluginManager()Lorg/gradle/api/internal/plugins/PluginManagerInternal;
I think this is the issue of gradle cache. I think you need to clear it out. The best solution over SO is here as
"You can safely delete the whole .gradle folder located under project directory. It'll be recreated every time the tasks are run. The same is for .gradle under home directory. It'll also be recreated as well, but the whole dependencies must be downloaded again - it's quite time-consuming.
As I see in various places over the web gradle for android development
is quite slow and people complain about it. No idea what's reason
exactly - this is how it works.
I don't think that low performance is because of big folders. Actually
they help it to be faster.
there might gradle.properties as well as global gradle scripts located
under $HOME/.gradle. In such case special attention must be paid when
deleting the content of this directory."
take a look at this link .
And please select it as a answer if it helps and let me know.,
I found the solution. I deleted the .gradle and .Android(android studio version)1.5 folders inside c:/users and started Android Studio.
There's usually a problem with gradle cache when it gets corrupt. I used this solve gradle sync guide to fix the error.
TL;DR: find .gradle folder and remove its content.

Categories

Resources