Android Studio: refuse gradle to download dependencies which has been downloaded - android-studio

I don't have access to internet all the time. I use dependencies to add libraries to my project when I am online. for example for using cards library I add this to build.gradle:
compile 'com.github.gabrielemariotti.cards:cardslib-core:2.1.0'
so it goes online and download the related files.
Now I'm offline and don't have access to INTERNET. I started another project and want to use that cards library again, But it says:
Error:(29, 13) Failed to resolve: com.github.gabrielemariotti.cards:cardslib-core:2.1.0
Why it try to download the library again while I have it on my system? How Can I use this dependency in other project in offline mode?
I don't want to copy .jar file to my project I want to use the downloaded file by declare it in dependencies.

You can set Android Studio to offline mode in the settings: Build, Execution, Deployment -> Build Tools -> Gradle -> Offline work

Related

Unable to setup gradle for android studio in offline mode

First of all I want to say that its my first time to work with Android Studio so I don't know much about it.
What I am trying to do:
I am trying to setup Android Studio in offline mode because I have a very slow connection.
What I have done:
Downloaded and installed Android Studio 3.2.1
Downloaded and setup Android Sdk ( By specifying the path to sdk in Sdk Manager )
Downloaded and setup Gradle 4.6
Pasted gradle-4.6 folder inside C:/Users/Username/.gradle/wrapper/dists/
Set Global gradle settings to Offline work
Set Use local gradle distribution to C:/Users/Username/.gradle/wrapper/dists/gradle-4.6
Altered distributionUrl variable of gradle-wrapper-properties file to file:///C:/Users/Username/.gradle/wrapper/dists/gradle-4.6
What Is the problem:
Whenever I try to built and sync my project I get the following error:
No cached version of com.android.tools.build:gradle:4.6 available for offline mode.
I have looked at these posts:
Download and install Android studio gradle offline
No cached version… available for offline mode.
None of them fixed the problem. Please help.
Let complete your gradle build in online mode once, After that change the setting to offline mode, then it will work, until you add new dependencies or try to fetch anything from internet. try it may be it will work.
Or you can change Use Gradle from and locate to gradle file that you have downloaded

Disable Instant Run for project

I have a project that does not build if you try to build it with Instant Run enabled. That's why I would like to disable Instant Run for that project.
Can I do that in a way that can be committed to the repository?
if you want to disable instant-run ONLY for the project that is not compatible (i.e the one with SugarORM lib)
on root of your projct open gradle-->gradle-wrapper.properties then change the value
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
and
on your project build.gradle change the value
classpath 'com.android.tools.build:gradle:2.2.3'
If you want to disable instant-run for all project (Across Android Studio) see this
It's not possible to turn off Instant Run for a Project only till now available stable version of Android Studio 2.3
But to build the Project properly with Instant run enabled and it will not affect the project try to remove the .idea folder and .gradle folder, then click Sync Project with Gradle Files, when the process finished, try to run app.
Hope this solution works for you.

Android training for FragmentBasics won't import into AS 1.5.1

