What is Clean project in Android Studio really doing? - android

I have used clean project a few times after breaking my tutorial app. I did this by doing a refactor or some other fancy command on a variable. I don't actually know what android studio is doing in the background and I am wondering if anyone can give a good detailed answer in simple English. :)
Thank you in advance,

Simple answer it Deletes the build directory
It removes whatever already-compiled files are in your project meaning it removes the .class files and recompiles the project again.
Source is here : https://www.jetbrains.com/help/idea/2016.3/cleaning-system-cache.html?search=clean
If you want to have some fun by cleaning yourself
Open your project path using cmd
(go to project path and type cmd and hit enter like below)
Then use command gradlew clean and hit enter and see what happens when it cleans
For other tasks and meet your project's Mr.Gradle use command gradlew help

Clean action, basically invoking ./gradle clean task in your application directory, which is removing all generated files, removes build folders. So basically next time you will run/build all the artifacts will be builded from the scratch and will not be reused.
More information you can find on a official gradle site
Information about android plugin
DSL reference for Android plugin

Cleaning the project removes all build artifacts (ex: deleting the app/build folder)

I don't know what it does. But I would like to share my experience that is worth to know.
I was having one Android Studio project in which I was managing two projects through buildTypes(Lets name them project A and B).
I was previously working with project A. Now I need to work on project B. So I made necessary changes and implemented the functionality. My next task was to generate the signed APK. I generated the signed APK with the keystore of appropriate project that is project B.
But the generated signed APK was showing the SHA1 of the keystore of project A. and Google play store was not allowing me to upload the apk with different keystore. I checked it 5 to 6 times and generated signed APK and failed every time.
After 3 to 4 hours I gave one try to clean project as any other solution was not working for me and Voila now it signed the apk with correct keystore.
So clean and rebuild the project before generating the signed APK is a best practice mainly If you are working with different buildTypes

Cleaning an Android project simply deletes the build directory. It removes the .class files that are generated when you compile your project and then recompiles again. As per my experience, whenever I move my Android Studio project folder in another location in same or different hard drive, it gives an error while running the project. In that case, cleaning the project helps eliminating the errors by re-building the project from scratch and to run successfully.
To clear a project in Studio, go to Build > Clean Project. Done.

Related

Android Studio Cordova project doesn't have the option to generate as APK/App Bundle

I have inherited an Android Studio project from a previous developer that uses Cordova. This is a template that we have used for three years for each new app we build. I have very little experience with building in Android and have Googled my way through so far.
With the August 2021 update on Google Play Store I'm now needing to submit our newest app in bundle format, but I don't seem to have a way to do this.
I have seen guides referring to a 'Generate apk/bundle' option that should be visible under 'build' from the top menu, but this option is not visible for me:
Whenever I've used this template before, there was a message displayed saying "Migrate Project to Gradle? This project does not use the Gradle build system". My understanding from a day of research is that although my module had a build.gradle folder, the top level project also needed one (and a settings.gradle file). This seems to have worked as there is now a 'Gradle' that syncs successfully when I make a change.
When I use the command 'cordova build', the project is building successfully.
I've also read that you can use gradlew bundlerelease to generate a bundle, but if I use gradlew tasks then there is no task available relating to bundling.
I'd really appreciate any advice on how I bundle this app please.
EDIT: By changing directory into app/platforms/android, the gradlew bundlerelease function works. I receive a BUILD SUCCESSFUL message, but nothing is actually being generated.
You should be able to generate the bundle using
cordova build android --release -- --packageType=bundle
See https://github.com/apache/cordova-android/issues/729 for more details
In case anyone is reading this in the future, thought I'd post my solution here.
My issue was that after manually adding the top project-level build.gradle and gradle.settings files, Android Studio converted it to be Gradle-based and somehow my existing module was not recognised. I had to create a new module inside the project, upgrade Cordova to 10.0.0 and migrate the project to Android X.
After the above changes, the menu option to generate the app bundle existed and finally worked.

Android Studio - going to "Android" file tree format from "project" file tree format results in showing "gradle scripts" only

I'm importing from Bitbucket and am experiencing the issue. There are also no run configurations available. Do any Android gurus have an idea?
Thank you
-T
edit run config:
Different views will show and group your project files differently in Android Studio and IntelliJ IDEs. I think if you choose "Files", you will see all project files, and the actual directories in which they exist.
If this is a project you downloaded from bitbucket, you will most likely have to build the project yourself, and that is why you only see gradle scripts in the project view. You will also most likely have to create your own Run configurations.
Developers usually only upload the source files-- it's up to the end users downloading the project to build it themselves to generate the build files.
You could try creating and running your own "Android" Run configuration, and see where the build breaks, patch the current build failure + rerun. Rinse and repeat. Sorry for the bad news-- I've been frustrated in the past getting Android projects from github running for the same reasons.

