Creating a project in android studio . it downloads some files every time - android

When I create a new project in android studio. It downloads some files every time. It is really frustrating to wait for more than 15 minutes to complete. It is worse when the downloading got failed and ask to download it again.
I googled it and found a lot of ways Some people suggest this way. Some suggest that way but they all are confusing.
Is there any simple way so that the AS doesn`t need online every time to download files.

Enable Gradle offline mode, It will fix your problem.
Follow this instruction on how to do that.
I'm assuming that you are using Android Studio on Windows.
File -> Settings -> Build, Execution, Deployment -> Gradle
Check the checkbox for Offline work. -> Apply or OK
Update
Go to the right side of Android Studio look for Gradle select it.
Then press the Toggle offline mode button.
You can check the effect by creating a new project.

Related

Is it possible to make android studio 3+ run offline?

I am new to Android development and have poor internet connection at home, whenever I create a new android project it takes forever to sync and build and most of the times it fails to build at all, I was wondering if there is a way so that I can download and save all the necessary build files like gradle, builder jar etc and use them to make android studio work offline?
Thank you and have great day.
I would suggest at least installing Gradle separately, and configuring projects not to download and use the Gradle wrapper for every new project.
After Android Studio downloads all the other libraries for the first time, then you can turn on offline mode in the IDE, and those packages will be shared for all projects
As soon as you try to use a new library, though, you need to get back online
Enable offline mode
If you are on a slow network connection, your build times may suffer when Gradle attempts to use network resources to resolve dependencies. You can tell Gradle to avoid using network resources by using only the artifacts that it has cached locally.
To use Gradle offline when building with Android Studio, proceed as follows:
Open the Preferences window by clicking File > Settings (on Mac, Android Studio > Preferences).
In the left pane, click Build, Execution, Deployment > Gradle.
Check the Offline work checkbox.
Click Apply or OK.
If you're building from the command line, pass the --offline option.
For more info, visit https://developer.android.com/studio/build/optimize-your-build

How to disable the "Refreshing SDK" when I create a project onStudio?

In Android Studio, when I click the "Start a new Android Studio project" on the main window;
and then, a dialog pop up, this is the picture of the dialog:
https://i.stack.imgur.com/0oEjd.jpg
It take some time to download something, look like a part of SDK, but my SDK is downloaded already;
the "Support Repository" is already downloaded too;
https://i.stack.imgur.com/2Pklh.png
I hate this time to wait, and I want to disable this function or something, so I searching for the answer about this question, but nothing found;
I have some not too good ideas for this, one is disable the "Android Repository" on "SDK Update Sites" of "SDK Manager", if I do this, the Download Dialog shown still, but it can't download anything, so the wait time became shorter, but I can't stand too.
My version of Android Studio is 2.3.1;
you can simply disable your network when you want to open or start a project or you can give the android studio a fake proxy to disable its access to google repositories (i never test the second one but it may work ).
truly you can't get rid of these downloads in the android studio and it's a tab-suffering search.
another bothering issue which may also happen for you is that your android studio download or update gradle and it takes so much time.
for this issue, you can go to setting-> build, execution ... -> build tools -> gradle, then mark the offline work.this is a default setting for all projects.
if you already opened a project you can also select a local gradle folder for this project there.

no cached version available for offline mode

At office, I am behind a proxy. The internet access is restricted.
So I performed a gradle sync at home and copied the folder ".gradle" present at C:\Users\username.gradle from my home PC to the same location on my office PC.
Now on my office PC, I set gradle in Android Studio to "Work Offline" but still whenever I try to perform a gradle sync, I get an error stating
Error: Could not download google-services.jar (com.google.gms:google-services:3.0.0): No cached version available for offline mode
However on digging through the ".gradle" folder I was able to locate the google-service.jar file at
C:\Users\username\.gradle\caches\modules-2\files-2.1\com.google.gms\google-services\3.0.0\32b833222c886ecfb37d79b1a05ce1eddb702db1
I am not sure how to proceed. Please help.
I had to dig for this a long time in the 2019.2 version. This option has moved in the UI. It is now in the toolbar of the gradle tools:
see JetBrains documentation at https://www.jetbrains.com/help/idea/jetgradle-tool-window.html#offline
This Error occurs when in your Android Studio's Gradle Tools Offline Mode option is Enabled.
When Enabled it lookes like this.
To fix it, you can Disable mode by clicking on the option shown in below screenshot.
> Update: I heard Google Listened to the suggestion! and now in new android studio versions, when you start a new project, a popup will come with option to either build with gradle online or offline.. Great for you all..
You need to re-enable your gradle online mode
Google changed the location of doing this...
After the latest version as at this time i am typing this answer, which is version below
Android Studio 3.6.1
built on February 27, 2020
I have sent a message to the them so Google changes this in next update..Cos the new location confuses the Software engineers who are used to the old way of doing it...
But for now follow these clear 2 steps to find it and toggle it Online or Offline easily..
Just Go to the top-right hand corner of your SDK and click the vertical Gradle tab as circled in red in the my picture below...
Then you Click this icon (which looks like a symbol in an electrical schematic circuit) on the gradle table that comes out.. As Circled in Red in my picture below..
Maybe helps someone. Just remove --offline in "Command-line Options:"
click on gradle on the right
toggle offline mode
try again (sync with gradle files)
It seems that in newer versions of IntelliJ (I am on 2018.1) you may need to uncheck the Offline checkbox in Gradle preferences.
Just for reference 2019.1 Ultimate IntelliJ, go to Gradle -> Settings (a top-rightmost icon) -> Uncheck the Offline work in Global Gradle settings.
Gradle Tab not presented, go to View -> Tool Windows -> Gradle to show it first.
I'm using android studio in MacBook
step 1 - Go to preferences by clicking android studio on the left
uppermost corner.
step 2 - Go inside Build,Execution,Deployment.
step 3 - Finally select Gradle.
step 4 - then, uncheck offline work. Click apply then ok.
step 5- lastly try to sync once again.
Hope this will work because it works for me.
You can set startParameter.offline=false in your settings.gradle
Try running gradle with the --debug flag, in addition to the --offline flag. That will tell you exactly where it's looking for the files.
One possible reason for the error is that the path of the .gradle folder is different between your home and office PC, possibly because your username is different on each machine. The .gradle cache uses absolute paths (see .gradle/caches/modules-2/metadata-2.16/artifact-at-repository.bin for an example). This is a documented Gradle issue: https://discuss.gradle.org/t/copying-the-gradle-cache-to-another-machine/7546/13. If possible, use the same GRADLE_HOME at home and work to resolve the issue.
How to configure gradle to work "offline" (using cached dependencies)
Uncheck the 'Offline work' under the Global Gradle settings fixes my issue.

Android Studio Project Files are Missing

I was working on app and it was opened in Android Studio. It was all perfect but when after some browsing i clicked on android studio window. it says there are no files opened.
and when I checked in file explorer, all of my project files are removed except .idea folder.I did spend a lot of days on it. I cannot let this happen to me. what possible solutions of this problem?
I tried windows folder recovery, no benefit.
File > Invalidate Caches & Restart seems to be the solution for most oddities.
Before trying any thing. Back-up the project you have.
You can look through local history in Android Studio. In Android Studio -> VCS(Menu) -> Local History -> show History
Select an early restore point that includes your sources-> right mouse -> Revet
strongly I'd recommend you to use git to avoid such as situation. The code is Our Precious👽 Don't lose it.🙂
Just make a copy of the project and save it to another location and open it from the new location. Build it again and it will work.

Why Android Studio rebuilds project so slow even when no changes in sources?

When I make some changes in source code, Android Studio (actually gradle) needs to rebuild the project. It's obvious.
Why the second build takes almost the same amount of time like the first build, even if I haven't made any changes in the project?
When I look into GradleConsole it waits on "assembleDubug" task. I think gradle should be aware there're no changes and shouldn't waste so much time on it.
Finally, I found the solution: turn on Offline work for gradle.
or using CLI:
./gradlew --offline assembleDebugOrWhatever
Does the gradle console say
:app:assemeble UP-TO-DATE ?
If you take a look at the run configuration, you might notice at the very bottom Before Launch: Gradle-aware Make
This is just telling it to recompile(if necessary) before running, but that detection is delegated to Gradle. Gradle will only actually recompile if it detects that it needs to, but the assemble task must still attempt to run to detect UP-TO-DATEness. So it says it's running it, but its not actually doing anything. When I run it two times in a row, the first time it takes a while to do everything, BUT the second time it just runs through the task list pretty quickly (with a bunch of UP-TO-DATEs) and deploys to phone/emulator.
To avoid rebuild EACH TIME, i'm going to my module project settings -> Dependencies and up or down one of my library item -> Apply -> Ok -> Make regenerating R.java.
You could also try unchecking "Use external build" in compiler settings:
File -> Settings (Ctrl+Alt+S) -> Compiler -> Uncheck "Use external build"
This isn't a problem per se. And it has nothing to do with Android Studio since Gradle is just an Android Plugin that helps you build your projects. You need to fully understand what gradle does to know why Android Studio uses it whenever you run your apps. Take a look at this nice SO question on gradle and the android developer website's article on it. Finally, from my personal experience,when it comes to dealing with Android Studio and Eclipse for Android development, you need to be a little patient. Hope this helps in some way.

Categories

Resources