In trying to get the hang of Fragment, I imported into Android Studio 1.5.1 the unzipped folder FragmentBasics after extracting the downloaded file FragmentBasics.zip to that Folder.
Now I have Gradle problems and I have no clue what to do to be able to run the app. I don't know that the .zip file is from Eclipse as the message suggests.
I did move the folder FragmentBasics to C:\Users\Dov because of the space in "Google Drive" but got same error.
Gradle project sync failed . Basic functionality (e.g., editing, debugging) will not work properly.
Failed to sync gradle project 'FragmentBasics'
Error:Cause: failed to find target with hash string 'android-15' in: C:\Users\Dov\AppData\Local\Android\sdk
Open Android SDK Manager
ECLIPSE ANDROID PROJECT IMPORT SUMMARY
Risky Project Location:
The tools should handle project locations in any directory. However,
due to bugs, placing projects in directories containing spaces in the
path, or characters like ", ' and &, have had issues. We're working to
eliminate these bugs, but to save yourself headaches you may want to
move your project to a location where this is not a problem.
C:\Users\Dov\Google Drive\AndroidStudioProjects\FragmentBasics
-
Replaced Jars with Dependencies:
The importer recognized the following .jar files as third party
libraries and replaced them with Gradle dependencies instead. This has
the advantage that more explicit version information is known, and the
libraries can be updated automatically. However, it is possible that
the .jar file in your project was of an older version than the
dependency we picked, which could render the project not compileable.
You can disable the jar replacement in the import wizard and try again:
android-support-v4.jar => com.android.support:support-v4:18.0.0
Moved Files:
Android Gradle projects use a different directory structure than ADT
Eclipse projects. Here's how the projects were restructured:
AndroidManifest.xml => app\src\main\AndroidManifest.xml
res\ => app\src\main\res\
src\ => app\src\main\java\
Next Steps:
You can now build the project. The Gradle project needs network
connectivity to download dependencies.
Bugs:
If for some reason your project does not build, and you determine that
it is due to a bug or limitation of the Eclipse to Gradle importer,
please file a bug at http://b.android.com with category
Component-Tools.
(This import summary is for your information only, and can be deleted
after import once you are satisfied with the results.)
I installed sdk 15 but then had problems with Gradle griping about
gradle-wrapper.properties file having a line with
gradle-2.8-all.zip that needed to be changed to
gradle-2.1-all.zip, so I edited gradle-wrapper.properties file to contain 2.1 instead of 2.8.
Message said after making change, re-import project. And it works.
Before importing I only removed following line from AndroidManifest.xml
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" />
Worked with FragmentsBasics.zip in Android Studio 2.3.3

Support library missing

I am trying to add an existing project as a module. However, it wont compile as it says this library is missing:
android-support-v4.jar => com.android.support:support-v4:20.+
I have opened the sdk manager and installed the latest version of Android Support Library but the error remains. How can I fix this please?
Make sure that you have the "Android Support Repository" installed under "Extras" in the SDK manager.
The support libraries are managed in a local Maven repository, and that repository is the "Android Support Repository" component.
You can manually search the android support library jar in the android sdk directory and then copy it to a directory included in your projects library path. I believe the jar should be somewhere in the \extras\android\support directory.
Note: I must do that when developing android apps with netbeans + android plugin. Not sure if android studio is supposed to pick the support library automatically from the sdk folder.

Why does Android Studio download gradle each time a new gradle project is imported?

Why does Android Studio download gradle every time I try to import a new project?
Initially, I imported one gradle project for which Gradle 2.1 was auto-downloaded. Subsequently, for a second project import, it downloaded Gradle 1.10. Now again while importing a third project, it has downloaded Gradle 2.2.1.
What is happening?
Projects can declare which Gradle they require to run (see gradle.properties file in gradle directory in the root of the project).
Android Studio uses this information to download and run the right version (it's actually not Android Studio, it's the Gradle Wrapper running inside it). And it's a good thing.
What you can do?
Wait. Once you have the version downloaded in ~/.gradle directory, it will be used for any project declaring the same version. It's one-time cache.
Disable the usage of the wrapper when you import the project. I really recommend against it! You project might not build because of that.
Same happens to me.
The answer of JBaruch is allright.
1.- When you're opening a file on the option Gradle project: select the build.gradle that cames on your project
2.- Select the option "Use local grade distribution" and in Gradle home option; go and select in C:\Program Files\Android\Android Studio\gradle\gradle-2.2.1
It will not ask you to download it again (except if needs other version)
...well, here's what I normally do to speed up the initial build on opening a project (target):
1- open a project you already have working and open the file gradle-wrapper.properties a copy the following line (your project most likely will have a different version):
distributionUrl=https://services.gradle.org/distributions/gradle-6.7-bin.zip
2- paste it and replace the code on the same file on the target project
3- open the file build.gradle (project code) from a project you already have working and copy the following classpath, (again, your project most likely will have a different version)
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0-alpha15'
// ...
}
4- paste it on the same file on the target project
This way you can speed up the build of the target project while avoiding the usual 100Mb or so Gradle download.
Basically it downloads the Gradle build files for your current project according to its version and this whole work is done by your gradle wrapper which actually looks towards the basic requirement for your project and downloads the files according to that so whenever you are going to use any another projects of same version or with same requirements then it will not download any additional file at that time.Its just a one time shot!!!!
It usually downloads the Gradle updated version & and external dependencies for each project rather than fetching it from the cache.
So follow these steps:-
Go to settings
Search for Gradle
Untick Download External Dependencies Option.

Resources