Android Studio uploads sterile APK to device when Gradle has custom logic changing APK names

While using Android Studio I encountered the following error:
The date of the APK is 2 days older than the current one (Gradle is used to append the build date to APK name). I've checked folder \build\outputs\apk, and an APK with the correct date has indeed been generated:
The follows have been tried:
Build -> Clean Project
Build -> Rebuild Project
File -> Invalidate Caches / Restart...
How do I fix this so the correct APK can be uploaded to device to run?
Edit:
Changed the title to better reflect the circumstances where this issue would occur. It appears that Android Studio would remember the APK names provided by Gradle when it's been synced with Android Studio, but does not update the APK names when Gradle is ran to create the actual files.
In my situation it's caused by the fact that the current date is appended to the APK name, so if I synced Gradle to Android Studio on 12/3 Android Studio would remember the APK filename to be app_2014-12-03.apk). Then using Gradle build and run the app on 12/4 would cause the disconnection between Android Studio and Gralde, where Gralde generated app_2014-12-04.apk and yet Android Studio still remembered the APK filename to be app_2014-12-03.apk.
It is a problem with sync between Gradle and Android Studio. Press Gradle Sync icon (it is icon between Project Structure and AVD Manager) and it will solve the issue.
(In comments you asked for explanation - I found this answer few weeks ago, when I had also issue with this[but now I cannot find this page]. If I remember correctly was information, that during Sync Gradle is informing AS about different information including info about apk path. In your case [and mine in past] path is changing every day, as we have date in name of apk and due to this we have to make Sync)
If you want a workaround for this you can check out my answer on this post.
Basically, you wold only rename the APK when doing a command line build, such as from a CI Server. While doing normal development Android Studio works as usual.

Android Studio build error or misconfigured

I am having trouble building with Android Studio on one of my computers. The same project was building fine and when I pushed to github and pulled from the other machine I get the following error
Argument 0 for #NotNull parameter of com/intellij/execution/configurations/GeneralCommandLine.setExePath must not be null
I tried generating a new default project and I get the same build error so it must be something with my setup.
Does anyone know what I can do to fix these issues? Or even how to completely uninstall Android Studio and start fresh? Thanks
I had same error. In my case it was caused because of modification some important configuration. I fixed the issue by executing following steps:
File -> Other Settings -> Default Project Structure
SDKs
Add new SDK (select JDK option)
Specify path to JDK (in my case it was "C:\Program Files\Java\jdk1.7.0_45")
Save changes
You can also check if you have configured path tho the Android SDK
Good luck!
Had the same problem. Had to uninstall Android Studio, delete all files related to it including install files, the .AndroidStudioPreview folder under your user directory, and those files made in your project's folder upon importing. This amounts to the idea folder and the [projectname].iml file. Now reinstall and re-import the project. You can reuse the same build.gradle. Mine's working now.

Android Logcat files on Hudson/Jenkins

we are using Hudson for CI of an Android project with Android emulator plugin to run UI tests on the emulator. A git project delivers the source code.
Now I see that in the git repo, for each build a logcat file is created and put in the git project folder, which is then pushed back to git. As we are expecting a lot of builds, this could easily spam the project folder. Does anyone know if it is possible to set the destination folder for the emulator logs?
I cannot find any options in the emulator plugin or Hudson anywhere.
The logcat files are named logcat_[some_number].log.
Best regards,
Kim
Upgrade to version 2.0 of the plugin (or newer) and you'll see these logcat files are now written to a temporary directory, rather than your workspace.
If you're using Hudson, possibly you only see the very old version 1.6 in the Update Centre.
Which is just another reason to upgrade to Jenkins! :)
However, if you can't upgrade either the plugin or Jenkins (for some weird reason), just use an "Execute shell" step to delete any logcat_*.log files at the start of each build.
These files are purely temporary anyway and should probably only exist in your workspace after a failed build — otherwise the logcat output is archived automatically as logcat.txt.
Add an ant task to rename the logcat file to your convenience and remove the oldest ones.
add the logs to the .gitignore file, if you want to exclude them from your repository.

Categories

Resources