We have Gradle set up to build and test our Android app. Now we ran into the problem, that Gradle test runs fail reproducibly after a class was renamed somewhere in the project:
Execution failed for task ':PROJ:compileDebugUnitTestJavaWithJavac'.
> Unable to read class file: '/path/to/class/with/the/name/before/renaming.class'
This error is reproducible both..
locally (run gradle tests from Android Studio, or on command line using ./gradlew test), and
remotely, when the tests run on our CI (a Teamcity server).
What solves the issue, is manually triggering a rebuild locally (e.g. in Android Studio Build > Rebuild Project) or re-running the Teamcity task with the flag clean all files in the checkout directory before the build set.
Is there any way we can get our tests to not fail after a class has been renamed?
While the above solution is simple enough it is kinda annoying that a simple rename which makes it to our repo will blow up the CI builds... We really want those to stay green. :)
This is a known issue in Gradle 2.14 and 2.14.1 and there will be a workaround for it in upcoming Android Gradle plugin release.
As a workaround you can do a clean build for your project. For a CI build, a clean build is a good idea anyway.
You could use the Swabra build feature of TC that cleans out the working directory either before or after each build, so that all generated files are blown away and the build always starts with a clean working copy. For reproducible builds this is a must-be-used feature in my opinion.
Alternatively you can of course also add the clean Gradle task to your TC configuration so that Gradle cleans away previous build artefacts. But if using TC I'd prefer Swabra as it restores VCS state reliably.
Related
I am very new to KMM (Kotlin Multiplatform Mobile) and iOS development (including CocoaPods). I have come across the following build error in Android Studio.
Execution failed for task ':shared:podInstall'.
java.io.IOException: Cannot run program "pod" (in directory "/Users/.../AndroidStudioProjects/.../iosApp"): error=2, No such file or directory
The directory definitely exists and I seem to be able to manually run pod commands from within the directory. I am not sure but it seems like this problem came about when I updated the Kotlin plugin from 1.5.0 to 1.5.10. This problem occurred even when starting a completely new KMM project.
I thought it might have something to do with Android Studio not being able to find the pod command so I added it to the path but that didn't seem to do anything. Any help with this would be appreciated.
Check your Gradle JDK :
Android Studio > Preferences > Build, Execution, Deployment > Build Tools > Gradle
Then select Gradle JDK -> Embedded JDK
Maybe you must execute in command line :
./gradlew :shared:podInstall
Have you tried File > Invalidate Cache and Restart?
I had exactly same issue, but It got fixed after invalidate cache and restart.
I have android lib module (with native implementation). When I build the app (as debug) it also build this lib module (as debug) and as a result of lib build I get .aar (as a debug). All is fine here, I try to build debug and I get debug .aar.
Then, I need to build this android lib without the whole android app, just this lib. In order to do it I open Gradle tab at the right side in Android Studio window then I found my lib name -> Tasks -> build -> assemble. And this gradle task make a build for only this lib.
Issue is that as a result I get two .aar files one debug and one release. I don't need to get two I would like to have an option to choose what to build - debug or release.
Main issue here that it takes a lot of time for build this lib in debug and in release. Because of this I would like to choose how to build and it should save a time.
So, how to do it?
Since you are building all variant it will take time so You can use android build comment ./gradlew :app:assembleDebug or ./gradlew :app:assembleRelease . Run comment in your application root folder
NB:- if you application not in app folder means submodule use corresponding folder name instead of app ./gradlew ::assembleDebug
The Android Studio Build menu has options including
Make Project
Rebuild Project
When should I use each?
Most of the time you should use Make Project. Sometimes, after adding libraries and making big changes to the project you should use Rebuild Project.
If you look at the menu, you'll see that Make Project and Compile have keyboard shortcuts, that suggests that they are often used. Others are seldom used.
It is the same as IntelliJ Idea.
Compile All the source files in the specified scope are compiled. The scope in this case may be a file, a package, etc.
Make Project All the source files in the entire project that have been modified since the last compilation are compiled. Dependent source files, if appropriate, are also compiled. Additionally, the tasks tied to the compilation or make process on modified sources are performed. For example, EJB validation is performed if the corresponding option is enabled on the Validation page.
Make Module Compiled are all the source files that have been modified since the last compilation in the selected module as well as in all the modules it depends on recursively.
Rebuild Project All the source files in the project are recompiled. This may be necessary when the classpath entries have changed, for example, SDKs or libraries being used added, removed or altered
Copied from IntelliJ Idea 13 help.
The difference is that Rebuild executes gradle's clean task first. If you look in the Gradle Console 'Rebuild Project' will say something like
Executing tasks: [clean, :app:compileDebugSources, :app:compileDebugAndroidTestSources]
While 'Make Project' won't have clean
Executing tasks: [:app:compileDebugSources, :app:compileDebugAndroidTestSources]
Difference between make and rebuild is "clean" task.
When you do rebuild project it performs clean too.
I have a multi-project setup in Gradle and work in Android-studio. The setup contains two apps (each one has its own project directory with its own build.gradle) and some libraries shared by those apps.
The directory structure looks like this:
/workspace/
/workspace/app1/
/workspace/app2/
/workspace/app3/
/workspace/library1/
/workspace/library1/
When I build from the command line I can limit the build to only one of the apps via
gradle assembleDebugApp1
When I build from within Android Studio, it seems to build all projects that have a build.gradle file and are inside of workspace.
In Android Studio, when I run Build->Make Project, I see on the bottom what gradle does:
Gradle build using tasks: [:app1:assembleDebug, :app2:assembleDebug, library1:bundleDebug, (...)].
I would like it to only run the assemble task for my "current project".
I'm new to AndroidStudio, so maybe the question is : How do I set the "current project'?
How do I tell Android Studio to only build what I need for app1?
Edit based on replies:
I do want to run gradle via make so it does give feedback back to the IDE, because I'd like to see the "Make Messages" window:
Open Gradle tasks tab and select task to run. You can select a task from subprojects.
On command line:
gradle :app1:assembleDebug
I'm not sure if there is an "official" way of handling this yet but I got around it by creating a new "Run Configuration" and replacing the default "Build" option in the "Before Launch" section with my own command that calls Gradle with the relevant command line options.
I'm automating the publication of my Android app and I'm using Gradle, great utility!
Just a problem, consider this .bat file (under Windows 7):
:: assemble the project
gradle assemble -Pprofile_name=%profile_name% -p%destination_dir%
::copy apk to repository
copy "D:\compile\myapp\build\apk\*.apk" "d:\build_repository"
Well the copy command is never executed, never. It seems that the execution stops after calling gradle utility. Any idea?
The build within Gradle has ends with success and no error at all...
I ran into this very same problem, but for a webapp. Gradle isn't necessarily the issue, but how you are invoking it. As explained in this post,
How to execute more than one maven command in bat file?
because gradle is a batch file itself, it completes execution and doesn't return control back to your batch file. Use the same 'call' strategy and everything should work.
Like so for your original post,
call gradle assemble -Pprofile_name=%profile_name% -p%destination_dir%
::copy apk to repository
copy "D:\compile\myapp\build\apk\*.apk" "d:\build_repository"
If you are on ionic/cordova and batch execution is stopping after ionic cordova build --release android use call before
call ionic cordova build --release android